Skip to content

Commit

Permalink
Refactor cube extraction logic in Day2 module
Browse files Browse the repository at this point in the history
  • Loading branch information
samjowen committed Dec 27, 2023
1 parent 1548c62 commit 71f1c72
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions lib/day2/day2.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,24 @@ defmodule Day2 do

cube_list = String.split(set_string, ",")

Enum.reduce(cube_list, initial_cube_map, fn x, acc ->
case String.contains?(x, "red") do
true -> Map.put(acc, :red, extract_integer(x))
false -> acc
end
Enum.reduce(cube_list, initial_cube_map, fn cube, acc ->
acc
|> (fn acc ->
case String.contains?(x, "green") do
true -> Map.put(acc, :green, extract_integer(x))
false -> acc
case String.contains?(cube, "red") do
true -> Map.put(acc, :red, extract_integer(cube))
_ -> acc
end
end).()
|> (fn acc ->
case String.contains?(x, "blue") do
true -> Map.put(acc, :blue, extract_integer(x))
false -> acc
case String.contains?(cube, "green") do
true -> Map.put(acc, :green, extract_integer(cube))
_ -> acc
end
end).()
|> (fn acc ->
case String.contains?(cube, "blue") do
true -> Map.put(acc, :blue, extract_integer(cube))
_ -> acc
end
end).()
end)
Expand Down

0 comments on commit 71f1c72

Please sign in to comment.