Boustrophedon transform: Difference between revisions
Content added Content deleted
(New post.) |
(→F#: Remove mutable data probably more idiotmatic) |
||
Line 251: | Line 251: | ||
<syntaxhighlight lang="fsharp"> |
<syntaxhighlight lang="fsharp"> |
||
// Boustrophedon transform. Nigel Galloway:October 26th., 2023 |
// Boustrophedon transform. Nigel Galloway:October 26th., 2023 |
||
let fG n g=let rec fG n g=[match |
let fG n g=let rec fG n g=[match n with h::[]->yield g+h |h::t->yield g+h; yield! fG t (g+h)] in [yield g; yield! fG n g]|>List.rev |
||
let |
let Boustrophedon n=Seq.scan(fun n g->fG n g)[Seq.head n] (Seq.tail n)|>Seq.map(List.head) |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
===The Task=== |
===The Task=== |
||
<syntaxhighlight lang="fsharp"> |
<syntaxhighlight lang="fsharp"> |
||
printfn "zeroes"; |
printfn "zeroes"; Seq.unfold(fun n->Some(n,0I))1I|>Seq.take 15|>Boustrophedon|>Seq.iter(printf "%A "); printfn "" |
||
let n=sprintf $"%A{ |
let n=sprintf $"%A{Seq.unfold(fun n->Some(n,0I))1I|>Boustrophedon|>Seq.item 999}" in printfn "%s ... %s (%d digits)" n[0..19] n[n.Length-20..n.Length] (n.Length) |
||
printfn "ones"; |
printfn "ones"; Seq.unfold(fun n->Some(n,n))1I|>Seq.take 15|>Boustrophedon|>Seq.iter(printf "%A "); printfn "" |
||
let n=sprintf $"%A{ |
let n=sprintf $"%A{Seq.unfold(fun n->Some(n,n))1I|>Boustrophedon|>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....."; |
printfn "1,-1,1,-1....."; Seq.unfold(fun n->Some(n,-n))1I|>Boustrophedon|>Seq.take 15|>Seq.iter(printf "%A "); printfn "" |
||
let n=sprintf $"%A{ |
let n=sprintf $"%A{Seq.unfold(fun n->Some(n,-n))1I|>Boustrophedon|>Seq.item 999}" in printfn "%s ... %s (%d digits)" n[0..19] n[n.Length-20..n.Length] (n.Length) |
||
printfn "factorials"; |
printfn "factorials"; Seq.unfold(fun(n,g)->Some(n,(n*g,g+1I)))(1I,1I)|>Boustrophedon|>Seq.take 15|>Seq.iter(printf "%A "); printfn "" |
||
let n=sprintf $"%A{ |
let n=sprintf $"%A{Seq.unfold(fun(n,g)->Some(n,(n*g,g+1I)))(1I,1I)|>Boustrophedon|>Seq.item 999}" in printfn "%s ... %s (%d digits)" n[0..19] n[n.Length-20..n.Length] (n.Length) |
||
printfn "primes"; let p= |
printfn "primes"; let p=primes() in Seq.initInfinite(fun _->bigint(p()))|>Boustrophedon|>Seq.take 15|>Seq.iter(printf "%A "); printfn "" |
||
let n=sprintf $"%A{let p=primes() in Seq.initInfinite(fun _->bigint(p()))|>Boustrophedon|>Seq.item 999}" in printfn "%s ... %s (%d digits)" n[0..19] n[n.Length-20..n.Length] (n.Length) |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
{{out}} |
{{out}} |