Function advent_solutions::advent2017::day22::part1_with_bursts
[−]
[src]
pub fn part1_with_bursts(input: &str, bursts: usize) -> usize
For example, suppose you are given a map like this:
..#
#..
...
Then, the middle of the infinite grid looks like this, with the virus
carrier's position marked with [ ]:
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . # . . .
. . . #[.]. . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
The virus carrier is on a clean node, so it turns left, infects the node, and moves left:
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . # . . .
. . .[#]# . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
The virus carrier is on an infected node, so it turns right, cleans the node, and moves up:
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . .[.]. # . . .
. . . . # . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
Four times in a row, the virus carrier finds a clean, infects it, turns left, and moves forward, ending in the same place and still facing up:
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . #[#]. # . . .
. . # # # . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
Now on the same node as before, it sees an infection, which causes it to turn right, clean the node, and move forward:
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . # .[.]# . . .
. . # # # . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
After the above actions, a total of 7 bursts of activity had taken
place. Of them, 5 bursts of activity caused an infection.
After a total of 70, the grid looks like this, with the virus carrier
facing up:
. . . . . # # . .
. . . . # . . # .
. . . # . . . . #
. . # . #[.]. . #
. . # . # . . # .
. . . . . # # . .
. . . . . . . . .
. . . . . . . . .
By this time, 41 bursts of activity caused an infection (though most
of those nodes have since been cleaned).
assert_eq!(part1_with_bursts(input, 70), 41);
After a total of 10000 bursts of activity, 5587 bursts will have
caused an infection.
assert_eq!(part1_with_bursts(input, 10000), 5587);
Given your actual map, after 10000 bursts of activity, how many
bursts cause a node to become infected? (Do not count nodes that begin
infected.)