Files
project-euler/92.fs
T
2025-08-03 20:16:55 -07:00

22 lines
589 B
FSharp

module _92
open common
let squareChainLoop =
let squareDigits d =
let square n = n * n
d |> numDigits |> Seq.map square |> Seq.sum
let chainDict = new System.Collections.Generic.Dictionary<int,int>()
let rec chainCache = function
| x when chainDict.ContainsKey(x) -> chainDict.[x]
| 1 -> 1
| 89 -> 89
| x -> chainDict.[x] <- chainCache (squareDigits x); chainDict.[x]
allIntegers |> Seq.skip 1 |> Seq.takeWhile ((>) 10000000)
|> Seq.map chainCache
|> Seq.filter ((=) 89)
|> Seq.length