Untouchable numbers: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: elided the incorrect number of untouchable numbers for one million.) |
(Realize in F#) |
||
Line 62: | Line 62: | ||
<br><br> |
<br><br> |
||
=={{header|F_Sharp|F#}}== |
|||
===The Function=== |
|||
This task uses [[Extensible_prime_generator#The_functions|Extensible Prime Generator (F#)]] |
|||
<lang fsharp> |
|||
// Untouchable numbers. Nigel Galloway: January 31st., 2021 |
|||
let fN i (g::e as l)=let rec fN n x=match n with h::t->(let n=x+h in if n>i then None else fN t n) |_->Some((if x+g>i then [] else l),int x) in fN e 0L |
|||
let fG n (i::g as e) l=fN n (((e|>List.map((*)l))@e)|>List.distinct) |
|||
let uT g=let N,G,fN=Array.create g true,[|yield! primes64()|>Seq.takeWhile((>)(int64 g))|],fG (int64(g-1)) |
|||
let g=G.Length-1 |
|||
let rec fG n e l=match fN n G.[e] with Some([],z)->N.[z]<-false; match l with (n,e)::t->fG n e (if e<G.Length-1 then (n,e+1)::t else t) |_->() |
|||
|Some(n,z)->N.[z]<-false; fG n e (if e<G.Length-1 then (n,e+1)::l else l) |
|||
|_->match l with (n,e)::t->fG n e (if e<G.Length-1 then (n,e+1)::t else t) |_->() |
|||
N.[0]<-false; fG [1L] 0 [([1L],1)]; N |
|||
</lang> |
|||
===The Task=== |
|||
;Less than 2000 |
|||
<lang fsharp> |
|||
uT 2000|>Array.mapi(fun n g->(n,g))|>Array.filter(fun(_,n)->n)|>Array.chunkBySize 30|>Array.iter(fun n->n|>Array.iter(fst>>printf "%5d");printfn "") |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
2 5 52 88 96 120 124 146 162 188 206 210 216 238 246 248 262 268 276 288 290 292 304 306 322 324 326 336 342 372 |
|||
406 408 426 430 448 472 474 498 516 518 520 530 540 552 556 562 576 584 612 624 626 628 658 668 670 708 714 718 726 732 |
|||
738 748 750 756 766 768 782 784 792 802 804 818 836 848 852 872 892 894 896 898 902 926 934 936 964 966 976 982 996 1002 |
|||
1028 1044 1046 1060 1068 1074 1078 1080 1102 1116 1128 1134 1146 1148 1150 1160 1162 1168 1180 1186 1192 1200 1212 1222 1236 1246 1248 1254 1256 1258 |
|||
1266 1272 1288 1296 1312 1314 1316 1318 1326 1332 1342 1346 1348 1360 1380 1388 1398 1404 1406 1418 1420 1422 1438 1476 1506 1508 1510 1522 1528 1538 |
|||
1542 1566 1578 1588 1596 1632 1642 1650 1680 1682 1692 1716 1718 1728 1732 1746 1758 1766 1774 1776 1806 1816 1820 1822 1830 1838 1840 1842 1844 1852 |
|||
1860 1866 1884 1888 1894 1896 1920 1922 1944 1956 1958 1960 1962 1972 1986 1992 |
|||
Real: 00:00:00.229, CPU: 00:00:00.218, GC gen0: 141, gen1: 3, gen2: 1 |
|||
</pre> |
|||
;Count less than 100000 |
|||
<lang fsharp> |
|||
printfn "%d" (uT 100000|>Array.filter id|>Array.length) |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
13863 |
|||
Real: 00:07:12.230, CPU: 00:07:11.921, GC gen0: 341102, gen1: 43, gen2: 4 |
|||
</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |
||
{{trans|Wren}} |
{{trans|Wren}} |