summaryrefslogtreecommitdiff
path: root/2018/aoc2018-d08-1.py
diff options
context:
space:
mode:
authorblenovo <bk@gmail.com>2025-03-04 15:37:55 +0100
committerblenovo <bk@gmail.com>2025-03-04 15:37:55 +0100
commit15662865f0886209d871a7225bfc62cffd2e0783 (patch)
tree7130fb1b11a058ffdbeefe471eccd6ad461d8843 /2018/aoc2018-d08-1.py
parenta926f0a2aa1818879930f5843d5c2cfabd3bfebc (diff)
transfer from previous server
Diffstat (limited to '2018/aoc2018-d08-1.py')
-rwxr-xr-x2018/aoc2018-d08-1.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/2018/aoc2018-d08-1.py b/2018/aoc2018-d08-1.py
new file mode 100755
index 0000000..2d0110d
--- /dev/null
+++ b/2018/aoc2018-d08-1.py
@@ -0,0 +1,31 @@
+currentfilename = "input.txt";
+#currentfilename = "testinput.txt"; #example only
+
+f = open(currentfilename, 'r');
+myinput = eval(f.read().replace(" ",","));
+f.close();
+
+#for i in myinput:
+# print(i);
+
+def NodeAnalysis(License, index):
+ NumberOfChilds = License[index[0]];
+ index[0] += 1;
+ NumberofEntries = License[index[0]];
+ index[0] += 1;
+ #print(index, " - this node has ", NumberOfChilds, " and ", NumberofEntries);
+ for child in range(NumberOfChilds):
+ NodeAnalysis(License, index);
+
+ for entry in range(NumberofEntries):
+ index[1] += License[index[0]];
+ index[0] += 1;
+ #print("\tcurrent index ", index[0]);
+
+
+i = [0,0];
+
+NodeAnalysis(myinput, i);
+print("input length\t", len(myinput));
+print("final index\t", i[0]);
+print("part1 answer\t", i[1]);