diff options
Diffstat (limited to '22.c')
-rw-r--r-- | 22.c | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -114,7 +114,7 @@ map_elem(struct map const * map, int x, int y) || y < 0 || y >= map->rows) return ' '; - return map->_buf[x + y * map->cols]; + return map->_buf[x + (map->rows - 1 - y) * map->cols]; } @@ -170,8 +170,8 @@ elf_move(struct elf * elf, struct map const * map, int distance) struct elf newelf; switch (elf->dir) { - case D_NORTH: dy = -1; break; - case D_SOUTH: dy = +1; break; + case D_NORTH: dy = +1; break; + case D_SOUTH: dy = -1; break; case D_EAST: dx = +1; break; case D_WEST: dx = -1; break; default: @@ -304,7 +304,7 @@ main(int argc, char ** argv) // Set initial position elf.x = 0; - elf.y = 0; + elf.y = map.rows - 1; elf.dir = D_EAST; while (elf.x < map.cols && map_elem(&map, elf.x, elf.y) != '.') ++elf.x; @@ -344,8 +344,8 @@ main(int argc, char ** argv) // Done. printf("Password is %d (%d,%d,%d)\n", - 1000 * (1 + elf.y) + 4 * (1 + elf.x) + elf.dir, - 1 + elf.x, 1 + elf.y, elf.dir); + 1000 * (map.rows - elf.y) + 4 * (1 + elf.x) + elf.dir, + 1 + elf.x, map.rows - elf.y, elf.dir); // Tidy and exit. map_tidy(&map); |