What are you coding?

Day 3 „spoiler" meme

image

3 Likes
Day 3 part 1

I scanned through the input data each row at a time, scanning each row character by character; terminating numbers and then storing them with a complete list of their digit locations. In the same scan, I also made note of symbols and their positions.

And then I iterated over each symbol and collected a list of numbers that were adjacent by calling a method on the part number location object that accounted for adjacency (and without optimizations, also wasted a bunch of cycles checking if the symbol was somehow in the same position as the one of the digits; no need to optimize yet). I then stored the symbol and its associated adjacent part numbers in another object.

Then it was a matter of just collecting all of the part numbers associated with a symbol (removing duplicates… which I don’t think was necessary…) and throwing them all in a list to be added.

This worked very well, except I forgot to break and finalize a number when a symbol was encountered. So rather than 123*456 getting identified as the * symbol with 123 and 456 numbers associated, it was getting stored as * with a single 123456. Remember what I said about letting the logic look “inside” the number? Yeah, I shouldn’t have done that… but then I probably would have had an even harder time figuring this out.

Day 3 part 2

So… I already had a complete list of the symbols and their associated part numbers. This part 2 was even easier than yesterday because I had accidentally prepared for it… or maybe I’m getting better at anticipating the “wrinkles”?

1 Like

Muhaha, finally a day for trickery and hackery. I am proud of my hackiest solution so far.

Day 4 Part 1.
        scratchCard = scratchCard.replaceAll( "  ", " 0" ); //to trick those single digits into behaving
        String winnersRegex = scratchCard.substring( scratchCard.indexOf( ":" ) + 1, scratchCard.indexOf( "|" ) ).trim().replace( ' ', '|' );
        String numbers = scratchCard.substring( scratchCard.indexOf( "|" ) );
        Matcher matcher = Pattern.compile( winnersRegex ).matcher( numbers );
        int count = 0;
        while ( matcher.find() ) {count++;}
        return count;

I am keeping Part 2 for lunchbreak or tonight. It looks to be a bit more complex. upon looking again: nope not that bad.

1 Like

I took longer than I needed to because I was deploying nom. (Why yes, three spaces doesn’t parse as one space.)

Otherwise straightforward and

I didn’t even need any hashmaps. My card struct had an id field but it never got used. Two sets of course, and intersection is built in. For part 2 I just had two lists, card count and card value. Apparently some people were working out each copy of each card individually…

2 Likes

Part 2 got me a few index and off-by-1 errors… the first this year. And I was too lazy to do it in a single pass. I just recycled my part 1 solution and did a 2nd pass. I liked this one though. I like… taking shortcuts.

1 Like
Day 4 part 2

I think past years of AoC have started paying off. I think prior to working past years’ challenges, I would have likely started with a recursive algorithm to process each card. But once again, very few changes needed from my part 1 to accommodate part 2

2 Likes

Oh and my local group has grown to 6-7 (1 couple is working together) besides me and 1-2 aspirational people who have declared they would like to join.

2 Likes

Done day 5 part 1 but I find I’ve entirely lost my enthusiasm for part 2. Eek.

1 Like

I am done with Day 5 Part 1 as well.

I have part 2 planned out in my head.

You need to process the seeds in chunks I believe. Even if you end up with more chunks after running the current result set through a category, it is still a very finite number. I plan on sticking with the data structure the original input suggests: start point and length of chunk. All you need is the ability to split of a chunk at the boundary that matches a map rule if it isn‘t completely contained in that rule. I will be switching to a seed Stash for this

Right now still resting b/c the cold got bad . I will finish it after dinner though and I am quite sure my idea is going to work.

What I really need to do, I think, is write a range class that’ll handle intersects and things while keeping only start and end values. So (range of seeds) becomes (range of seeds that don’t get changed, range of seeds that get processed by line 1, range of seeds that don’t get changed, range of seeds that get processed by line 2), etc.

But even writing in Perl I don’t have the oomph to make it come out right.

2 Likes

yes I already had a class like that from last year. made it easier to process the data

Bleh. I know how to do part 2. I’m just not convinced yet that I want to do it.

2 Likes

I did it: Day 5 Part 2. It was a bit … on the dark and dreary side like the weather here:

Day 5 is early for running out of space on ints and needing “mathy” optimizations

I actually wrote a unit test for this one because I was too lazy to start debugging.

But the main mistake I made was that I needed to split a chunk in 3 parts head/body/tail when it partially matched a rule.

1 Like

I did it. Day 5 part 2 complete. Wasn’t as fun as how I did part 1.

2 Likes

Day 6 was nice and simple. I spent more time parsing the input than writing the solution.
One of my local friends who apparently gets up early managed to get into the rankings :wink:

Part 2 was different from what I expected. I had expected they would change how speed is gained.

1 Like

I used the winnow parser library today because the author asked me to. :innocent:

Today was that lovely thing where I spot an optimisation, write part 1 with that, and part 2 ends up being just a matter of tweaking the parser. Usually that happens once or twice a year.

3 Likes

My parsing today is anything but … elegant… lots of string.split(…) and string.replace(…)
Also I wrote a completely new one for part 2. It was lazier than building one that could do both cleanly.

Also my partner complains that I brute-forced the solution instead of using proper math formulas. Well I did optimize it a little and surprisingly it worked.

2 Likes
$ time ./day06b.py input.txt

<redacted>

real    0m5.018s
user    0m5.017s
sys     0m0.000s

Not great. But not terrible.

1 Like

day 6 done

My second thought on day 6 was “this smells like a quadratic”. So that was how I implemented it, rather than poking the equation and homing in on zero crossings by some other means, even though it meant I had to use [shudder] floating point. I get the impression quite a few people brute-forced it.

day 5 done

Phew! I could see how to do it yesterday, but I ran out of enthusiasm and stopped. Use the built-in Range class, you idiot Roger. It doesn’t have a whole lot of useful functions, just contains and is_empty, but there are some extension traits which let me lay out the overlap behaviours very cleanly. (More on Codeberg.)

Then it’s just a matter of turning a chain of ranges into a longer chain of ranges if they overlap with one of the map lines, and remapping each range as a whole (by changing its start and end values) rather than each indivitual number.

2 Likes
.../06$ time target/release/b input
[some numbers]

real	0m0.001s
user	0m0.001s
sys 	0m0.000s
2 Likes