Last active
January 1, 2016 13:44
-
-
Save tasuten/3c12f0469e58163c8ee1 to your computer and use it in GitHub Desktop.
書き初め@2016
This file contains 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
defmodule Kakizome do | |
def multiple_of_nine?(x) when not is_integer(x), do: false | |
# negative integer | |
def multiple_of_nine?(n) when n < 0, do: multiple_of_nine?(-n) | |
# 0, 1, 2, 3, 4, 5, 6, 7, 8 -> false | |
def multiple_of_nine?(n) when n <= 8 , do: false | |
def multiple_of_nine?(9), do: true | |
def multiple_of_nine?(n) do | |
# Is sum-of-digits-in-decimal multiple of 9 ? | |
n |> Integer.to_string |> String.codepoints |> \ | |
Enum.map(fn(x) -> String.to_integer(x) end) |> \ | |
Enum.sum |> multiple_of_nine? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
2016は9の倍数なので