Super-d numbers: Difference between revisions
Content added Content deleted
m (added a trademark glyph to MathWorld.) |
(Realize in F#) |
||
Line 27: | Line 27: | ||
=={{header|F_Sharp|F#}}== |
|||
;The Function |
|||
<lang fsharp> |
|||
// Generate Super-N numbers. Nigel Galloway: October 12th., 2019 |
|||
let superD N= |
|||
let I=bigint(pown 10 N) |
|||
let G=bigint N |
|||
let E=G*(111111111I%I) |
|||
let rec fL n=match (E-n%I).IsZero with true->true |_->if (E*10I)<n then false else fL (n/10I) |
|||
seq{1I..999999999999999999I}|>Seq.choose(fun n->if fL (G*n**N) then Some n else None) |
|||
</lang> |
|||
;The Task |
|||
<lang fsharp> |
|||
superD 2 |> Seq.take 10 |> Seq.iter(printf "%A "); printfn "" |
|||
superD 3 |> Seq.take 10 |> Seq.iter(printf "%A "); printfn "" |
|||
superD 4 |> Seq.take 10 |> Seq.iter(printf "%A "); printfn "" |
|||
superD 5 |> Seq.take 10 |> Seq.iter(printf "%A "); printfn "" |
|||
superD 6 |> Seq.take 10 |> Seq.iter(printf "%A "); printfn "" |
|||
superD 7 |> Seq.take 10 |> Seq.iter(printf "%A "); printfn "" |
|||
superD 8 |> Seq.take 10 |> Seq.iter(printf "%A "); printfn "" |
|||
superD 9 |> Seq.take 10 |> Seq.iter(printf "%A "); printfn "" |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
19 31 69 81 105 106 107 119 127 131 |
|||
261 462 471 481 558 753 1036 1046 1471 1645 |
|||
1168 4972 7423 7752 8431 10267 11317 11487 11549 11680 |
|||
4602 5517 7539 12955 14555 20137 20379 26629 32767 35689 |
|||
27257 272570 302693 323576 364509 502785 513675 537771 676657 678146 |
|||
140997 490996 1184321 1259609 1409970 1783166 1886654 1977538 2457756 2714763 |
|||
185423 641519 1551728 1854230 6415190 12043464 12147605 15517280 16561735 18542300 |
|||
17546133 32613656 93568867 107225764 109255734 113315082 121251742 175461330 180917907 182557181 |
|||
</pre> |
|||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
<lang factor>USING: arrays formatting io kernel lists lists.lazy math |
<lang factor>USING: arrays formatting io kernel lists lists.lazy math |