You are viewing a single comment's thread. Return to all comments →
My Elixir solution:
defmodule Solution do def get_next(l) do [0] ++ (Enum.zip(l, tl l) |> Enum.map(fn {a, b} -> a+b end)) ++ [0] end def pasc(_, 0), do: [] def pasc(prev, iter) do next = get_next(prev) [next] ++ pasc(next, iter-1) end def get_pasc(n), do: [[0, 1, 0]] ++ pasc([0, 1, 0], n) end {n, _} = Integer.parse(IO.gets "") Solution.get_pasc(n-1) |> Enum.each(fn row -> Enum.reject(row, &(&1 == 0)) |> Enum.map(&Integer.to_string(&1) <> " ") |> List.to_string() # |> String.trim() |> IO.puts() end)
Seems like cookies are disabled on this browser, please enable them to open this website
Pascal's Triangle
You are viewing a single comment's thread. Return to all comments →
My Elixir solution: