Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solucion Reto #26 Elixir #1287

Open
fabigunner79 opened this issue Nov 10, 2023 · 0 comments
Open

Solucion Reto #26 Elixir #1287

fabigunner79 opened this issue Nov 10, 2023 · 0 comments

Comments

@fabigunner79
Copy link

#Fabian Garrido
#Elixir

 defmodule WeeklyChallenge2022 do
  @spec main() :: :ok
  def main do
    draw_polygon(10, :square)
    draw_polygon(15, :triangle)
    draw_polygon(12, :diamond)
  end

  @spec draw_polygon(integer(), atom()) :: :ok
  defp draw_polygon(size, type) when is_integer(size) and size >= 2 do
    total_size = if type == :diamond, do: size * 2, else: size

    1..total_size
    |> Enum.each(fn value ->
      case {type, value} do
        {:square, _} ->
          IO.puts(String.duplicate("* ", total_size))
        {:triangle, _} ->
          IO.puts(String.duplicate("* ", value))
        {:diamond, _} when value <= size ->
          IO.puts(String.duplicate("* ", value))
        {:diamond, _} ->
          spaces = String.duplicate("  ", value - size)
          stars = String.duplicate("* ", total_size - value)
          IO.puts("#{spaces}#{stars}")
      end
    end)

    IO.puts("")
  end
end

WeeklyChallenge2022.main() ```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant