Rust challenge 36/100 - advent of code 2021 day 6 part 1 & 2
Table of content
What is this
The rules of the game are explained in my original post.
36th Challenge
Challenge
Today I’m solving today’s AoC day 6 2021.
Solution
Ok, maybe slightly different approach of learning today. I’m going to look at the functions used by other rust solutions before starting. If I don’t know them I will learn their meaning before I start. Lets take a look at the Reddit Mega Thread for Day 6.
Skimming through the thread I found the following functional calls, seems nothing too special going on today. Maybe I need to add the whole scope into my search.
rotate_left(..)
include_str!(“”)
This adds a string literal into the code source. I prefer to just create one in my code with const INPUT:&str..
bench()
Used to benchmark a method, if you’re interested in the speed of your code which I’m currently not.
let mut state = [0u64; 9];
Initalizing an array with u64
int length 9
.
x.or_insert(0)
See the rust doc.
x.for_each()
Like most languages, rust has a for_each iteration method. See Stackoverflow thread on when to use for_each.
use itertools::{iterate, Itertools};
This is a handy dandy toolbox for powerful iterator operations. I defentely want to invest some time to get to know the scope of the lib.
Ok that didn’t help much. The first part was easy but I implemented it badly keeping track of every fishes individual clock rather than the number of fishes with a given clock. I ended up cheating off of the answer of Github User yorhodes after trying recursive approach, filter approach and what not but always trying to keep track of every fish … oh well better luck next time.
Oh well better luck next time.