One of my colleagues came up with something completely different which I thought was interesting:
(This is translated from python to elixir)
File.stream!("/Users/kwando/projects/AoC2022/02/input.txt")
|> Stream.map(fn line -> String.trim(line) |> String.to_charlist() end)
|> Enum.reduce(0, fn [elf, _, you], score ->
shape_score = you - ?X + 1
case {elf - ?A, you - ?X} do
{any, any} ->
score + 3 + shape_score
{elf, you} when rem(you + 2, 3) == elf ->
score + 6 + shape_score
{_, _} ->
score + shape_score
end
end)
https://github.com/nilskj/AdventOfCode2022/blob/master/day02a.py






















