Last active
August 29, 2015 14:00
-
-
Save robotlolita/11175586 to your computer and use it in GitHub Desktop.
sum digits in Harmonia
This file contains hidden or 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
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 | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment