Advent of Code F# – Day 17

The source code for this post (both Part 1 and Part 2) is avail­able here and you can click here to see my solu­tions for the oth­er Advent of Code chal­lenges.

Descrip­tion for today’s chal­lenge is here.

 

Anoth­er nice and sim­ple chal­lenge whose solu­tion fits nice­ly into 20 lines, so here goes:

day17_01

If you have been fol­low­ing this series of posts on this blog, then you’ll have seen some­thing sim­i­lar to this code in pre­vi­ous chal­lenges already. Cou­ple of sub­tle points to note here:

  • we only yield a com­bi­na­tion if the total vol­ume of the con­tain­ers match­es the total (could have done the fil­ter­ing after the fact, AFAIK there’s no sig­nif­i­cant per­for­mance dif­fer­ence in both approach­es);
  • we’re using a depth-first approach here — yield the com­bi­na­tions with­out the cur­rent con­tain­er first, then only yield com­bi­na­tions with this con­tain­er if it wouldn’t take us over the 150 litre lim­it

 

Part 2

The com­bi­na­tion-find­ing code stays the same, we just need to fil­ter the com­bos after the fact by length:

day17_02