Function advent_solutions::advent2017::day09::part1
[−]
[src]
pub fn part1(root: &Node) -> usize
Your goal is to find the total score for all groups in your input. Each
group is assigned a score which is one more than the score of the
group that immediately contains it. (The outermost group gets a score of
1.)
{}, score of1.let root = Node::from_bytes(b"{}") .to_result() .unwrap(); assert_eq!(part1(&root), 1);
{{{}}}, score of1 + 2 + 3 = 6.let root = Node::from_bytes(b"{{{}}}") .to_result() .unwrap(); assert_eq!(part1(&root), 6);
{{},{}}, score of1 + 2 + 2 = 5.let root = Node::from_bytes(b"{{},{}}") .to_result() .unwrap(); assert_eq!(part1(&root), 5);
{{{},{},{{}}}}, score of1 + 2 + 3 + 3 + 3 + 4 = 16.let root = Node::from_bytes(b"{{{},{},{{}}}}") .to_result() .unwrap(); assert_eq!(part1(&root), 16);
{<a>,<a>,<a>,<a>}, score of1.let root = Node::from_bytes(b"{<a>,<a>,<a>,<a>}") .to_result() .unwrap(); assert_eq!(part1(&root), 1);
{{<ab>},{<ab>},{<ab>},{<ab>}}, score of1 + 2 + 2 + 2 + 2 = 9.let root = Node::from_bytes(b"{{<ab>},{<ab>},{<ab>},{<ab>}}") .to_result() .unwrap(); assert_eq!(part1(&root), 9);
{{<!!>},{<!!>},{<!!>},{<!!>}}, score of1 + 2 + 2 + 2 + 2 = 9.let root = Node::from_bytes(b"{{<!!>},{<!!>},{<!!>},{<!!>}}") .to_result() .unwrap(); assert_eq!(part1(&root), 9);
{{<a!>},{<a!>},{<a!>},{<ab>}}, score of1 + 2 = 3.let root = Node::from_bytes(b"{{<a!>},{<a!>},{<a!>},{<ab>}}") .to_result() .unwrap(); assert_eq!(part1(&root), 3);
What is the total score for all groups in your input?