fub: A photo of an ADM3A terminal (ADM3A)
[personal profile] fub

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

Date: 2022-12-06 01:52 pm (UTC)
andrewducker: (Default)
From: [personal profile] andrewducker
Very cool! I haven't used Prolog since I was at university, where it was definitely fun to get to grips with, and made me think differently about what was possible.

Profile

fub: (Default)
fub

December 2025

S M T W T F S
 123456
7891011 12 13
14151617181920
212223 24252627
28293031   

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Dec. 26th, 2025 06:04 pm
Powered by Dreamwidth Studios