Last active
March 1, 2025 22:31
-
-
Save voronoipotato/4577a0afb369a441a37f5880674320cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let twister (n: float) = | |
let n = min n 100. | |
let n = max 0. n | |
let a = n * 2. | |
//if a < 50 then 1 else 0 | |
let a' = | |
let x = min (n-50.) 0. | |
let y = min -x 1. | |
y | |
let b = (100. - n) * 2. | |
//if a >= 50 then 1 else 0 | |
let b' = | |
let x = max 0. (n - 50.) | |
let y = min 1. x | |
y | |
a' * a + b * b' | |
let cyclicTwister (n: int) = | |
let n = min n 100 | |
let n = max 0 n | |
let a = n * 2 | |
//if a < 50 then 1 else 0 | |
let a' = | |
let x = min (n-50) 0 | |
let y = min -x 1 | |
y | |
let b = (100 - n) * 2 | |
//if a >= 50 then 1 else 0 | |
let b' = | |
let x = max 0 (n - 50) | |
let y = min 1 x | |
y | |
a' * a + b * b' | |
let inline ap (f: 'a -> 'a) a i = | |
let rec ap' a i = | |
match i with | |
| 0 -> a | |
| n -> ap' (f a) (i-1) | |
ap' a i | |
let twist = ap twister >> Seq.initInfinite | |
let cycTwist = ap cyclicTwister >> Seq.initInfinite | |
//gets the "length" of the infinite sequence | |
let inline grab (m: 'a seq) = | |
let rec grab' seen l' = | |
let head = Seq.head l' | |
if seen |> Seq.contains head |> not then | |
grab' (head::seen) (l' |> Seq.tail) | |
else | |
seen | |
grab' [Seq.head m] (m |> Seq.tail) | |
let inline len (l: 'a seq) = grab l |> Seq.length | |
[1..100] |> List.map (cycTwist >> len) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment