Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
16
Task/Sierpinski-carpet/Elixir/sierpinski-carpet.elixir
Normal file
16
Task/Sierpinski-carpet/Elixir/sierpinski-carpet.elixir
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
defmodule RC do
|
||||
def sierpinski_carpet(n), do: sierpinski_carpet(n, ["#"])
|
||||
|
||||
def sierpinski_carpet(0, carpet), do: carpet
|
||||
def sierpinski_carpet(n, carpet) do
|
||||
new_carpet = Enum.map(carpet, fn x -> x <> x <> x end) ++
|
||||
Enum.map(carpet, fn x -> x <> String.replace(x, "#", " ") <> x end) ++
|
||||
Enum.map(carpet, fn x -> x <> x <> x end)
|
||||
sierpinski_carpet(n-1, new_carpet)
|
||||
end
|
||||
end
|
||||
|
||||
Enum.each(0..3, fn n ->
|
||||
IO.puts "\nN=#{n}"
|
||||
Enum.each(RC.sierpinski_carpet(n), fn line -> IO.puts line end)
|
||||
end)
|
||||
Loading…
Add table
Add a link
Reference in a new issue