Skip to content

Commit ed0b675

Browse files
committed
Add day2b
1 parent 60bb5e5 commit ed0b675

File tree

7 files changed

+58
-86
lines changed

7 files changed

+58
-86
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ test_emulator: test/emulator.c emulator parser
4141
day02a: src/day02a.c emulator parser
4242
$(CC) $(CFLAGS) $< -o $@.o emulator.o parser.o
4343

44-
day02b: src/day02b.c
45-
$(CC) $(CFLAGS) $< -o $@.o
44+
day02b: src/day02b.c emulator parser
45+
$(CC) $(CFLAGS) $< -o $@.o emulator.o parser.o
4646

4747
day03a: src/day03a.c
4848
$(CC) $(CFLAGS) $< -o $@.o

src/day02a.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Licensed under the MIT license.
22

3-
// 1202 Program Alarm
3+
// 1202 Program Alarm Part 1
44

55
#include <stdio.h>
66
#include <time.h>

src/day02b.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Licensed under the MIT license.
2+
3+
// 1202 Program Alarm Part 2
4+
5+
#include <stdio.h>
6+
#include <string.h>
7+
#include <time.h>
8+
#include "../lib/emulator.h"
9+
#include "../lib/parser.h"
10+
#define MEMORY 256
11+
12+
static Word scan(Word clean[], int length)
13+
{
14+
for (Word noun = 0; noun < 100; noun++)
15+
{
16+
for (Word verb = 0; verb < 100; verb++)
17+
{
18+
Word dirty[MEMORY];
19+
20+
memcpy(dirty, clean, sizeof(Word) * length);
21+
22+
dirty[1] = noun;
23+
dirty[2] = verb;
24+
25+
emulator_execute(dirty);
26+
27+
if (dirty[0] == 19690720)
28+
{
29+
return noun * 100 + verb;
30+
}
31+
}
32+
}
33+
34+
return 0;
35+
}
36+
37+
int main(void)
38+
{
39+
Word memory[MEMORY];
40+
clock_t start = clock();
41+
Word product = scan(memory, parser_parse(stdin, memory));
42+
43+
printf(
44+
"02b " WORD_FORMAT " %lf\n",
45+
product,
46+
(double)(clock() - start) / CLOCKS_PER_SEC);
47+
48+
return 0;
49+
}

test/emulator.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#define EXCEPTION_IO "Error: I/O.\n"
88
#define MEMORY 10000
99

10-
int main(int count, String args[])
10+
int main(int count, ZString args[])
1111
{
1212
if (count < 3)
1313
{

tools/example.sh

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,5 @@
1-
cat ../data/011.txt | ./../day01a.o
2-
cat ../data/012.txt | ./../day01b.o
3-
4-
for i in {02..07};
5-
do
6-
cat ../data/${i}1.txt | ./../day${i}a.o
7-
cat ../data/${i}1.txt | ./../day${i}b.o
8-
done
9-
10-
cat ../data/081.txt | ./../day08a.o
11-
cat ../data/082.txt | ./../day08a.o
12-
cat ../data/083.txt | ./../day08b.o
13-
14-
for i in {09..09};
15-
do
16-
cat ../data/${i}1.txt | ./../day${i}a.o
17-
cat ../data/${i}1.txt | ./../day${i}b.o
18-
done
19-
20-
cat ../data/101.txt | ./../day10a.o
21-
cat ../data/102.txt | ./../day10a.o
22-
cat ../data/111.txt | ./../day11a.o
23-
24-
for i in {12..16};
25-
do
26-
cat ../data/${i}1.txt | ./../day${i}a.o
27-
cat ../data/${i}1.txt | ./../day${i}b.o
28-
done
29-
30-
cat ../data/171.txt | ./../day17a.o
31-
cat ../data/171.txt | ./../day17b.o
32-
cat ../data/172.txt | ./../day17b.o
33-
34-
for i in {18..19};
35-
do
36-
cat ../data/${i}1.txt | ./../day${i}a.o
37-
cat ../data/${i}1.txt | ./../day${i}b.o
38-
done
39-
40-
cat ../data/201.txt | ./../day20a.o
41-
cat ../data/202.txt | ./../day20a.o
42-
43-
for i in {22..22};
44-
do
45-
cat ../data/${i}1.txt | ./../day${i}a.o
46-
cat ../data/${i}1.txt | ./../day${i}b.o
47-
done
48-
49-
cat ../data/241.txt | ./../day24b.o
50-
cat ../data/251.txt | ./../day25z.o
1+
./../test_emulator.o ../data/021.csv ../data/021.txt
2+
./../test_emulator.o ../data/022.csv ../data/022.txt
3+
./../test_emulator.o ../data/023.csv ../data/023.txt
4+
./../test_emulator.o ../data/024.csv ../data/024.txt
5+
./../test_emulator.o ../data/025.csv ../data/025.txt

tools/test.bat

Lines changed: 0 additions & 27 deletions
This file was deleted.

tools/test.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)