repositories
/
advent21.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
cleanup
[advent21.git]
/
03b.c
diff --git
a/03b.c
b/03b.c
index
c940822
..
2213374
100644
(file)
--- a/
03b.c
+++ b/
03b.c
@@
-35,16
+35,14
@@
int main(void)
unsigned numbers[2000] = {0};
int c = 0, y = 0, maxbits = 0, bits = 0;
while ((c = getchar()) != EOF) {
unsigned numbers[2000] = {0};
int c = 0, y = 0, maxbits = 0, bits = 0;
while ((c = getchar()) != EOF) {
- if (c == '0') {
- numbers[y] = numbers[y]*2;
- bits++;
- } else if (c == '1') {
- numbers[y] = numbers[y]*2+1;
- bits++;
- } else if (c == '\n') {
+ if (c == '\n') {
maxbits = bits > maxbits ? bits : maxbits;
bits = 0;
y++;
maxbits = bits > maxbits ? bits : maxbits;
bits = 0;
y++;
+ } else {
+ numbers[y] *= 2;
+ if (c == '1')
+ numbers[y]++;
}
}
}
}