Skip to content

Commit 783209c

Browse files
committed
FP with Elixir: 04
1 parent dd733ef commit 783209c

File tree

1 file changed

+22
-0
lines changed
  • elixir/learn-fp-with-elixir/02.variables-and-functions/exercises

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
defmodule MatchstickFactory do
2+
def boxes(matchsticks) do
3+
big = div(matchsticks, 50)
4+
remaining_after_big = rem(matchsticks, 50)
5+
6+
medium = div(remaining_after_big, 20)
7+
remaining_after_medium = rem(remaining_after_big, 20)
8+
9+
small = div(remaining_after_medium, 5)
10+
remaining_matchsticks = rem(remaining_after_medium, 5)
11+
12+
%{
13+
big: big,
14+
medium: medium,
15+
small: small,
16+
remaining_matchsticks: remaining_matchsticks
17+
}
18+
end
19+
end
20+
21+
IO.inspect MatchstickFactory.boxes(98)
22+
IO.inspect MatchstickFactory.boxes(39)

0 commit comments

Comments
 (0)