18
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Elixir言語で5の倍数と5のつく数字だけヒロミゴーする

Posted at

経緯

完全に@kmagaiさんのGo言語で5の倍数と5のつく数字だけヒロミゴーするに乗っかりました。

Goではないですが、どんな言語でもヒロミゴーでエキゾチック・ジャパンなFizzBuzzして良いのでは???という思いです。

ルールは全く同じ。5がつく数字でExotic、5の倍数でJapan、両立したらExotic Japan。

コード

go.exs
defmodule ExoticJapan do
  def go!(num) when num > 0 do
    Enum.each 1..num, fn (i) ->
      IO.puts "#{i} " <> hiromi(exotic?(i), japan?(i))
    end
  end

  defp hiromi(true,   true), do: "Exotic Japan"
  defp hiromi(true,  false), do: "Exotic"
  defp hiromi(false,  true), do: "Japan"
  defp hiromi(false, false), do: ""

  defp exotic?(num), do: to_string(num) |> String.contains?("5")

  defp japan?(num), do: rem(num, 5) == 0
end

System.argv |> List.first |> String.to_integer |> ExoticJapan.go!
$ elixir go.exs 240000000

所感

hiromi/2が美しくない。もうちょっとどうにかならんかね。

18
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?