Day 24
Blech. Three-dimensional node map (x, y, time). Just not fun. Might do it in Rust later.
Day 24
Blech. Three-dimensional node map (x, y, time). Just not fun. Might do it in Rust later.
Day 25: kept awake by a sore throat so I did this when it dropped. Fairly straightforward.
So that’s three I didn’t finish that I’ll go back to at some point. I had very much expected to have shifted to Rust well before then, and I may yet get those three done in PostScript. Not bad for a 1980s language that nobody takes seriously.
Day 20 sucks as much as Day 19. I supposed it might be me that sucks.
I have begun writing unit tests… and I am more confused than ever.
ps. the unit tests solved part1–more or less. This was even worse than “off-by-one” days…
pps: part 2 is resisting. After writing all those tests I was sure that I could easily apply the part 2 changes aka the decryption key and run the mixing 10 times… but it fails… I think I’ll put part 2 with all of Day 19…
Day 21, part 1: solved the test input on the first run. Parsing the actual input didn’t even throw an error and yet my monkey math is wrong.
I can’t see what I am doing different from everyone else whose solutions I studied
long doMath() {
return switch ( operation ) {
case "+" -> lefty.doMath() + right.doMath();
case "-" -> lefty.doMath() - right.doMath();
case "*" -> lefty.doMath() * right.doMath();
case "/" -> lefty.doMath() / right.doMath();
default -> constant;
};
}
I have looked at the last 4 days. It seems to be all map search shenanigans. I think I need a break for now. I have studied the reddit solution thread for the things I couldn’t solve and I still cannot solve them. I’ll probably try again at some point but right now I feel like I am wasting my time and not having fun.
PS: apparently I cannot let go of a problem … so Long is required here. (also I cannot read the outputs and … I really need to stop now, my brain is tired)
I don’t think I’ve seen anything that would overflow a 64-bit int, but 32 might well be pushing it.
Java allows for picking between 32 and 64 with int and long. At work because numbers for database ids tend to get big long is the default. but with these problems here I have somehow defaulted to int … certain collection operations return int (size)… length of arrays is returned as int and so that happens and it is just another issue I keep stumbling over…
After the overflow bit kept me from immediately solving day 20 on the first try… I had more luck with part 2. I got a little creative and I wish I had more ideas like this one:
human.operation = null; //because I can
try {root.doMath();}
catch ( NullPointerException e ) {
try {
root.doHumanMath( 0L );
}
catch ( HumanDetection hd ) {
return hd.result;
}
}
Actually tracing something with a stack trace? Best puzzle in a while.
I would never ever do this in production code. And yet… it was almost trivial to implement and works like a charm.
Rust offers 128s if you want 'em. My training program for Letter Tycoon needs that. Go on, ask me why it has a hardcoded list of the first 26 prime numbers.
For the anagram finding. Order doesn’t matter, only which cards are used, so A A B C is 2 × 2 × 3 × 5 etc and if f(available letters) mod f(letters in word) == 0 then I can make word with the available letters.
OK so that got very meta very fast.
I do the Weekly Challenges, two small programming problems each week. (Originally the Perl Weekly Challenge, then Perl and Raku, and other languages are welcome as “guests”.)
To keep things interesting I’m doing them in nine languages that each hold some interest for me. They’re not so hard that this is very time-consuming; I usually knock off about two languages per day in idle moments.
Because me, I write them not as things that print output, but as functions that return the right structure, plus a bunch of test cases that implement that problem’s examples.
So I’ve just written a thing that takes test specifications in a language-neutral format like this:
ch-1:
- function: maxgap
arguments:
- 2
- 5
- 8
- 1
result: 2
- function: maxgap
arguments:
- 3
result: 0
and generates a source code file for each language that implements them, ready for me to write the actual code; e.g.
#! /usr/bin/python3
import unittest
class TestMaxgap(unittest.TestCase):
def test_ex1(self):
self.assertEqual(maxgap([2, 5, 8, 1]), 2, 'example 1')
def test_ex2(self):
self.assertEqual(maxgap([3]), 0, 'example 2')
unittest.main()
(Inspired by an AoC problem, the parsing is recursive, so I can have arrays of arrays etc.)
I have sinned against XKCD:
That was the one with the blueprints… the engine builder game. So… I was kind of peeked at some other java devs code and took his idea of having self contained states to make everything a little easier to implement.
From there I went back to implementing Dijkstra/A*… now that by itself without eliminating a bunch of states gets pretty slow. So I decided to compare states that had the same “production” at time X and if one state had more resources than another I would keep the one with the bigger pile of resources. Now with there being 4 resources… how do I compare those? I took the blueprint costs and made some kind of heuristic to evaluate a pile of stuff:
int totalValue( Blueprint blueprint ) {
return ( orePile ) * blueprint.oreCOre //
+ ( clayPile ) * blueprint.clayCOre //
+ ( obsPile ) * ( blueprint.obsCOre + blueprint.obsCClay * blueprint.clayCOre ) //
+ ( geoPile ) * ( blueprint.geoCOre + blueprint.geoCObs * blueprint.obsCClay * blueprint.clayCOre *10 ); //
}
This works for 29 of 30 blueprints. This is the one it doesn’t work for:
Blueprint[blueprintId=7, oreCOre=3, clayCOre=3, obsCOre=3, obsCClay=11, geoCOre=2, geoCObs=8]
Apparently, the strategy here is to produce cheaper resources first… and sometime late in the game there is a state where the high valued resources throw out a state that would lead to 1 more geode in the end
Luckily, my algorithm works without the optimization… it is just slow… like 2 minutes slow. With it it is more like 1.5 seconds. For part 2 my heuristic worked just fine due to the reduced input set and I didn’t have to wonder if the longer run would complete
At some point I want to try and improve the heuristic…
I am currently struggling implementing Part 2 of either Day 20 or Day 22. In both cases it seems I should have gone fully object oriented to avoid those pesky edge cases (literally in case of 22).
I really don’t know why Day 20 doesn’t just “work”. I thought I had it when I reset my “movement” markers after each mixing. But still not correct. There is probably another +/- 1 error hidden here. Something that works with Part 1 because Part 1 the numbers are never more than twice the list length.
Day 22… I am still debugging my way through how I need to flip coordinates (because I have a flat matrix and not some kind of dicey structuire). I think I have better chances here because I just need to math out the correct formulas for the edges, I have a paper model of the die to help me figure out what is what…
By now there are 3 others (one pair, two solos) among my friendgroup who are working on the puzzles. And 1 kid who would really really like if his parents let him participate but they are doing it in C++ and he only knows java from school (and also he is 13 and a bit on the young side for the puzzles beyond the beginning). I may have thought about inviting him over to solve a couple of puzzles from another year at some point
I still haven’t done 22/2, or 24 at all; the specific day helps give me a deadline. But soon…
I have yet to begin 23-25… but I will… last few evenings I was working on my server again and I can only really concentrate on one techie-project at a time. They need the same brain-space…
My server is now almost at a point where no further work is needed. I have just 2 opens now and one of those may not be necessary to do anything about…
So I got Day 22.2.test running… and then my optimistic run with the “production” input failed… half an hour later I realized: this is not the same input pattern. this is a completely different cube. Because I manually input the edges and how they match… I had to do it over and now need to debug on “production” how it is all supposed to go. I am completely unable to see the math of the folding edges and how I could derive what goes where from the code. I haven’t checked anywhere for ideas. I’ll go with my manual input and debug that until it works
The reason I haven’t worked at all on 22.2 is
I’m sure there should be a way to look at the layout and do the folding programmatically, rather than hard-coding “left edge of row 1 column 3 is top edge of row 2 column 2” or whatever But I don’t have the mental toolbox to turn that into code.
Something something 3 dimensions… I am barely fluent in 2 dimensions… I am not able to go beyond that…
Just got my command-line password manager feature-complete (for now).
Tell it pw [sitename]
and it’ll decrypt a gpg-encrypted recfile, recsel
it to get the relevant site record, and print that out - though if it finds a field called TOTP it’ll use oathtool
to generate codes and display those instead. Also options for “view the whole file” and “edit the file, re-encrypting afterwards”.
Sadly, recsel
does need an actual file in a filesystem, but I’m sticking the decrypted file on an ephemeral tmpfs in RAM.
No guarantees of course, but I think this does a decent job.
Wrote a calmanager
plugin to snabble dates of future events from Meetup groups, and insert them into the house calendar. Meetup used to provide iCalendar files, but apparently they don’t any more.
I’ve been coding a flask / python web app for a database for my mail aliases (the two of us currently have something around 450 of those). The previous iteration was written in php and was no longer maintainable. I lack any php skills whatsoever and the code was so horrifying that I wouldn’t touch it… the docker container for the php thing broke with every upate because it kept forgetting to install the mysql plugin.
The new mail tool itself is done and I am quite happy with it. Then I spent several days fighting to install mysql drivers in the python docker container… the irony hurts.
Now I have various things that work or not because I can’t smooth out the differences between dev and production environments. Because in dev I use an sqlite database. I love coding. I hate devops.
I’ve recently bound a key sequence in my window manager (Xmonad) to grab the active window ID with xdotool
and then spawn an Emacs frame and run an elisp command, passing it the window ID as an argument.
The Emacs command does something along vaguely similar lines to your program to interact with the user and fetch a password, and it puts the result into the X clipboard and then uses xdotool
again to type ctrl+v into the original window.
I then tell Emacs to hide the frame and sleep for a second before deleting the frame completely, which gives the target application plenty of time to obtain the clipboard contents (which X has to obtain from the window/frame which currently owns the clipboard) before they’re gone. I’m not using any clipboard manager program, so I’m vaguely convinced that the passwords being pasted aren’t being captured and retained anywhere else, and I rather like that (assuming sensible usage) I never see the password at all.
Obviously that only works if ctrl+v is “paste” for the target application, but right now I’m only using this for some web browser forms. I could undoubtedly obtain more window data and choose the appropriate keystroke conditionally.
I hadn’t used xdotool
before, but it seems like it could be very useful.