Consecutive primes with ascending or descending differences: Difference between revisions

Content added Content deleted
m (Minor edit to Rust code)
(Realize in F#)
Line 279: Line 279:
</pre>
</pre>


This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)]
=={{header|F_Sharp|F#}}==
<lang fsharp>
// Longest ascending and decending sequences of difference between consecutive primes: Nigel Galloway. April 5th., 2021
let fN g fW=primes32()|>Seq.takeWhile((>)g)|>Seq.pairwise|>Seq.fold(fun(n,i,g)el->let w=fW el in match w>n with true->(w,el::i,g) |_->(w,[el],if List.length i>List.length g then i else g))(0,[],[])
for i in [1;2;6;12;18;100] do let _,_,g=fN(i*1000000)(fun(n,g)->g-n) in printfn "Longest ascending upto %d000000->%d:" i (g.Length+1); g|>List.rev|>List.iter(fun(n,g)->printf "%d (%d) %d " n (g-n) g); printfn ""
let _,_,g=fN(i*1000000)(fun(n,g)->n-g) in printfn "Longest decending upto %d000000->%d:" i (g.Length+1); g|>List.rev|>List.iter(fun(n,g)->printf "%d (%d) %d " n (g-n) g); printfn ""
</lang>
{{out}}
<pre>
Longest ascending upto 1000000->8:
128981 (2) 128983 128983 (4) 128987 128987 (6) 128993 128993 (8) 129001 129001 (10) 129011 129011 (12) 129023 129023 (14) 129037
Longest decending upto 1000000->8:
322171 (22) 322193 322193 (20) 322213 322213 (16) 322229 322229 (8) 322237 322237 (6) 322243 322243 (4) 322247 322247 (2) 322249
Longest ascending upto 2000000->9:
1319407 (4) 1319411 1319411 (8) 1319419 1319419 (10) 1319429 1319429 (14) 1319443 1319443 (16) 1319459 1319459 (18) 1319477 1319477 (32) 1319509 1319509 (34) 1319543
Longest decending upto 2000000->8:
322171 (22) 322193 322193 (20) 322213 322213 (16) 322229 322229 (8) 322237 322237 (6) 322243 322243 (4) 322247 322247 (2) 322249
Longest ascending upto 6000000->9:
1319407 (4) 1319411 1319411 (8) 1319419 1319419 (10) 1319429 1319429 (14) 1319443 1319443 (16) 1319459 1319459 (18) 1319477 1319477 (32) 1319509 1319509 (34) 1319543
Longest decending upto 6000000->9:
5051309 (32) 5051341 5051341 (28) 5051369 5051369 (14) 5051383 5051383 (10) 5051393 5051393 (8) 5051401 5051401 (6) 5051407 5051407 (4) 5051411 5051411 (2) 5051413
Longest ascending upto 12000000->9:
1319407 (4) 1319411 1319411 (8) 1319419 1319419 (10) 1319429 1319429 (14) 1319443 1319443 (16) 1319459 1319459 (18) 1319477 1319477 (32) 1319509 1319509 (34) 1319543
Longest decending upto 12000000->10:
11938793 (60) 11938853 11938853 (38) 11938891 11938891 (28) 11938919 11938919 (14) 11938933 11938933 (10) 11938943 11938943 (8) 11938951 11938951 (6) 11938957 11938957 (4) 11938961 11938961 (2) 11938963
Longest ascending upto 18000000->10:
17797517 (2) 17797519 17797519 (4) 17797523 17797523 (8) 17797531 17797531 (10) 17797541 17797541 (12) 17797553 17797553 (20) 17797573 17797573 (28) 17797601 17797601 (42) 17797643 17797643 (50) 17797693
Longest decending upto 18000000->10:
11938793 (60) 11938853 11938853 (38) 11938891 11938891 (28) 11938919 11938919 (14) 11938933 11938933 (10) 11938943 11938943 (8) 11938951 11938951 (6) 11938957 11938957 (4) 11938961 11938961 (2) 11938963
Longest ascending upto 100000000->11:
94097537 (2) 94097539 94097539 (4) 94097543 94097543 (8) 94097551 94097551 (10) 94097561 94097561 (12) 94097573 94097573 (14) 94097587 94097587 (16) 94097603 94097603 (18) 94097621 94097621 (30) 94097651 94097651 (32) 94097683
Longest decending upto 100000000->10:
11938793 (60) 11938853 11938853 (38) 11938891 11938891 (28) 11938919 11938919 (14) 11938933 11938933 (10) 11938943 11938943 (8) 11938951 11938951 (6) 11938957 11938957 (4) 11938961 11938961 (2) 11938963
Real: 00:00:04.708
</pre>
=={{header|Factor}}==
=={{header|Factor}}==
{{works with|Factor|0.99 2021-02-05}}
{{works with|Factor|0.99 2021-02-05}}