AnnouncementsMatrixEventsFunnyVideosMusicAncapsTechnologyEconomicsPrivacyGIFSCringeAnarchyFilmPicsThemesIdeas4MatrixAskMatrixHelpTop Subs
3

We did this last year. But this year I guess we are already behind. If you don't know what Advent of Code is, it is a series of coding challenges with a new one every day. It would typically run starting on the first until the 25th. But this year they are only going to the twelth.

https://adventofcode.com/

I'm not always sure how to format these. I may just wing it. Folks can share their solutions in code blocks here or give a link to a repo if they would like. Advent of code starts off pretty easy and then ramps up to some genuinely hard problems. So I would encourage people to try the first few even if you are a beginner. You can even pipe it into AI if that is your current level.

Also each day comes in two parts. The second part is usually harder than the first. Because I am starting behind anyone is welcome to start a thread if you are ahead of me.

Comment preview

[-]x0x70(0|0)

Here is my solution to part one:

#!/usr/bin/env node

var fs = require('fs');

module.exports.lineToInt=lineToInt;
function lineToInt(line) {
 var prefix = line.slice(0,1);
 var magnitude = parseInt(line.slice(1));
 if(prefix==='R') return magnitude; 
 if(prefix==='L') return -magnitude;
 throw new Error('Improper prefix');
}

module.exports.readlinesSync=readlinesSync;
function readlinesSync(path) {
 return fs.readFileSync(path,'utf8').split('\n').filter(i=>i);
}

module.exports.circleMod=circleMod;
function circleMod(a,base=100) {
 if(a<0) return base-circleMod(-a,base);
 return a%base;
}


function main() {
 var path = process.argv[2]||'input.txt';
 var inputs = readlinesSync(path);
     //inputs = inputs.map(lineToInt);
 var start = 50;
 var pointer = start;
 var zerocount = 0;
 for(var input of inputs) {
  var numInput = circleMod(lineToInt(input));
  pointer=circleMod(pointer+numInput);
  console.log({input,numInput,pointer});
  if(pointer===0) ++zerocount;
 }
 console.log('Password:',zerocount);
}

if(!module.parent) main();

I've yet to figure it out but for some reason applying circleMod to the input in addition to pointer changed the output. In theory if the circleMod is working correctly it shouldn't make a difference. But this is the nature of advent of code. Get the solution and move on. I'm working on part 2 now.