Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- readonly static string _puzzle = "06";
- static List<int> _input = File.ReadAllText(Util.CurrentQuery.Location + $"\\{_puzzle}.txt").Split(',').Select(f => int.Parse(f)).ToList();
- static int _targetDays = 256;
- static ulong _lanternfishCount = 0;
- static ulong _initialStateLanternfishCount = 0;
- Dictionary<int, ulong> _initialStateLanternfish = new Dictionary<int, ulong>();
- Dictionary<int, int> _initialStateCount = new Dictionary<int, int>();
- void Main()
- {
- //_input = File.ReadAllText(Util.CurrentQuery.Location + $"\\{_puzzle}_test.txt").Split(',').Select(f => int.Parse(f)).ToList();
- // calculate via divide and modulo how many fish are available after 80 days
- // for a set of fish, how many fish do they each create over _targetDays?
- // how many do that set create with their _targetDays?
- // This is a recursive function
- foreach (var i in _input)
- {
- // Oh, yeah, use a dictionary so we don't have to recalculate for each initial state in the input. /facepalm
- if (_initialStateLanternfish.ContainsKey(i))
- {
- _lanternfishCount += _initialStateLanternfish[i];
- }
- else
- {
- GenerateLanternfish(_targetDays, i);
- _initialStateLanternfishCount++;
- _lanternfishCount += _initialStateLanternfishCount;
- _initialStateLanternfish.Add(i, _initialStateLanternfishCount);
- _initialStateLanternfishCount = 0;
- }
- }
- //_lanternfish.Dump();
- _lanternfishCount.Dump();
- // 1639598111948
- }
- // Define other methods and classes here
- void GenerateLanternfish(int targetDays, int initialState)
- {
- for (var i = targetDays - initialState; i > 0; i -= 7)
- {
- GenerateLanternfish(i, 9);
- _initialStateLanternfishCount++;
- }
- }
Add Comment
Please, Sign In to add comment