-
Notifications
You must be signed in to change notification settings - Fork 0
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
WIP: Feature/day 7 #16
base: master
Are you sure you want to change the base?
Conversation
} | ||
} | ||
|
||
println!("{:#?}", contained_in_rules); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove debug print. (Can be added in #11)
|
||
let containers = get_containers("shiny gold", &contained_in_rules); | ||
|
||
// println!("{:#?}", containers); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
|
||
// println!("{:#?}", containers); | ||
|
||
containers.len() as i32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider inlining containers
.
total | ||
} | ||
|
||
fn parse_rules(input: Vec<&str>) -> HashMap<&str, HashMap<&str, i32>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move passe_rules
above the other two helper functions.
get_content_count("shiny gold", &rules) | ||
} | ||
|
||
fn get_containers<'a>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a function get_containers_count
to wrap the len()
call on the HashSet
.
} | ||
|
||
fn get_content_count(color: &str, rules: &HashMap<&str, HashMap<&str, i32>>) -> i32 { | ||
let rule = rules.get(color).expect("Color not listed in rules."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default to 0
without panicking!
let bag_rules_regex = Regex::new(r"bags contain (.*).").unwrap(); | ||
let bag_rule_regex = Regex::new(r"(\d+) (\w+ \w+) \w+").unwrap(); | ||
|
||
// Parse rules. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove comment or reword to be more helpful.
Signed-off-by: Jim Gerth <[email protected]>
Signed-off-by: Jim Gerth <[email protected]>
Bags contain different types of other bags. Especially when wanting to determine how many different types of bags a bag can contian, a set is more suitable for the problem, as duplicates are meaningless and even harmful in this situation. Signed-off-by: Jim Gerth <[email protected]>
Signed-off-by: Jim Gerth <[email protected]>
Signed-off-by: Jim Gerth <[email protected]>
Signed-off-by: Jim Gerth <[email protected]>
Both part 1 and part 2 used this code, thus refactored into its own function. Signed-off-by: Jim Gerth <[email protected]>
bb7e0e8
to
b32a833
Compare
No description provided.