Advent of Code 2023 Day 1: Trebuchet?!

preview_player
Показать описание
An unfortunate start, but some good lessons from today for the future.

(Disclaimer: I receive commissions on paid memberships through my link, but Codecrafters is not a sponsor of this channel, does not endorse any of my content, and does not review any of my videos.)
Рекомендации по теме
Комментарии
Автор

For part 2, it's actually probably simpler to check if the line starts with one of our match conditions (a word or a digit) and then shift by one character each time. The regex is how I did it, but in hindsight, I think it's more complicated than necessary and I think manually scanning the line would be much smarter.

This is basically just how the regex does it under the hood but it's probably easier to understand and doesn't require you to understand (?=...).

Also, I got the name of that wrong, sorry. It's a lookahead assertion ("this thing is ahead, but don't match it") not a non-capturing group (completely unrelated).

hyper-neutrino
Автор

The edge cases on `oneight`, `eightwo`, etc. were something i missed considering so got stuck for a while on this problem thanks a lot! :D

nonyabizness
Автор

Great solution. Much cleaner than mine. I replaced "one" with "one1one" for each number, and then removed non-digits. This preserves the text for overlaps, but still gets the digits in the right order. I think your solution is cleaner.

For future videos, can you make your font way bigger. It was nearly impossible to read on a phone.

xdf
Автор

D = {'one' : 1, 'two' : 2, 'three':3, 'four':4, 'five':5, 'six':6, 'seven':7, 'eight':8, 'nine':9, '1':1, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9, '0':0}
that's what i initially/intuitively did /// geez 1st day

nox
Автор

Thank you for your videos! I learn a lot from them.

ZyroZoro
Автор

On the "eightwothree" entry, I was of the opinion that the two didn't exist because the "t" was consumed by the eight. It gave me the right answer.

felix.delrubio
Автор

What I did in second part was:

-> generated all overlapping digit words combinations (like twone, oneight) and the corrected ones
-> replaced the ovelapping words with corrected ones
-> replaced all the words with numbers

_bergee_
Автор

I bypassed the attempt at frustrating things with the overlapping words by searching for the first string index and last string index of all pairs '1' and 'one', '2' and 'two' and so on. I keep track of the highest and lowest index and value during the loop.
Not sure if Python has a 'lastIndexOf()' kind of thing

eavdmeer
Автор

Thank you for sharing! it will be great if you could increase the font size for the upcoming videos, is very difficult to see clearly specially with that typeface

nardove
Автор

I was stuck on part 2 for exactly the reason you described for around 10 minutes before someone on chat gave me a hint to try the testcase "eightwo", which my code of course transformed to "8wo". That was pretty annoying indeed that the testcase didn't exercise that behaviour since stepping through the full input to look for possible issues was a bit impractical and it wasn't obvious behaviour.

batlin
Автор

Hi, thanks for the video I didn't know the possitive lookahead pattern.

Anyways, I got the correct solution just normalazing the string for special cases:
private string Normalize(string cad) {
Dictionary<string, string> replaces = new() {
{"oneight", "oneeight"},
{"eightwo", "eighttwo"},
{"eighthree", "eightthree"},
{"threeight", "threeeight"},
{"twone", "twoone"},
{"sevenine", "sevennine"},
{"nineight", "nineeight"},
{"fiveight", "fiveeight"},
{"one", "1"},
{"two", "2"},
{"three", "3"},
{"four", "4"},
{"five", "5"},
{"six", "6"},
{"seven", "7"},
{"eight", "8"},
{"nine", "9"}
};
foreach (var kv in replaces) {
cad = cad.Replace(kv.Key, kv.Value);
}
return cad;
}

RickMMarina
Автор

Maybe they chose to limit the test data in that way to "slow down" anyone using LLMs?

jtfidje
Автор

Please zoom in, thx for your content

xavierjulien
Автор

I'm getting 54429. Wish I knew what I was doing wrong.

murphygreen
Автор

Would you mind linking the code to your GitHub or in the decription if possible. Thx

ashmakes