Another day where I solved Part1 and had to go back to rewrite it when Part2 came around!
My insight was that you could count the length of the sequences of 1 joltage deltas, and use that to derive the number of possible combinations. Unfortunately, I wasn't able to figure out the general formula for sequenceLength->permutations, and had to hardcode the table 😣
Part 1
publicoverridelongSampleAnswer=>220;publicoverrideIEnumerable<int>ParseInput(stringrawInput)=>rawInput.Split(Environment.NewLine).Where(line=>line.Length>0).Select(line=>int.Parse(line));publicoverridelongSolve(IEnumerable<int>input){vardeltas=GetDeltas(input.OrderBy(x=>x).ToArray());returndeltas.Count(x=>x==1)*deltas.Count(x=>x==3);}protectedint[]GetDeltas(int[]values){vardeltas=newint[values.Length+1];for(vari=1;i<values.Length;i++){deltas[i]=values[i]-values[i-1];}deltas[0]=values[0];// joltage between outlet and first adapter.deltas[values.Length]=3;// joltage between last adapter and device.returndeltas;}
Another day where I solved Part1 and had to go back to rewrite it when Part2 came around!
My insight was that you could count the length of the sequences of 1 joltage deltas, and use that to derive the number of possible combinations. Unfortunately, I wasn't able to figure out the general formula for sequenceLength->permutations, and had to hardcode the table 😣
Part 1
Part 2