Aaron's Page

This is where I post about what I'm working on.

--- Day 6: Lanternfish ---

or..

It would be amazing if all these fish could eat plastic, because I think that's the only thing that outnumbers them in the ocean after part 2...

one art please

Part 1 and 2

Python

I learned my lesson from yesterday and immediately starting using a dict handling my state changes which paid off. Since the part two problem was just an expansion on the number of iterations to make using a list to maintain state impractical (probably impossible).

This is a great place to remember deep vs shallow copy of dicts in python:

Here is a deep copy example that keeps reference to the original dict

>>> t
{'0': 0, '1': 0, '2': 0, '3': 0, '4': 0, '5': 0, '6': 0, '7': 0, '8': 0}
>>> d = t
>>> d['1'] = 3
>>> t
{'0': 0, '1': 3, '2': 0, '3': 0, '4': 0, '5': 0, '6': 0, '7': 0, '8': 0}
>>>

...and here's the shallow copy that creates a new copy, that is separate

>>> t = {'0': 0, '1': 0, '2': 0, '3': 0, '4': 0, '5': 0, '6': 0, '7': 0, '8': 0}
>>> d = t.copy()
>>> d['1'] = 3
>>> t
{'0': 0, '1': 0, '2': 0, '3': 0, '4': 0, '5': 0, '6': 0, '7': 0, '8': 0}
>>> d
{'0': 0, '1': 3, '2': 0, '3': 0, '4': 0, '5': 0, '6': 0, '7': 0, '8': 0}
>>>

Watch out for Lanternfish!

Go

This was a fairly straight forward rip and replace from my Python solution. I even found a bit of code that was redundant from that that I didn't need to include in my go program. This was a good chance for me to get a better understanding of working with

<< - Table of Contents - >>