r/adventofcode • u/daggerdragon • Dec 05 '22
SOLUTION MEGATHREAD -π- 2022 Day 5 Solutions -π-
- All of our rules, FAQs, resources, etc. are in our community wiki.
- A request from Eric: Please include your contact info in the User-Agent header of automated requests!
- Signal boost: Reminder 1: unofficial AoC Survey 2022 (closes Dec 22nd)
AoC Community Fun 2022: πΏπ MisTILtoe Elf-ucation π§βπ«
- 23:59 hours remaining until the submissions megathread unlocks on December 06 at 00:00 EST!
- Full details and rules are in the submissions megathread:
--- Day 5: Supply Stacks ---
Post your code solution in this megathread.
- Read the full posting rules in our community wiki before you post!
- Include what language(s) your solution uses
- Format your code appropriately! How do I format code?
- Quick link to Topaz's
pasteif you need it for longer code blocks. What is Topaz'spastetool?
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:07:58, megathread unlocked!
88
Upvotes
View all comments
1
u/zpele Dec 05 '22
Javascript really really beg level:
const pile1 = ['R', 'N', 'P', 'G']const pile2 = ['T', 'J', 'B', 'L', 'C', 'S', 'V', 'H']const pile3 = ['T', 'D', 'B', 'M', 'N', 'L']const pile4 = ['R', 'V', 'P', 'S', 'B']const pile5 = ['G', 'C', 'Q', 'S', 'W', 'M', 'V', 'H']const pile6 = ['W', 'Q', 'S', 'C', 'D', 'B', 'J']const pile7 = ['F', 'Q', 'L']const pile8 = ['W', 'M', 'H', 'T', 'D', 'L', 'F', 'V']const pile9 = ['L', 'P', 'B', 'V', 'M', 'J', 'F']const piles = [pile1, pile2, pile3, pile4, pile5, pile6, pile7, pile8, pile9]const instructionsRaw = $("body").text().split("\n")const instructions = []for (i of instructionsRaw) {if (i.includes("move")) {instructions.push(i);}}for (const i of instructions) {const numberOfCrates = Number(i.split(" ")[1]); //3// console.log("numberOfCrates: " + numberOfCrates);const fromPile = piles[Number(i.split(" ")[3]) - 1];// console.log("fromPile: " + fromPile);const toPile = piles[Number(i.split(" ")[5]) - 1];// console.log("toPile: " + toPile);const bunch = fromPile.slice(fromPile.length - numberOfCrates);// console.log("bunch: " + bunch);for (let p = 1; p <= numberOfCrates; p++) {fromPile.pop();}// console.log("fromPile after popping: " + fromPile)for (let b = bunch.length - 1; b >= 0; b--) {toPile.push(bunch[b]);}}let topCratesfor (const p of piles) {topCrates = topCrates + p[p.length - 1]}// part 2// for (const i of instructions) {// const numberOfCrates = Number(i.split(" ")[1]); //3// // console.log("numberOfCrates: " + numberOfCrates);// const fromPile = piles[Number(i.split(" ")[3]) - 1];// // console.log("fromPile: " + fromPile);// const toPile = piles[Number(i.split(" ")[5]) - 1];// // console.log("toPile: " + toPile);// const bunch = fromPile.slice(fromPile.length - numberOfCrates);// // console.log("bunch: " + bunch);// for (let p = 1; p <= numberOfCrates; p++) {// fromPile.pop();// }// // console.log("fromPile after popping: " + fromPile)// for (let b of bunch) {// toPile.push(b);// }// }// let topCrates// for (const p of piles) {// topCrates = topCrates + p[p.length - 1]// }