Day 01 - Advent of Code 2023

preview_player
Показать описание
Advent of Code day 01 in Rustlang

# Chapters

00:00 Intro
00:11 GitHub PRs - cargo generate
00:51 Trebuchet?! Day 01
02:04 Part 1
07:52 Don't Translate Input!
08:36 Part 2
11:12 rstest
18:36 Debugging Part 2
22:01 Benchmarks with Divan
22:28 dhat heaps
23:28 Deep Dive for Part 1
32:49 Deep Dive for Part 2
36:46 Input Debugging
37:06 Leaderboard Review
37:44 Wrap up
Рекомендации по теме
Комментарии
Автор

I am very new to Rust coming from a little bit of C, Javascript & C# mostly, so i am using advent of code to sharpen up my basics and understanding of syntax etc.. however i probably spent close to 3.5 hours trying to get Part 1 and 2 done in a way that i thought looked right and understood.
But after seeing this video, I realize I still used so many levels of useless abstraction i did not need.
And it has shown me allot of concepts in rust I either didn't know about or didn't understand how they were implemented.
Subbed, great video
👍

QuentinMcCormick-oq
Автор

I took a different approach on part 2. Created an array of tuples like ("one", "o1e"), ("two", "t2o"), ("three", "t3e"), etc... then looped with a replace. Luckily the numbers will only overlap by one letter max, so I just kept first and last letters. Then, just pulled out digits in the same order 😊

kevincodes
Автор

The amount of detail and explanation in this is extremely educational, thanks so much!

TheUkearchy
Автор

Great stuff, this year i'm gonna dive into rust myself. So your setup video helped me out a lot! GL with this years AoC!

MaikDiepenbroek
Автор

This is going to be a great year for AOC :D
Thx! Looking foreward to tomorrow!

endrevestb
Автор

I'm glad I wasn't the only one that got hung up by the overlapping number words!

ExpertOfNil
Автор

The "eightwothree" actually not mattering in the test input was so evil (either way would return 83)🤣

Your solution is much more elegant than mine. In part 2 I abused a regex, and in the process learned the std Rust crate doesn't have "lookahead assertions" to do it cleanly. There's another crate called "fancy_regex" that does, but I instead just matched multiple times and advanced where I was looking 1 index past the start of the last hit. If I had to guess, my approach would only work for ASCII and I'd be in trouble if someone for instance put a poop emoji in the input 💩. I'm not sure if yours is affected, but I'll probably go check it out for fun.

Your more "functional programming" approach is so much cleaner in the end, and I need to train myself to take those sorts of opportunities.

kentbowling
Автор

This is such a great concept for a series. I've been solving the problems mostly in JS or Python and then just translating them to Rust, but this series really helps in learning how to think in Rust.

pwbandwidth
Автор

very interesting, I took a very different approach, which might not be performant, but I am just doing this to learn rust.
Basically I had a couple of helper functions:
&str) -> (usize, char) // returns tuple of index and found digit as char
&str) -> (usize, char)
both of them use the string.find or rfind methods to get the index of first or last occurence, for the string based digits I had another helper funciton which matched from "one" => '1' etc. so both function would have the same output. then in the main() I compared both functions output and chose the lower index version for the first digit and higher index verison for the second input. concatenated with the same forma().parse() and tada it worked

florianbopp
Автор

These are simply amazing! I'm learning Rust and the deep dives are super helpful. :D

ThePixelSlime
Автор

Thanks you for this Tutorial Chris, it really helped me with the part 2 of the challenge.

oghenemarho
Автор

I keep forgetting about filter_map(). At least this time, I did instead of .map(|c| c.to_digit(10)), so clippy did't warn me about it. I feel marginally better about forgetting filter_map when I never actually used map().

I liked the way you did match it.last() to handle the case where the line only had one digit. In part 1, I ended up iterating over each line twice (once to get the first digit, and once for the last digit). In part 2, I was using a for loop instead of an iterator chain, so I used Option<u32> variables to keep track of whether I had seen a first or last digit yet.

markday
Автор

Thank you for making this and explaining your process. As someone that is new to Rust, this is very insightful!

hotmailful
Автор

That's definitely awesome content for us beginners :D, please keep doing it!

diegoparraca
Автор

very nice to see some else's approach. I totally forgot about starts_with. You can "clean up" that if-else tree with a match, like so:
match &word {
w if w.starts_with("one") => Some(1),
w if w.starts_with("two") => Some(2),
w if w.starts_with("three") => Some(3),
...
_ => None,
}

servalp
Автор

Wrote my first rust code from scratch today. Took me 1 hour to get both stars but was worth it. Thanks to your previous video, I learned about Advent of Code, which also led me to discover Advent of Cyber.

siddharthbisht
Автор

This is fun, thanks for making these videos!
A much more efficient solution for "concatenating" two decimal digits would be to just multiply the first one by 10 and then add the second one. Allocating a string, parsing it and then deallocating it is kinda excessive, I'd say ;) On the other hand, your solution is probably more helpful for rust newbs that are watching since they learn how to do the string stuff.

flyingsquirrel
Автор

Checking this out after having completed day 1 (in Go, sorry but I have Rust burnout). I totally also tried cheesing part 2 with replace all ones etc. and then left-to-right search and replace. Liked the trickiness of this, but they should have had a test case that ended in like eightwo or something.

necuz
Автор

for part 1 I used rusts' char.is_ascii_digit() and then for part 2, used an index to iterate, still using char.is_ascii_digit() for the normal digits and looked ahead for the spelled versions

jamstoast
Автор

I got stuck on part 2, had the example been "threeightwo" then I'd understand that I needed to account for overlap.

Ankstek