summaryrefslogtreecommitdiff
path: root/2018/aoc2018-d05-1.py
diff options
context:
space:
mode:
Diffstat (limited to '2018/aoc2018-d05-1.py')
-rw-r--r--2018/aoc2018-d05-1.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/2018/aoc2018-d05-1.py b/2018/aoc2018-d05-1.py
new file mode 100644
index 0000000..b1d8ebc
--- /dev/null
+++ b/2018/aoc2018-d05-1.py
@@ -0,0 +1,60 @@
+
+f = open("input");
+#f = open("testinput");
+
+'''
+test1 = ord("a") - ord("A");
+test2 = ord("b") - ord("B");
+test3 = ord("c") - ord("C");
+
+print(test1, " ",test2, " ",test3, " ")
+
+'''
+
+cdiff = 32;
+
+def polymer_d(a,b):
+ return (cdiff == abs(ord(a) - ord(b)));
+
+
+myinput = f.read();
+print(myinput);
+print(len(myinput));
+
+is_poly = True;
+'''
+while is_poly:
+ is_poly = False;
+ for x in range(1,len(myinput)):
+ x1 = myinput[x-1];
+ x2 = myinput[x];
+ if polymer_d(x1,x2):
+ #print((x1+x2));
+ #myinput = myinput.replace((x1+x2),"");
+ myinput = myinput[
+ is_poly = True;
+ break;
+ #is_poly = False;
+'''
+
+while is_poly:
+ is_poly = False;
+ sub = "";
+ for x in range(2,len(myinput)):
+
+ x1 = myinput[x-2];
+ x2 = myinput[x-1];
+ if polymer_d(x1,x2):
+ myinput = sub + myinput[x:];
+ is_poly = True;
+ break;
+ else:
+ sub += x1;
+#print(myinput);
+print(len(myinput));
+print(myinput);
+myinput.rstrip("\n");
+
+print("part 1", len(myinput) -1);
+#9687 too high
+#minus 1 helped lol, not sure why