Loops/Increment loop index within loop body: Difference between revisions

Content added Content deleted
(→‎Functional Python: Pruned out a little scaffolding – two unused imports.)
m (→‎Functional Python: Updated output.)
Line 3,259: Line 3,259:
def go(tpl):
def go(tpl):
if isPrime(tpl[1]):
if isPrime(tpl[1]):
print(secondArrow(showInteger)(tpl))
print(showTuple(tpl))
return splitArrow(succ)(dbl)(tpl)
return splitArrow(succ)(dbl)(tpl)
else:
else:
Line 3,347: Line 3,347:




# showInteger :: Int -> String
# showTuple :: (Int, Int) -> String
def showInteger(n):
def showTuple(tpl):
'''Integer string with comma-chunked digits.'''
'''Integer string with comma-chunked digits.'''
return f'{n:,}'
return '{:2} -> {:20,}'.format(*tpl)




Line 3,381: Line 3,381:
main()</lang>
main()</lang>
{{Out}}
{{Out}}
<pre>(1, '43')
<pre> 1 -> 43
2 -> 89
(2, '89')
3 -> 179
(3, '179')
4 -> 359
(4, '359')
5 -> 719
(5, '719')
(6, '1,439')
6 -> 1,439
(7, '2,879')
7 -> 2,879
(8, '5,779')
8 -> 5,779
(9, '11,579')
9 -> 11,579
(10, '23,159')
10 -> 23,159
(11, '46,327')
11 -> 46,327
(12, '92,657')
12 -> 92,657
(13, '185,323')
13 -> 185,323
(14, '370,661')
14 -> 370,661
(15, '741,337')
15 -> 741,337
(16, '1,482,707')
16 -> 1,482,707
(17, '2,965,421')
17 -> 2,965,421
(18, '5,930,887')
18 -> 5,930,887
(19, '11,861,791')
19 -> 11,861,791
(20, '23,723,597')
20 -> 23,723,597
(21, '47,447,201')
21 -> 47,447,201
(22, '94,894,427')
22 -> 94,894,427
(23, '189,788,857')
23 -> 189,788,857
(24, '379,577,741')
24 -> 379,577,741
(25, '759,155,483')
25 -> 759,155,483
(26, '1,518,310,967')
26 -> 1,518,310,967
(27, '3,036,621,941')
27 -> 3,036,621,941
(28, '6,073,243,889')
28 -> 6,073,243,889
(29, '12,146,487,779')
29 -> 12,146,487,779
(30, '24,292,975,649')
30 -> 24,292,975,649
(31, '48,585,951,311')
31 -> 48,585,951,311
(32, '97,171,902,629')
32 -> 97,171,902,629
(33, '194,343,805,267')
33 -> 194,343,805,267
(34, '388,687,610,539')
34 -> 388,687,610,539
(35, '777,375,221,081')
35 -> 777,375,221,081
(36, '1,554,750,442,183')
36 -> 1,554,750,442,183
(37, '3,109,500,884,389')
37 -> 3,109,500,884,389
(38, '6,219,001,768,781')
38 -> 6,219,001,768,781
(39, '12,438,003,537,571')
39 -> 12,438,003,537,571
(40, '24,876,007,075,181')
40 -> 24,876,007,075,181
(41, '49,752,014,150,467')
41 -> 49,752,014,150,467
(42, '99,504,028,301,131')</pre>
42 -> 99,504,028,301,131</pre>


=={{header|Racket}}==
=={{header|Racket}}==