aoc_omni/c/2019/2/1202_program_alarm.c

37 lines
652 B
C
Raw Normal View History

2024-12-12 10:08:11 -05:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "../../lib/intcode.h"
#define EXPECTED_OUTPUT 19690720
int main() {
ic_load_rom_from_input();
IC *c = ic_new_computer();
ic_poke(c, 1, 12);
ic_poke(c, 2, 2);
ic_run(c);
printf("Part 1: %d\n", ic_peek(c, 0));
int noun, verb;
for (noun = 0; noun < 100; noun++) {
for (verb = 0; verb < 100; verb++) {
ic_reset(c);
ic_poke(c, 1, noun);
ic_poke(c, 2, verb);
ic_run(c);
if (ic_peek(c, 0) == EXPECTED_OUTPUT) goto done;
}
}
done:
printf("Part 2: %d\n", noun * 100 + verb);
aoc_free();
return 0;
}