Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
「シクシク素数列 Advent Calendar 2018」 23日目 Elixir
n = IO.gets("N: ") |> String.trim |> String.to_integer
# 0から100の整数列を作成したのち、まず4か9を含みかつ1の位が4ではない整数列となるようにしその後素数だけを残す。
IO.puts (0..100) |> Enum.map(fn(x) -> x end) |> Enum.filter(fn(x) -> Integer.to_string(x) |> String.match?(~r/(4\d)|9/) end) |> Enum.filter(fn(x) -> (2..(x - 1)) |> Enum.all?(fn(x2) -> rem(x, x2) != 0 end) end) |> Enum.slice(0, n) |> Enum.join(",")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment