Xah Talk Show 2022-12-13 Advent of Code Day 2, in WolframLang, emacs lisp, JavaScript

Problem Description

problem: given a string of lines, like this:

A Y
B X
C Z

and we have the following relation, where the right side win:

third column, is the result of y - x
1 1 draw , 0
1 2 win, 1
1 3 lose, 2

2 1 lose, -1
2 2 draw, 0
2 3 win, 1

3 1 win, -2
3 2 lose, -1
3 3 draw, 0

if outcome -1, → 0
if outcome 0, → 3
if outcome 1, → 6

Table[ { {x, y}, {Mod[x, 2], Mod[y, 2]}, {Mod[x, 2] - Mod[y, 2]} }, {x, 0,2}, {y, 0,2} ]

0 % 2 = 0
1 % 2 = 1
2 % 2 = 0

0 % 2 = 0
1 % 2 = 1
2 % 2 = 0
Clear[xinput, fComputeLineScore, x6, xanswer  ]

fComputeLineScore[{x_, y_}] := y + 1 + Mod[ ( Mod[y + 3-x, 3] ) + 1, 3] 3

xinput = "
A Y
B X
C Z";

x6 = Map[ fComputeLineScore,
  ToExpression[
   Partition[
    StringSplit[
     StringReplace[
      xinput, { "A" -> "0", "B" -> "1", "C" -> "2", "X" -> "0",
       "Y" -> "1", "Z" -> "2" } ] ], 2 ] ] ]
xanswer = Total @ x6
Table[ {{x, y }, {Mod[ x, 3 ], Mod[ y, 3 ]}}, {x, 0, 2}, {y, 0, 2} ]
Table[ {x, y, ( Mod[y+3-x, 3] ) }, {x, 0, 2}, {y, 0, 2} ]
Table[ {x, y, Mod[ ( Mod[y + 3-x, 3] ) + 1, 3] }, {x, 0, 2}, {y, 0, 2} ]//TableForm
advent of code 2022 day 2 2022-12-13 mMRRx
advent of code 2022 day 2 2022-12-13 mMRRx
advent of code 2022 day 2 2022-12-13 vGmqt
advent of code 2022 day 2 2022-12-13 vGmqt

2022 Advent of Code