What are you coding?

$ time ./day06b.py input.txt

<redacted>

real    0m0.029s
user    0m0.019s
sys     0m0.010s

Better. At this point I’m probably actually seeing an issue with disk performance on WSL

Re: quadratic formula
It should have been obvious to me since I posted this and I even thought to myself that it looked parabolic

I refactored and learned a bit more about applied math, but I can’t take credit for actually realizing the quadratic formula works (but I am proud that I figured out how to fit the parameters into a formula I haven’t thought about in 20 years!)

1 Like

Day 7. This one was solved by object orienting all the way :slight_smile:
First time I overlooked a minor detail in the problemd description of part 2 leading to a few errors. Part 2 is the interesting part though where a teeny tiny bit of thinking is required. Perfect for a week-day solution.

My local friends were still talking in how few lines they can solve problems.
I don’t think that’s the most valuable metric.
I mean I am trying to write the main solution method as a one-liner that can be read and understood.

It’s still running quite fast. I have yet to run into any performance issues.

2 Likes

My ideal solution is one that teaches me a little more about Rust. Today I learned how to make an enum usable as a sort key.

Day 7

The β€œhard part” seemed to be working out the hand ranking, but as it turns out this was quite easy: throw the cards into a counter (HashMap with auto increment), and then look at the number of distinct cards and if necessary the highest count of any single card. Then just sort the list of hand objects by hand rank, card 0, card 1, etc.
Then when it came to part 2 the changes were pretty minor, and mostly to account for the possibility of an all-jack hand.

Having a few days off as I go away to Airecon NW.

2 Likes

(Day 7)

I used a Map, too, to evaluate hands. It was surprisingly trivial.

And for part 2 I could use a simple switch statement to map everything to the variant with jokers. There is only one case that needs additional information (# of jokers).

I overlooked that Jokers were now the least valuable card in part 2.

2 Likes

Hooray, Day 7 let me enjoy OO again!

I know I’m a dinosaur because I love my OO and it’s not cool or hip like functional.

But I’m not a professional programmer, so I don’t care.

2 Likes

I am, and I don’t care either. :slight_smile:

1 Like

Not an advent of code thing but pretty pleased with the Python code I threw together today.

We generate a bunch of binary data to soak test our software. A while back we made some changes to the script that generates the data but nothing that should have affected the data itself. We got identical data out after we’d made the changes. All good.

Some time and several commits down the road, we noticed the data wasn’t identical. I’ve had a team member trying to track the issue down for a couple of weeks now and he’s not made much headway.

So I took a crack at it today. Before too long I’d identified the 8 differences across the 15GBs of data and tracked down the specific change that caused them to creep in. :blush:

4 Likes

oo is still hip in my book

2 Likes

I figured oo must still be popular. It’s in the middle of every book. :stuck_out_tongue:

2 Likes

Learn lisp, you can write object oriented functional code. CLOS is still what other object oriented languages want to be when they grow up.

2 Likes

I really should learn a lispy language. Which one is best?

[runs away hurriedly]

1 Like

an ANSI common lisp. SBCL is probably the easiest to get going with, and it’s slime support is excellent. (slime is superior lisp interaction mode for emacs, which lets a a superior lisp control an inferior lisp, which gives the ability to introspect a running image and otherwise interact with the running program so you do things to it. that includes normal debugging stuff, like setting breakpoints and so on, but also rebind function definitions etc. The introspection is fantastic, and makes it easy to track down all the callers of a method, or figure out which versions of a method would be called from a particular place, given the current scope.

2 Likes

Okay so Day 8 Part 1 was a nice bit of coding.
And Part 2 was not the expected search algorithm… but I suspect I need a semi-repeat of my code from last years Day 17 with cycle detection…? Because I can’t get those paths to sync up before I lose patience.

1 Like

Currently waiting on Day 8 Part 2 bruteforce method because I know what I need to do to do it analytically… I just don’t want to (at the moment; that might change)

EDIT: it appears I have plenty of time to refactor to the analytical approach… bruteforce is taking… a while…

EDIT 2: I gave up on bruteforce and just did it with LCM increments!. It’s probably supposed to be Chinese Remainder Theorem but despite copying that from previous years, I still couldn’t get it to work out.

1 Like

Okay so I have the solution in theory. For Day 8.2

Turns out of course it’s periodic and the period is trivial: just each starting point to a distinct endpoint and it loops from there. Or so my code suggests. Also the period prime factors are suspicious: they all have 2 factors and share one of them. But when I multiply the factors to get the smallest common multiple… the result is not correct–test result is correct but not my result for the production values.

edit: F… it was another integer overflow. who would have THOUGHT? I am an idiot.

1 Like
Day 9, part 2

I don’t know if I’m clever or this was just a lame part 2. The entire diff between part 1 and part 2

--- day09a.py   2023-12-09 08:37:15.357076837 -0600
+++ day09b.py   2023-12-09 08:39:18.217077391 -0600
@@ -40,7 +40,7 @@
         reading = reading.strip()
         if reading == '':
             continue
-        readings.append(SensorReadings([ int(t) for t in reading.split() ]))
+        readings.append(SensorReadings([ int(t) for t in reading.split() ][::-1]))
     return sum([ reading.next() for reading in readings ])
2 Likes

Day 10. Okay part 1 has me once again mixing up x and y coordinates because even after more than two dozen puzzles solved, I just can’t. But I solved it and most of the work went into calculating the value of the starting spot (after checking with the value my eyes could calculate). It just felt incomplete not calculating it.

And then comes part 2. Yikes. Is this like an extra awful version of flood-fill? With the squeezing between pipes? Meh. I don’t even know where to start.

edit: 1 hour later I know how to do it–I also know this is not a straightforward implementation. This is hard. But here is the gist:

  • at every step in the loop depending on wether I am walking clockwise or anti-clockwise either left or righthand is β€œoutside” and the other side is β€œinside”. Straight pieces have outside and inside. Corners only have one or the other. So I need to track this for every single piece of my loop. Then I can find all the β€œnot part of the loop” pieces in the matrix and can hopefully do some kind of flood filling or similarish. A little scary is that flood filling was a lot later last year so maybe I’ll find something simpler.
Visualisation of my solution for Part 2 for the test input

Some ascii art really helped with this. I am unable to automatically determine clockwise or counterclockwise movement. Meh. But nevermind. It worked. The important part was marking
the starting spot again. Not as clean overall as I would have liked but at least I didn’t have to implement the complete flood fill I did last year for Day 17:

Oβ•”β•—β•”S╔╗╔╗╔╗╔╗╔╗╔═══╗
Oβ”‚β””β”˜β•‘β”‚β•‘β”‚β•‘β”‚β•‘β”‚β•‘β”‚β•‘β”‚β”Œβ”€β”€β•
Oβ•šβ”€β”β””β”˜β””β”˜β•‘β”‚β•‘β”‚β•‘β”‚β””β”˜β””β•β•—O
β•”β•β•β”˜β”Œβ”€β”€β”β•‘β”‚β””β”˜β””β”˜Iβ”Œβ”β”Œβ•O
β•šβ”€β”€β”€β•β•”β•β”˜β””β”˜IIIIβ”Œβ•β•šβ•OO
OOOβ•”β•β”˜β”Œβ”€β”€β”€β”IIIβ””β•—OOOO
OOβ•”β”˜β”Œβ”β””β•—β•”β•β”˜β”Œβ”II└═══╗
OOβ•šβ”€β•β•šβ”β•‘β”‚β”Œβ”β•‘β•šβ”β”Œβ”€β”β”Œβ”β•‘
OOOOOβ•”β”˜β•‘β”‚β•‘β”‚β•‘β•”β”˜β””β•—β”‚β•‘β•šβ•
OOOOOβ•šβ”€β•β•šβ•β•šβ•β•šβ”€β”€β•β•šβ•OO
1 Like

Day 10

I really enjoy the 2D map ones.

Part 2

I took a little too long doing part 1. Like I said, I enjoy the 2d map ones. There were faster ways to do it, but I rather like mine. Bonus is that it helped me with a leg-up on Part 2.

For part 2, I just β€œzoomed in”. I multiplied my grid coordinates by 3 and then filled in the connected sections. So, for example, this:

.......
.β”Œβ”€β”β”Œβ”.
.β”‚.β””β”˜β”‚.
.β””β”€β”€β”€β”˜.
.......

became:

#######################
#.....................#
#.....................#
#.....................#
#.....................#
#....β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ..β–ˆβ–ˆβ–ˆβ–ˆ....#
#....β–ˆ.....β–ˆ..β–ˆ..β–ˆ....#
#....β–ˆ.....β–ˆ..β–ˆ..β–ˆ....#
#....β–ˆ.....β–ˆβ–ˆβ–ˆβ–ˆ..β–ˆ....#
#....β–ˆ...........β–ˆ....#
#....β–ˆ...........β–ˆ....#
#....β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ....#
#.....................#
#.....................#
#.....................#
#.....................#
#######################

Then I just did a normal flood-fill, starting at the top-left (-1, -1) because the original (0,0) tile expanded out to fill the 9 positions: (-1, -1), (-1, 0), (-1, 1), ..., (1, 0), (1, 1); added bonus is that (-1, -1) is guaranteed to be β€œoutside” because the loop cannot extend into negatives. And then I iterated over my original dict() and counted how many original locations had neither a pipe in the loop nor it’s (row*3, col*3) in the flood-fill coordinates.

And, of course, I made visualizations:

β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ
β–ˆβ—¦β”Œβ”β”Œβ”β”Œβ”β”Œβ”β”Œβ”β”Œβ”β”Œβ”β”Œβ”€β”€β”€β”β–ˆ
β–ˆβ—¦β”‚β””β”˜β”‚β”‚β”‚β”‚β”‚β”‚β”‚β”‚β”‚β”‚β”‚β”‚β”Œβ”€β”€β”˜β–ˆ
β–ˆβ—¦β””β”€β”β””β”˜β””β”˜β”‚β”‚β”‚β”‚β”‚β”‚β””β”˜β””β”€β”β—¦β–ˆ
β–ˆβ”Œβ”€β”€β”˜β”Œβ”€β”€β”β”‚β”‚β””β”˜β””β”˜Iβ”Œβ”β”Œβ”˜β—¦β–ˆ
β–ˆβ””β”€β”€β”€β”˜β”Œβ”€β”˜β””β”˜IIIIβ”Œβ”˜β””β”˜β—¦β—¦β–ˆ
β–ˆβ—¦β—¦β—¦β”Œβ”€β”˜β”Œβ”€β”€β”€β”IIIβ””β”β—¦β—¦β—¦β—¦β–ˆ
β–ˆβ—¦β—¦β”Œβ”˜β”Œβ”β””β”β”Œβ”€β”˜β”Œβ”IIβ””β”€β”€β”€β”β–ˆ
β–ˆβ—¦β—¦β””β”€β”˜β””β”β”‚β”‚β”Œβ”β”‚β””β”β”Œβ”€β”β”Œβ”β”‚β–ˆ
β–ˆβ—¦β—¦β—¦β—¦β—¦β”Œβ”˜β”‚β”‚β”‚β”‚β”‚β”Œβ”˜β””β”β”‚β”‚β””β”˜β–ˆ
β–ˆβ—¦β—¦β—¦β—¦β—¦β””β”€β”˜β””β”˜β””β”˜β””β”€β”€β”˜β””β”˜β—¦β—¦β–ˆ
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ
2 Likes

day10.2: oopsie… my floodfill from last year was so complicated that I really didnβ€˜t want to do that.

Do any of you know https://code.golf/ ?
My colleague just showed me this.