Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

day04 input parsing will panic for some violations #1

Open
Bodobolero opened this issue Jul 16, 2022 · 0 comments
Open

day04 input parsing will panic for some violations #1

Bodobolero opened this issue Jul 16, 2022 · 0 comments

Comments

@Bodobolero
Copy link

Bodobolero commented Jul 16, 2022

Hi Tim, I admire your elegant, idiomatic solutions, however sometimes you got lucky.

For example in day04 parsing at

"byr" => value.parse::<usize>().unwrap().wrapping_sub(1920) <= 82,

you would panic due to calling unwrap() in case the token following byr: is not a sequence of 4 digits (which the task description asked us to check):

https://adventofcode.com/2020/day/4

You can continue to ignore the cid field, but each other field has strict rules about what values are valid for automatic validation:

byr (Birth Year) - four digits; at least 1920 and at most 2002.

Example input:

hgt:157cm byr:hugo ecl:grn iyr:2012
eyr:2030 hcl:#18171d pid:173cm

(Just stumbled upon your solution when trying to improve my Rust coding style to become more idiomatic and looking at other people's solutions)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant