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

adding lambdatalk
(J: bugfix (the initial implementation didn't quite match the requirement for display). Note that some of this content is still unreviewed)
(adding lambdatalk)
Line 3,020:
49,752,014,150,467 is prime, 41 primes found(so far)
99,504,028,301,131 is prime, 42 primes found(so far)</pre>
 
=={{header|Lambdatalk}}==
We use the javascript bigInts and the isPrime primitive working on big integers.
 
<syntaxhighlight lang="scheme">
 
{isPrime 11}
-> true
 
{isPrime 99504028301131}
-> true
 
{def upto
{def upto.loop
{lambda {:max :i :n}
{if {> :n :max}
then
else {if {isPrime :i}
then {tr {td n = :n} {td {@ style="text-align:right"} :i}}
{upto.loop :max
{BI.+ :i {BI.- :i 1}}
{BI.+ :n 1}}
else {upto.loop :max
{BI.+ :i 1}
:n} }}}}
{lambda {:n}
{upto.loop :n 42 1} }}
-> upto
 
{table
{upto 40}
}
->
n = 1 43
n = 2 89
n = 3 179
n = 4 359
n = 5 719
n = 6 1439
n = 7 2879
n = 8 5779
n = 9 11579
n = 10 23159
n = 11 46327
n = 12 92657
n = 13 185323
n = 14 370661
n = 15 741337
n = 16 1482707
n = 17 2965421
n = 18 5930887
n = 19 11861791
n = 20 23723597
n = 21 47447201
n = 22 94894427
n = 23 189788857
n = 24 379577741
n = 25 759155483
n = 26 1518310967
n = 27 3036621941
n = 28 6073243889
n = 29 12146487779
n = 30 24292975649
n = 31 48585951311
n = 32 97171902629
n = 33 194343805267
n = 34 388687610539
n = 35 777375221081
n = 36 1554750442183
n = 37 3109500884389
n = 38 6219001768781
n = 39 12438003537571
n = 40 24876007075181
 
stackoverflow for n > 40 on my iPad Pro, sorry.
 
</syntaxhighlight>
 
 
=={{header|Lua}}==
99

edits