Browse Source

Don't operate on xPos while indexing line

master
Robby Zambito 2 months ago
parent
commit
13733743f7
1 changed files with 2 additions and 3 deletions
  1. +2
    -3
      day3/1/c/main.c

+ 2
- 3
day3/1/c/main.c View File

@ -9,9 +9,8 @@ int main() {
int treeCount = 0;
for (int yPos = 0, xPos = 0;
(lineWidth = getline(&line, &bufSize, stdin)) > 0;
xPos = ++yPos * 3) {
/* - 1 from linewidth to account for newline */
if (line[xPos % (lineWidth - 1)] == '#')
xPos = (++yPos * 3) % (lineWidth - 1)) {
if (line[xPos] == '#')
treeCount++;
free(line);

Loading…
Cancel
Save