-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Blake Thomas
committed
Dec 2, 2022
1 parent
72acf09
commit 51363a2
Showing
3 changed files
with
2,574 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
const { readFile } = require('fs/promises'); | ||
|
||
// 2a | ||
async function init() { | ||
const input = await readFile('two.txt', 'utf8'); | ||
// const input = await readFile('two.test.txt', 'utf8'); | ||
const data = input.split('\n'); | ||
|
||
let score = 0; | ||
|
||
data.forEach((d) => { | ||
const [opp, me] = d.split(' '); | ||
|
||
score += play(opp, me); | ||
score += value(me); | ||
}); | ||
|
||
console.log(score); | ||
} | ||
|
||
function play(opp, me) { | ||
if (me === 'X') { | ||
if (opp === 'A') { | ||
return 3; | ||
} | ||
if (opp === 'B') { | ||
return 0; | ||
} | ||
if (opp === 'C') { | ||
return 6; | ||
} | ||
} | ||
if (me === 'Y') { | ||
if (opp === 'A') { | ||
return 6; | ||
} | ||
if (opp === 'B') { | ||
return 3; | ||
} | ||
if (opp === 'C') { | ||
return 0; | ||
} | ||
} | ||
if (me === 'Z') { | ||
if (opp === 'A') { | ||
return 0; | ||
} | ||
if (opp === 'B') { | ||
return 6; | ||
} | ||
if (opp === 'C') { | ||
return 3; | ||
} | ||
} | ||
} | ||
|
||
function value(me) { | ||
if (me === 'X') { | ||
return 1; | ||
} | ||
if (me === 'Y') { | ||
return 2; | ||
} | ||
if (me === 'Z') { | ||
return 3; | ||
} | ||
|
||
throw new Error('bad me', me); | ||
} | ||
|
||
init(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
A Y | ||
B X | ||
C Z |
Oops, something went wrong.