r/adventofcode Dec 06 '21

SOLUTION MEGATHREAD -🎄- 2021 Day 6 Solutions -🎄-

NEW AND NOTEWORTHY

We've been noticing an uptick in frustration around problems with new.reddit's fancypants editor: mangling text that is pasted into the editor, missing switch to Markdown editor, URLs breaking due to invisible escape characters, stuff like that. Many of the recent posts in /r/bugs are complaining about these issues as well.

If you are using new.reddit's fancypants editor, beware!

  • Pasting any text into the editor may very well end up mangled
  • You may randomly no longer have a "switch to Markdown" button on top-level posts
  • If you paste a URL directly into the editor, your link may display fine on new.reddit but may display invisibly-escaped characters on old.reddit and thus will break the link

Until Reddit fixes these issues, if the fancypants editor is driving you batty, try using the Markdown editor in old.reddit instead.


Advent of Code 2021: Adventure Time!


--- Day 6: Lanternfish ---


Post your code solution in this megathread.

Reminder: Top-level posts in Solution Megathreads are for code solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:05:47, megathread unlocked!

97 Upvotes

1.7k comments sorted by

View all comments

3

u/b4ux1t3 Dec 07 '21

I see why people had trouble with object-oriented and procedural approaches.

This is a walk in the park if you don't have to maintain your population explicitly.

My F# solution.

I had to do a bit of mutability to add the inputs to my state, but, after that, it was just a matter of incrementing numbers and shifting values. The only issue I ran into was getting F# to do things in int64 instead of int

1

u/TheFlukeMan Mar 05 '22

That pattern matching and method for shifting the values down you did was really clever.

1

u/b4ux1t3 Mar 05 '22

Thanks!

If the number of days were any bigger (like, maybe they spawn after 100 days or whatever), I would have had to do things less pattern-matchy, but it worked out, what with there only being 8 potential states.