Elixir Shape Area
defmodule ShapeArea do
def shape_area(1), do: 1
def shape_area(n), do: shape_area(n - 1) + 4 * (n - 1)
end
This returns the area of the growing n-interesting polygon using the direct formula instead of building the shape.
defmodule ShapeArea do
def shape_area(1), do: 1
def shape_area(n), do: shape_area(n - 1) + 4 * (n - 1)
end
This returns the area of the growing n-interesting polygon using the direct formula instead of building the shape.