Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
sum digits in Harmonia
module Fib using: Platform where
open Platform Prelude expose [+, parse, as-string, ~]
open Platform List expose [zip:using:, map:, take:, filter:, sum]
open Platform IO expose [read-line, print]
-- Typing things is currently cumbersome, but the type inference algorithm should catch 90% of this
let (Num a) => String -> a ::
x as-number = x parse
-- ~ is cons.
let fibs = 0 ~ 1 ~ fibs zip: fibs tail using: +
let n sum-digits = n as-string map: as-number |> sum
let main: _ = read-line >>= { x => fibs filter: even
|> take: x as-number
|> sum
|> sum-digits
|> print
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment