Advent of Code F# — Day 10

ps. look out for all my oth­er solu­tions for Advent of Code chal­lenges here.


Day 10

See details of the chal­lenge here.

The input for today’s chal­lenge looks like this:

bot 171 gives low to bot 4 and high to bot 84
bot 1 gives low to bot 117 and high to bot 81
bot 82 gives low to bot 209 and high to bot 103
bot 128 gives low to bot 56 and high to bot 91
val­ue 23 goes to bot 8
bot 7 gives low to bot 148 and high to bot 22

To parse this input file, it feels to me that Regex is the best bet; and to answer the chal­lenge we can run the sim­u­la­tion until one of the bots have both val­ue-17 and val­ue-61 chips.

The bulk of the work hap­pens in the def­i­n­i­tion for the events sequence. I decid­ed to use a Dic­tio­nary  to track the cur­rent state of the bots, but I didn’t want to expose that muta­bil­i­ty to the out­side hence why it was declare inside the def­i­n­i­tion for events.

Ulti­mate­ly events is a sequence of tuples telling us which bot gave low and hi val­ues to which tar­gets as we sim­u­late the behav­iour of the bots. It makes answer­ing both parts of the chal­lenge real­ly sim­ple.


Part 2

What do you get if you mul­ti­ply togeth­er the val­ues of one chip in each of
out­puts 0, 1, and 2?

We can con­sume the same events sequence we cre­at­ed ear­li­er, and col­lect any val­ues that are giv­en to out­put 0, 1 and 2 and mul­ti­ply them.



Liked this post? Why not support me on Patreon and help me get rid of the ads!