summaryrefslogtreecommitdiffstats
path: root/solutions/py/d14.py
diff options
context:
space:
mode:
authorGustav Sörnäs <gusso230@student.liu.se>2019-12-16 08:16:17 +0100
committerGustav Sörnäs <gusso230@student.liu.se>2019-12-16 08:16:17 +0100
commit640bdc3fed46a9e6d3d569dae8fa91da2894697d (patch)
treef9bd0ec2e2ed70f4ff0cec7880fe67a030950096 /solutions/py/d14.py
parent3b87c1a0630b3c5ef07b1e7f34be5e5cc29e4192 (diff)
downloadaoc-640bdc3fed46a9e6d3d569dae8fa91da2894697d.tar.gz
WIP Day 14 (working pt1)
Diffstat (limited to 'solutions/py/d14.py')
-rw-r--r--solutions/py/d14.py52
1 files changed, 52 insertions, 0 deletions
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