diff options
| author | Gustav Sörnäs <gusso230@student.liu.se> | 2019-12-16 08:16:17 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gusso230@student.liu.se> | 2019-12-16 08:16:17 +0100 |
| commit | 640bdc3fed46a9e6d3d569dae8fa91da2894697d (patch) | |
| tree | f9bd0ec2e2ed70f4ff0cec7880fe67a030950096 /solutions | |
| parent | 3b87c1a0630b3c5ef07b1e7f34be5e5cc29e4192 (diff) | |
| download | aoc-640bdc3fed46a9e6d3d569dae8fa91da2894697d.tar.gz | |
WIP Day 14 (working pt1)
Diffstat (limited to 'solutions')
| -rw-r--r-- | solutions/input/14 | 58 | ||||
| -rw-r--r-- | solutions/input/14-test1 | 6 | ||||
| -rw-r--r-- | solutions/py/d14.py | 52 |
3 files changed, 116 insertions, 0 deletions
diff --git a/solutions/input/14 b/solutions/input/14 new file mode 100644 index 0000000..c9b5f41 --- /dev/null +++ b/solutions/input/14 @@ -0,0 +1,58 @@ +3 DJDNR => 1 ZCMR +7 VWJH => 5 ZPGT +5 BHZP => 2 DJDNR +6 KCNKC, 19 MZWS => 4 PKVJF +21 GXSHP, 1 TWGP, 3 BGCW => 1 XHRWR +12 DZGWQ, 2 XRDL, 3 XNVT => 2 FTMC +7 VWJH, 33 BGCW, 1 TBVC => 9 DSDP +1 NMTGB, 4 KCNKC, 5 SBSJ, 4 MCZDZ, 7 DLCP, 2 GRBZF, 1 CLKP, 10 VQHJG => 6 DVCR +7 ZCMR => 9 VNTF +2 VNTF, 1 GKMN => 1 TZWBH +6 QMFV, 7 GRBZF => 7 RHDZ +8 PKVJF => 9 NJQH +110 ORE => 9 GZTS +4 DJDNR, 7 SFHV => 8 KQFH +1 ZTCZ, 5 LZFBP => 7 VWPMZ +2 GKMN, 6 TZWBH, 1 GXSHP => 1 MJHJH +2 DLCP, 4 NGJRN => 3 GRBZF +2 DJDNR, 1 GSRBL => 4 VWJH +7 RMQX => 3 SFHV +1 GZTS => 7 GSRBL +3 GZTS, 1 SFHV => 3 QLXCS +10 SFHV => 3 MKTHL +2 DJDNR, 2 BGCW, 4 FSTJ => 3 GKMN +2 KQFH, 7 GSRBL => 7 TWGP +22 RHDZ, 22 DZGWQ, 2 NGJRN, 14 XHRWR, 21 VWPMZ, 15 ZPXHM, 26 BHZP => 8 BPHZ +1 QLXCS => 6 ZBTS +12 DLCP, 9 DSDP => 9 ZPXHM +1 VNTF => 5 ZBTX +2 TZWBH, 2 JCDW => 1 CPLG +1 XHRWR, 7 FSTJ, 5 DZGWQ => 4 NGJRN +179 ORE => 3 RMQX +1 DSDP => 1 MZWS +140 ORE => 8 BHZP +1 LZFBP, 4 DZGWQ => 2 PMDK +1 GZTS => 1 GXSHP +10 CPLG, 8 MCZDZ => 5 ZTCZ +5 ZPGT, 4 THLBN, 24 GSRBL, 40 VNTF, 9 DVCR, 2 SHLP, 11 PMDK, 19 BPHZ, 45 NJQH => 1 FUEL +9 MKTHL => 7 KCNKC +5 NGJRN => 3 QMFV +1 ZTCZ, 6 VNTF => 2 VQHJG +5 FTMC, 5 ZBTX, 1 MJHJH => 1 CLKP +7 FSTJ => 6 DLCP +1 DSDP => 5 KTML +4 LZFBP, 8 MKTHL => 7 MCZDZ +1 SFHV => 1 DZGWQ +2 QLXCS => 4 ZMXRH +3 KQFH, 1 DJDNR => 7 TBVC +5 DSDP => 7 THLBN +9 BHZP, 1 VWJH => 6 BGCW +4 GXSHP => 6 JCDW +1 KQFH, 3 ZMXRH => 9 XNVT +6 TBVC => 4 GVMH +3 VWPMZ, 3 GRBZF, 27 MJHJH, 2 QMFV, 4 NMTGB, 13 KTML => 7 SHLP +1 GVMH => 2 FSTJ +2 VQHJG, 2 NJQH => 8 SBSJ +1 XNVT => 2 XRDL +2 KCNKC => 5 LZFBP +2 ZBTS, 8 DLCP => 4 NMTGB diff --git a/solutions/input/14-test1 b/solutions/input/14-test1 new file mode 100644 index 0000000..65ad5cc --- /dev/null +++ b/solutions/input/14-test1 @@ -0,0 +1,6 @@ +10 ORE => 10 A +1 ORE => 1 B +7 A, 1 B => 1 C +7 A, 1 C => 1 D +7 A, 1 D => 1 E +7 A, 1 E => 1 FUEL diff --git a/solutions/py/d14.py b/solutions/py/d14.py new file mode 100644 index 0000000..dc40da6 --- /dev/null +++ b/solutions/py/d14.py @@ -0,0 +1,52 @@ +import math + +class Chem(object): + def __init__(self, name, created): + self.name = name + self.created = created + + self.amount = 0 + self.wants = 0 + self.left_over = 0 + self.producers = {} + + def add_producer(self, producer, amount): + self.producers[producer] = amount + + def queue(self, amount): + self.wants = amount + for producer, amount in self.producers.items(): + #TODO + pass + + def produce(self, amount): + if self.name == "ORE": + self.amount += amount + return + + productions = math.ceil(amount / self.created) + self.amount += productions * self.created + for producer, amount in self.producers.items(): + producer.produce(productions * amount) + + def __repr__(self): + return str((self.name, self.amount)) + +def pt1(input): + chems = {"ORE": Chem("ORE", 1)} + for line in input: + output = line.strip().split(" => ")[1] + chems[output.split(" ")[1]] = Chem(output.split(" ")[1], int(output.split(" ")[0])) + + for line in input: + inputs = line.strip().split(" => ")[0] + output = line.strip().split(" => ")[1] + for i in inputs.split(", "): + chems[output.split(" ")[1]] \ + .add_producer(chems[i.split(" ")[1]], int(i.split(" ")[0])) + + chems["FUEL"].produce(1) + return chems["ORE"] + +def pt2(input): + return |
