First commit
This commit is contained in:
commit
1dba0af064
36 changed files with 1065 additions and 0 deletions
30
geometry.ex
Normal file
30
geometry.ex
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
defmodule Geometry do
|
||||
def rectangle_area(a, b) do
|
||||
a * b
|
||||
end
|
||||
|
||||
def rectangle_area_condensed(a, b), do: a * b
|
||||
end
|
||||
|
||||
defmodule Rectangle do
|
||||
def area(a, b), do: a * b
|
||||
def area(a), do: area(a, a)
|
||||
end
|
||||
|
||||
defmodule GeometryMultiClause do
|
||||
def area({:rectangle, a, b}) do
|
||||
a * b
|
||||
end
|
||||
|
||||
def area({:square, a}) do
|
||||
a * a
|
||||
end
|
||||
|
||||
def area({:circle, r}) do
|
||||
r * r * 3.14159
|
||||
end
|
||||
|
||||
def area(unknown) do
|
||||
{:error, {:unkown_shape, unknown}}
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue