$ 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
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.
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.
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.
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 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.