Elixir Today: Create a Left Triangle Pattern using Elixir

Photo by Nick Fewings on Unsplash

Elixir Today: Create a Left Triangle Pattern using Elixir

paugramming's photo
paugramming
·May 6, 2022·

1 min read

Subscribe to my newsletter and never miss my upcoming articles

Process

  • create a file named left_triangle.ex
  • write the code
left_triangle = fn n ->
  for i <- 0..n do
    for _ <- 0..i do
      "*"
    end
  end
  |> Enum.into("", fn string ->
    string = Enum.join(string)
    "#{string}\n"
  end)
end

IO.puts(left_triangle.(10))
IO.puts(left_triangle.(5))
  • run elixir left_triangle.ex

Result

*
**
***
****
*****
******
*******
********
*********
**********
***********

*
**
***
****
*****
******

Happy Coding!

 
Share this