How to resolve the algorithm Hilbert curve step by step in the F# programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Hilbert curve step by step in the F# programming language
Table of Contents
Problem Statement
Produce a graphical or ASCII-art representation of a Hilbert curve of at least order 3.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Hilbert curve step by step in the F# programming language
Source code in the fsharp programming language
// Hilbert curve. Nigel Galloway: September 18th., 2023
type C= |At|Cl|Ab|Cr
type D= |Z|U|D|L|R
let fD=function Z->0,0 |U->0,1 |D->0,-1 |L-> -1,0 |R->1,0
let fC=function At->[fD D;fD R;fD U] |Cl->[fD R;fD D;fD L] |Ab->[fD U;fD L;fD D] |Cr->[fD L;fD U;fD R]
let order(n,g)=match g with At->[n,Cl;D,At;R,At;U,Cr]
|Cl->[n,At;R,Cl;D,Cl;L,Ab]
|Ab->[n,Cr;U,Ab;L,Ab;D,Cl]
|Cr->[n,Ab;L,Cr;U,Cr;R,At]
let hilbert=Seq.unfold(fun n->Some(n,n|>List.collect order))[Z,At]
hilbert|>Seq.take 7|>Seq.iteri(fun n g->Chart.Line(g|>Seq.collect(fun(n,g)->(fD n)::(fC g))|>Seq.scan(fun(x,y)(n,g)->(x+n,y+g))(0,0))|>Chart.withTitle(sprintf "Hilbert order %d" n)|>Chart.show)
You may also check:How to resolve the algorithm Averages/Arithmetic mean step by step in the Fish programming language
You may also check:How to resolve the algorithm Sort using a custom comparator step by step in the Perl programming language
You may also check:How to resolve the algorithm Arrays step by step in the NSIS programming language
You may also check:How to resolve the algorithm Integer sequence step by step in the Delphi programming language
You may also check:How to resolve the algorithm Commatizing numbers step by step in the C# programming language