Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/Floyds-triangle/Elixir/floyds-triangle.elixir
Normal file
18
Task/Floyds-triangle/Elixir/floyds-triangle.elixir
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
defmodule Floyd do
|
||||
def triangle(n) do
|
||||
max = trunc(n * (n + 1) / 2)
|
||||
widths = for m <- (max - n + 1)..max, do: (m |> Integer.to_string |> String.length) + 1
|
||||
format = Enum.map(widths, fn wide -> "~#{wide}w" end) |> List.to_tuple
|
||||
line(n, 0, 1, format)
|
||||
end
|
||||
|
||||
def line(n, n, _, _), do: :ok
|
||||
def line(n, i, count, format) do
|
||||
Enum.each(0..i, fn j -> :io.fwrite(elem(format,j), [count+j]) end)
|
||||
IO.puts ""
|
||||
line(n, i+1, count+i+1, format)
|
||||
end
|
||||
end
|
||||
|
||||
Floyd.triangle(5)
|
||||
Floyd.triangle(14)
|
||||
Loading…
Add table
Add a link
Reference in a new issue