2022 Day 10 part 2
This commit is contained in:
parent
35fe136562
commit
38e4d396e1
1 changed files with 12 additions and 0 deletions
12
2022/day10.m
12
2022/day10.m
|
@ -15,6 +15,7 @@
|
||||||
int x;
|
int x;
|
||||||
int counter;
|
int counter;
|
||||||
int *nextSample;
|
int *nextSample;
|
||||||
|
int pixel;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int samplePositions[] = {20, 60, 100, 140, 180, 220, -1};
|
static int samplePositions[] = {20, 60, 100, 140, 180, 220, -1};
|
||||||
|
@ -26,6 +27,7 @@ static int samplePositions[] = {20, 60, 100, 140, 180, 220, -1};
|
||||||
counter = 0;
|
counter = 0;
|
||||||
nextSample = samplePositions;
|
nextSample = samplePositions;
|
||||||
_signalSum = 0;
|
_signalSum = 0;
|
||||||
|
pixel = 0;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +38,15 @@ static int samplePositions[] = {20, 60, 100, 140, 180, 220, -1};
|
||||||
_signalSum += counter * x;
|
_signalSum += counter * x;
|
||||||
++nextSample;
|
++nextSample;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("%c", (x - 1 <= pixel && pixel <= x + 1) ? '#' : ' ');
|
||||||
|
pixel++;
|
||||||
|
if (pixel == 40) {
|
||||||
|
printf("\n");
|
||||||
|
pixel = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)noop;
|
- (void)noop;
|
||||||
|
@ -67,6 +78,7 @@ int main() {
|
||||||
[state addX: argument];
|
[state addX: argument];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
NSLog(@"Part 1: %d", state.signalSum);
|
NSLog(@"Part 1: %d", state.signalSum);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue