Compare commits

..

1 commit

Author SHA1 Message Date
c2cf27e601 day7 2020-12-13 02:12:28 +01:00

View file

@ -76,8 +76,8 @@ impl<'a> BagRules<'a> {
fn parse_bag_rule_line(line: &'a str) -> (Bag<'a>, Vec<Bag<'a>>) {
let mut splitted = line.splitn(2, " bags contain ");
let key = splitted.next().expect("invalid bag rule line: missing key");
let values = splitted.next().expect("invalid bag rule line: missing value");
let key = splitted.next().unwrap();
let values = splitted.next().unwrap();
if values == "no other bags." {
return (key, vec![]);
@ -85,7 +85,7 @@ impl<'a> BagRules<'a> {
let values: Vec<&str> = values
.strip_suffix(".")
.expect("invalid bag rule line: not terminated with `.`")
.unwrap()
.split(',')
.flat_map(BagRules::parse_bag_content)
.collect();
@ -99,7 +99,7 @@ impl<'a> BagRules<'a> {
let bag = bag
.strip_suffix(" bags")
.or(bag.strip_suffix(" bag"))
.expect("invalid bag content: no bag(s) suffix");
.unwrap();
let count = count.trim().parse::<usize>().unwrap();
vec![bag.trim(); count]
}