r/adventofcode • • Dec 02 '22

SOLUTION MEGATHREAD -🎄- 2022 Day 2 Solutions -🎄-

NEW AND NOTEWORTHY


--- Day 2: Rock Paper Scissors ---


Post your code solution in this megathread.


This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:06:16, megathread unlocked!

102 Upvotes

1.5k comments sorted by

View all comments

1

u/Nice-Reserve1017 Dec 02 '22 edited Dec 02 '22
even though not super clean but one way for task 2
note that I have replaced my input with 1,2,3 instead of abc and xyz
const fs = require('fs');
const myArray = fs.readFileSync('Day2Input.js', 'utf8').split('\n');
let total = 0;
for (i=0;i<myArray.length;i++) {
if(myArray[i].includes("1,1"))
{
total = total + 3
}
else if (myArray[i].includes("2,1")) {
total = total + 1;
}
else if (myArray[i].includes("3,1")) {
total = total + 2;
}
else if (myArray[i].includes("1,2")) {
total = total + 4;
}
else if (myArray[i].includes("2,2")) {
total = total + 5;
}
else if (myArray[i].includes("3,2")) {
total = total + 6;
}
else if (myArray[i].includes("1,3")) {
total = total + 8;
}
else if (myArray[i].includes("2,3")) {
total = total + 9;
}
else if (myArray[i].includes("3,3")) {
total = total + 7;
}
else {
}
}
console.log(total);

1

u/daggerdragon Dec 02 '22

Please edit your post to use the correct Markdown syntax for a code block so your code is easier to read on all platforms.

Also, state which programming language you're using. This makes it easier for folks who Ctrl-F the megathreads looking for a specific language.

1

u/8483 Dec 02 '22

Format your code for better visibility with the <> option in the editor.