F#
let rec extractDigits acc input = if input <= 9 then input::acc else extractDigits (input % 10::acc) (input/10) let sumOfSquares input = input |> List.fold(fun acc i -> acc + i*i) 0 let rec isHappy input = if input = 1 then true else if input >= 2 && input <=6 then false else let newInput = input |> extractDigits List.empty |> sumOfSquares isHappy newInput [<EntryPoint>] let main argv = [1..10000] |> List.filter(fun i -> isHappy i) |> List.iter(fun i -> printfn "%d" i) 0
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
F#