summaryrefslogtreecommitdiff
path: root/19.c
diff options
context:
space:
mode:
authorAdam Spragg <adam@spra.gg>2022-12-29 23:56:56 +0000
committerAdam Spragg <adam@spra.gg>2022-12-29 23:56:56 +0000
commitdd9fe7e11dd42bd01898078732cb2fae30778a05 (patch)
tree8bc140c679721b85a62862d77b71c0c6807e539a /19.c
parent880758c7d5d805440e2239080840486503013bf8 (diff)
Puzzle 19: Move blueprint id into the blueprint
Diffstat (limited to '19.c')
-rw-r--r--19.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/19.c b/19.c
index 3fe6b4a..265d163 100644
--- a/19.c
+++ b/19.c
@@ -16,6 +16,7 @@ enum MATERIAL {
struct blueprint {
+ int id;
int ore_ore;
int clay_ore;
int bsdn_ore;
@@ -26,9 +27,10 @@ struct blueprint {
void
-blueprint_ctor(struct blueprint * b, int ore_ore, int clay_ore,
+blueprint_ctor(struct blueprint * b, int id, int ore_ore, int clay_ore,
int bsdn_ore, int bsdn_clay, int geod_ore, int geod_bsdn)
{
+ b->id = id;
b->ore_ore = ore_ore;
b->clay_ore = clay_ore;
b->bsdn_ore = bsdn_ore;
@@ -182,7 +184,7 @@ main()
while (fgets(buf, sizeof(buf), stdin)) {
regmatch_t rematch[8];
- int bid, t;
+ int t;
struct blueprint b;
struct inventory i;
@@ -191,8 +193,9 @@ main()
continue;
}
- bid = atoi(buf + rematch[1].rm_so);
- blueprint_ctor(&b, atoi(buf + rematch[2].rm_so),
+ blueprint_ctor(&b,
+ atoi(buf + rematch[1].rm_so),
+ atoi(buf + rematch[2].rm_so),
atoi(buf + rematch[3].rm_so),
atoi(buf + rematch[4].rm_so),
atoi(buf + rematch[5].rm_so),
@@ -206,14 +209,14 @@ main()
inventory_tick(&i);
fprintf(stderr, "Blueprint %d tick %d, ore: %ld/%ld, clay %ld/%ld, bsdn %ld/%ld, geod %ld/%ld\n",
- bid, t + 1,
+ b.id, t + 1,
i.ore.amount, i.ore.robots,
i.clay.amount, i.clay.robots,
i.bsdn.amount, i.bsdn.robots,
i.bsdn.amount, i.bsdn.robots);
}
- printf("Blueprint %d geodes = %ld\n", bid, i.geod.amount);
+ printf("Blueprint %d geodes = %ld\n", b.id, i.geod.amount);
}
regfree(&reblueprint);