Function advent_solutions::advent2017::day01::part2
[−]
[src]
pub fn part2(input: &str) -> u32
You notice a progress bar that jumps to 50% completion. Apparently, the door isn't yet satisfied, but it did emit a star as encouragement. The instructions change:
Now, instead of considering the next digit, it wants you to consider
the digit halfway around the circular list. That is, if your list
contains 10 items, only include a digit in your sum if the digit
10/2 = 5 steps forward matches it. Fortunately, your list has an even
number of elements.
For example:
1212produces6: the list contains4items, and all four digits match the digit2items ahead.assert_eq!(part2("1212"), 6);
1221produces0, because every comparison is between a1and a2.assert_eq!(part2("1221"), 0);
123425produces4, because both2s match each other, but no other digit has a match.assert_eq!(part2("123425"), 4);
123123produces12.assert_eq!(part2("123123"), 12);
12131415produces4.assert_eq!(part2("12131415"), 4);
What is the solution to your new captcha?