Fix bug in day 6
This commit is contained in:
parent
624b34d72e
commit
041a4259de
1 changed files with 3 additions and 3 deletions
|
|
@ -13,7 +13,7 @@ fn find_loop(mut pos: (usize, usize), mut dir: usize, map: &[Vec<bool>]) -> bool
|
||||||
.filter(|&x| x < map[0].len()),
|
.filter(|&x| x < map[0].len()),
|
||||||
pos.1
|
pos.1
|
||||||
.checked_add_signed(DIR_MAP[dir].1)
|
.checked_add_signed(DIR_MAP[dir].1)
|
||||||
.filter(|&y| y < map[0].len()),
|
.filter(|&y| y < map.len()),
|
||||||
) {
|
) {
|
||||||
visited.insert((pos, dir));
|
visited.insert((pos, dir));
|
||||||
if map[next_pos.1][next_pos.0] {
|
if map[next_pos.1][next_pos.0] {
|
||||||
|
|
@ -66,7 +66,7 @@ fn main() {
|
||||||
.filter(|&x| x < map[0].len()),
|
.filter(|&x| x < map[0].len()),
|
||||||
pos.1
|
pos.1
|
||||||
.checked_add_signed(DIR_MAP[dir].1)
|
.checked_add_signed(DIR_MAP[dir].1)
|
||||||
.filter(|&y| y < map[0].len()),
|
.filter(|&y| y < map.len()),
|
||||||
) {
|
) {
|
||||||
if map[next_pos.1][next_pos.0] {
|
if map[next_pos.1][next_pos.0] {
|
||||||
dir = (dir + 1) % 4;
|
dir = (dir + 1) % 4;
|
||||||
|
|
@ -81,7 +81,7 @@ fn main() {
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
for y in 0..map.len() {
|
for y in 0..map.len() {
|
||||||
for x in 0..map[0].len() {
|
for x in 0..map[0].len() {
|
||||||
if !map[y][x] {
|
if !map[y][x] && (x, y) != start_pos {
|
||||||
map[y][x] = true;
|
map[y][x] = true;
|
||||||
if find_loop(start_pos, 0, &map) {
|
if find_loop(start_pos, 0, &map) {
|
||||||
count += 1;
|
count += 1;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue