22 lines
589 B
FSharp
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
|
|
|