Skip to content

day04 input parsing will panic for some violations #1

@Bodobolero

Description

@Bodobolero

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions