Further adventures in Prolog
Dec. 4th, 2022 11:55 amSo I said I was probably not going to do the other days of Advent of Code, but it’s just too much fun, and I’m re-learning some fun Prolog tricks. And some of the assignments are of the type “find (or count) all occurrences where X is true”, and Prolog is ideally suited for that! I solved the assignment for day 2 in basically ten lines of code: nine for a scoring table and one line to do the actual work!
The assignment for day 3 required string manipulation, which is not something Prolog is very good at — it is one of the reasons it’s not a language to Get Stuff Done, because input or output manipulation is a large part of any kind of serious software development. So my solution is kinda kludgy, but the bonus is that it is robust against multiple types of equipment being packed double!
The day 4 assignment is, once again, a “find all X for which Y is true” and that is what Prolog does. So the solution is, once again, very concise: two lines of code to set the requirements, one line of code to find all items that satisfy those requirements.
I’ve switched to using pastebin for the code, because most of you will probably not care and my blog is not suited for posting code anyway. And I have a busy week ahead of me, so it might be that this is as far as I go with it.
Crossposted from my blog. Comment here or at the original post.
no subject
Date: 2022-12-06 01:52 pm (UTC)no subject
Date: 2022-12-12 10:03 am (UTC)I don't think anybody ever uses Prolog to do serious work, though.
And I seem to have fallen off the AoC bandwagon, and perhaps I will clamber back on, and perhaps I won't. We'll see.