Boustrophedon transform: Difference between revisions
Content added Content deleted
(New post.) |
(Realize in F#) |
||
Line 113: | Line 113: | ||
</pre> |
</pre> |
||
=={{header|F_Sharp|F#}}== |
|||
===The function=== |
|||
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)] |
|||
<syntaxhighlight lang="fsharp"> |
|||
// Boustrophedon transform. Nigel Galloway:October 26th., 2023 |
|||
let fG n g=let rec fG n g=[match g with h::[]->yield n+h |h::t->yield n+h; yield! fG (n+h) t] in [yield n; yield! fG n g]|>List.rev |
|||
let rec Boustrophedon n g=seq{yield List.head g; yield! Boustrophedon n (fG (n()) g)} |
|||
</syntaxhighlight> |
|||
===The Task=== |
|||
<syntaxhighlight lang="fsharp"> |
|||
printfn "zeroes"; Boustrophedon (fun()->0I) [1I]|>Seq.take 15|>Seq.iter(printf "%A "); printfn "" |
|||
let n=sprintf $"%A{Boustrophedon (fun()->0I) [1I]|>Seq.item 999}" in printfn "%s ... %s (%d digits)" n[0..19] n[n.Length-20..n.Length] (n.Length) |
|||
printfn "ones"; Boustrophedon (fun()->1I) [1I]|>Seq.take 15|>Seq.iter(printf "%A "); printfn "" |
|||
let n=sprintf $"%A{Boustrophedon (fun()->1I) [1I]|>Seq.item 999}" in printfn "%s ... %s (%d digits)" n[0..19] n[n.Length-20..n.Length] (n.Length) |
|||
printfn "1,-1,1,-1....."; Boustrophedon (let mutable n=1I in (fun()->n<- -n; n)) [1I]|>Seq.take 15|>Seq.iter(printf "%A "); printfn "" |
|||
let n=sprintf $"%A{Boustrophedon (let mutable n=1I in (fun()->n<- -n; n)) [1I]|>Seq.item 999}" in printfn "%s ... %s (%d digits)" n[0..19] n[n.Length-20..n.Length] (n.Length) |
|||
printfn "factorials"; Boustrophedon (let mutable n,g=1I,2I in (fun()->let r=n in n<-n*g; g<-g+1I; r)) [1I]|>Seq.take 15|>Seq.iter(printf "%A "); printfn "" |
|||
let n=sprintf $"%A{Boustrophedon (let mutable n,g=1I,2I in (fun()->let r=n in n<-n*g; g<-g+1I; r)) [1I]|>Seq.item 999}" in printfn "%s ... %s (%d digits)" n[0..19] n[n.Length-20..n.Length] (n.Length) |
|||
printfn "primes"; let p=primesI() in Boustrophedon (fun()->Seq.head p) [Seq.head p]|>Seq.take 15|>Seq.iter(printf "%A "); printfn "" |
|||
let p=primesI() in let n=sprintf $"%A{Boustrophedon (fun()->Seq.head p) [Seq.head p]|>Seq.item 999}" in printfn "%s ... %s (%d digits)" n[0..19] n[n.Length-20..n.Length] (n.Length) |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
zeroes |
|||
1 1 1 2 5 16 61 272 1385 7936 50521 353792 2702765 22368256 199360981 |
|||
61065678604283283233 ... 63588348134248415232 (2369 digits) |
|||
ones |
|||
1 2 4 9 24 77 294 1309 6664 38177 243034 1701909 13001604 107601977 959021574 |
|||
29375506567920455903 ... 86575529609495110509 (2370 digits) |
|||
1,-1,1,-1..... |
|||
1 0 0 1 0 5 10 61 280 1665 10470 73621 561660 4650425 41441530 |
|||
12694307397830194676 ... 15354198638855512941 (2369 digits) |
|||
factorials |
|||
1 2 5 17 73 381 2347 16701 134993 1222873 12279251 135425553 1627809401 21183890469 296773827547 |
|||
13714256926920345740 ... 19230014799151339821 (2566 digits) |
|||
primes |
|||
2 5 13 35 103 345 1325 5911 30067 172237 1096319 7677155 58648421 485377457 4326008691 |
|||
13250869953362054385 ... 82450325540640498987 (2371 digits) |
|||
</pre> |
|||
=={{header|J}}== |
=={{header|J}}== |
||
Implementation:<syntaxhighlight lang=J>b=: {{ |
Implementation:<syntaxhighlight lang=J>b=: {{ |