Skip to content

Instantly share code, notes, and snippets.

@DeepSnowNeeL
Last active December 3, 2022 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DeepSnowNeeL/00e81101fd3157c72f0940acb72d6445 to your computer and use it in GitHub Desktop.
Save DeepSnowNeeL/00e81101fd3157c72f0940acb72d6445 to your computer and use it in GitHub Desktop.
Advent Of Code 2022 - shitty solutions 🤮
//AOC 1 - 1
temp1.wholeText.split("\n\n").map(txt=>txt.split("\n")).map(arr => arr.map(str=>parseInt(str,10))).map(arr => arr.reduce((sum,a)=>sum+a,0)).sort((a,b)=> a-b)[237]
//AOC 1 - 2
temp1.wholeText.split("\n\n").map(txt=>txt.split("\n")).map(arr => arr.map(str=>parseInt(str,10))).map(arr => arr.reduce((sum,a)=>sum+a,0)).sort((a,b)=> a-b).slice(-4).slice(0,3).reduce((sum,a)=>sum+a,0)
//AOC 2 - 1
const pts = { 'X':1,'Y':2,'Z':3};
const winCond = { 'AX':3, 'AY':6, 'AZ':0, 'BX':0, 'BY':3, 'BZ':6, 'CX':6, 'CY':0, 'CZ':3 };
temp1.textContent.split("\n").slice(0,-1).map(a=>a.split(" ")).map(round =>{
console.log(round, pts[round[1]] , winCond[round[0]+round[1]]);
return pts[round[1]] + winCond[round[0]+round[1]];
}).reduce((sum,a)=>sum+a,0);
//AOC 2-2
//A for Rock, B for Paper, and C for Scissors
//X for Rock, Y for Paper, and Z for Scissors
//X lose, Y draw, and Z win
const whatShouldWePlay = { 'AX':'Z','AY':'X','AZ':'Y',
'BX':'X','BY':'Y','BZ':'Z',
'CX':'Y','CY':'Z','CZ':'X'};
const pts = { 'X':1,'Y':2,'Z':3};
const winCond = { 'AX':3, 'AY':6, 'AZ':0, 'BX':0, 'BY':3, 'BZ':6, 'CX':6, 'CY':0, 'CZ':3 };
temp1.textContent.split("\n").slice(0,-1).map(a=>a.split(" ")).map(round =>{
console.log(round[0]+round[1], whatShouldWePlay[round[0]+round[1]], 'pts',pts[whatShouldWePlay[round[0]+round[1]]] , 'winpts', winCond[round[0]+whatShouldWePlay[round[0]+round[1]]]);
return pts[whatShouldWePlay[round[0]+round[1]]] + winCond[round[0]+whatShouldWePlay[round[0]+round[1]]];
}).reduce((sum,a)=>sum+a,0);
//AOC 3-1
const value = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
temp1.textContent.split("\n").slice(0,-1).map(sack=>{
const sack1 = sack.substr(0,sack.length/2).split("");
const sack2 = sack.substr(sack.length/2).split("");
const letter = sack1.filter(a=> sack2.some(b=> a === b))[0];
console.log(letter,value.indexOf(letter)+1);
return value.indexOf(letter)+1;
}).reduce((sum,a)=>sum+a,0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment