summaryrefslogtreecommitdiff
path: root/12.c
diff options
context:
space:
mode:
authorAdam Spragg <adam@spra.gg>2022-12-12 10:31:49 +0000
committerAdam Spragg <adam@spra.gg>2022-12-12 10:31:49 +0000
commit411c0f61756fad52d1d287d53b64149c71209829 (patch)
treefe33a70e567c113d2503880583e051458b980d68 /12.c
parentcac30055faf199136f9fa14b3ed866c9b78ed022 (diff)
Reverse direction of search
Diffstat (limited to '12.c')
-rw-r--r--12.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/12.c b/12.c
index 42d63d4..417ebdb 100644
--- a/12.c
+++ b/12.c
@@ -75,7 +75,7 @@ tryvisit(unsigned char * range, int cols, int rows, struct pos const * from, int
// Check height
src = range[from->x + from->y * cols];
- if (height(dst) > height(src) + 1)
+ if (height(dst) < height(src) - 1)
return 0;
// OK. We can visit, so mark the new position as visited.
@@ -126,9 +126,9 @@ main()
}
rows = rangelen / cols;
- // Find start, and mark it as visited
- if ((p = memchr(range, 'S', rangelen)) == NULL) {
- fprintf(stderr, "No start position!\n");
+ // Find end, and mark it as visited
+ if ((p = memchr(range, 'E', rangelen)) == NULL) {
+ fprintf(stderr, "No end position!\n");
free(range);
return -1;
}
@@ -141,8 +141,8 @@ main()
struct pos * loc;
for (loc = front; loc != NULL; loc = loc->next) {
- if ((range[loc->x + loc->y * cols] & 0x7F) == 'E')
- // We found the end point!
+ if ((range[loc->x + loc->y * cols] & 0x7F) == 'S')
+ // We found the start point!
break;
if (tryvisit(range, cols, rows, loc, -1, 0))
@@ -167,9 +167,9 @@ main()
}
if (front)
- printf("Found end at %d,%d in %d steps\n", front->x, front->y, steps);
+ printf("Found start at %d,%d in %d steps\n", front->x, front->y, steps);
else
- printf("No end found after %d steps\n", steps);
+ printf("No start found after %d steps\n", steps);
pos_free(front);
free(range);