Skip to content

Instantly share code, notes, and snippets.

@tasuten
Last active January 1, 2016 13:44
Show Gist options
  • Save tasuten/3c12f0469e58163c8ee1 to your computer and use it in GitHub Desktop.
Save tasuten/3c12f0469e58163c8ee1 to your computer and use it in GitHub Desktop.
書き初め@2016
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
@tasuten
Copy link
Author

tasuten commented Jan 1, 2016

2016は9の倍数なので

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment