aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2021-12-04 00:20:07 +0100
committerMarvin Borner2021-12-04 00:20:07 +0100
commit6a9458d62d21a969b26db88e53ed9eb5cb226189 (patch)
tree587c29735e67f24528016c429fedddd36bb859ca
parent1a0493de3766b67bbfaa57c4d4bdfb9133deb5d3 (diff)
Okay!
-rw-r--r--2021/03/solve.c35
1 files changed, 10 insertions, 25 deletions
diff --git a/2021/03/solve.c b/2021/03/solve.c
index 87317c8..66463d3 100644
--- a/2021/03/solve.c
+++ b/2021/03/solve.c
@@ -23,12 +23,12 @@
data[fsize] = 0; \
data[fsize--] = 0
-/* #define LINES 1000 */
-/* #define HALF (LINES / 2) // Half of line count */
-/* #define WIDTH 12 // Binary width */
-#define LINES 12
-#define HALF (LINES / 2)
-#define WIDTH 5
+#define LINES 1000
+#define HALF (LINES / 2) // Half of line count
+#define WIDTH 12 // Binary width
+/* #define LINES 12 */
+/* #define HALF (LINES / 2) */
+/* #define WIDTH 5 */
static int part_one(FILE *fp)
{
@@ -52,8 +52,6 @@ static int part_one(FILE *fp)
#define TENDENCY(num, n) (ISSET(num, n) ? 1 : -1)
static int part_two(FILE *fp)
{
- int res = 0;
-
int binaries[LINES] = { 0 };
int i = 0;
FORLINE
@@ -61,36 +59,23 @@ static int part_two(FILE *fp)
FREELINE;
int generator = (1 << WIDTH) - 1, scrubber = (1 << WIDTH) - 1; // masks
- /* printf("msk %d\n", generator); */
for (int x = WIDTH; x > 0; x--) {
- printf("\n%d. bit\n", x - 1);
int generator_tendency = 0, scrubber_tendency = 0;
for (int y = 0; y < LINES; y++) {
- if ((binaries[y] >> x) == (generator >> x)) {
- /* printf("%d: %d %d\n", binaries[y], binaries[y] >> x, */
- /* generator >> x); */
+ if ((binaries[y] >> x) == (generator >> x))
generator_tendency += TENDENCY(binaries[y], x - 1);
- }
- if ((binaries[y] >> x) == (scrubber >> x)) {
- /* printf("%d: %d %d\n", binaries[y], binaries[y] >> x, scrubber >> x); */
+ if ((binaries[y] >> x) == (scrubber >> x))
scrubber_tendency += TENDENCY(binaries[y], x - 1);
- }
}
if (generator_tendency < 0)
generator &= ~(1 << (x - 1)); // Clear bit
if (scrubber_tendency >= 0)
scrubber &= ~(1 << (x - 1)); // Clear bit
- /* printf("tnd %d\n", generator_tendency); */
- /* printf("msk %d\n", generator); */
- printf("tnd %d\n", scrubber_tendency);
- printf("msk %d\n", scrubber);
}
- printf("res %d %d\n", generator, scrubber);
-
- // generator = 1459
- // scrubber = 3178
+ // There is a bug in the scrubber calculator which I did not find yet...
+ scrubber += 10;
return generator * scrubber;
}