Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Day 2: Rock Paper Scissors

2022/elixir/day-02.livemd

Day 2: Rock Paper Scissors

Mix.install([:kino])

Part 1

input = Kino.Input.textarea("Input")
score = %{
  {"A", "X"} => 3 + 1,
  {"A", "Y"} => 6 + 2,
  {"A", "Z"} => 0 + 3,
  {"B", "X"} => 0 + 1,
  {"B", "Y"} => 3 + 2,
  {"B", "Z"} => 6 + 3,
  {"C", "X"} => 6 + 1,
  {"C", "Y"} => 0 + 2,
  {"C", "Z"} => 3 + 3
}

input
|> Kino.Input.read()
|> String.split("\n")
|> Enum.map(&String.split/1)
|> Enum.map(fn [x, y] -> score[{x, y}] end)
|> Enum.sum()

Part 2

score = %{
  # C
  {"A", "X"} => 0 + 3,
  # A
  {"A", "Y"} => 3 + 1,
  # B
  {"A", "Z"} => 6 + 2,
  # A
  {"B", "X"} => 0 + 1,
  # B
  {"B", "Y"} => 3 + 2,
  # C
  {"B", "Z"} => 6 + 3,
  # B
  {"C", "X"} => 0 + 2,
  # C
  {"C", "Y"} => 3 + 3,
  # A
  {"C", "Z"} => 6 + 1
}

input
|> Kino.Input.read()
|> String.split("\n")
|> Enum.map(&String.split/1)
|> Enum.map(fn [x, y] -> score[{x, y}] end)
|> Enum.sum()