diff options
author | b-idea <test@test.com> | 2023-10-25 21:06:14 +0200 |
---|---|---|
committer | b-idea <test@test.com> | 2023-10-25 21:06:14 +0200 |
commit | 3d2b624cba351e8d10d407e9322e87d31a20f3be (patch) | |
tree | 5ac11e23cb13b4dbc6ef6de1980d3ae5d9e110f2 | |
parent | d7fef5244c43526e4f1102f816130f55cf20e8a7 (diff) |
added day 09
-rw-r--r-- | 2018/aoc2018-d01-02.py | 32 | ||||
-rw-r--r-- | 2018/aoc2018-d09.py | 50 |
2 files changed, 82 insertions, 0 deletions
diff --git a/2018/aoc2018-d01-02.py b/2018/aoc2018-d01-02.py new file mode 100644 index 0000000..ee8bab2 --- /dev/null +++ b/2018/aoc2018-d01-02.py @@ -0,0 +1,32 @@ +print(); +f = open("input"); + +part1 = 0; +results = []; +not_found = True; +loopcount = 0; +myinput = []; + +for i in f: + myinput.append(int(i)); + +while not_found: + for i in myinput: + #print(i, "endofline"); + part1 += i; + results.append(part1); + #for x in results: + if (results.count(part1) > 1): + part2 = part1; + print(part2); + not_found = False; + break; + loopcount += 1; + #print("loop", loopcount); + +#results.sort(); +#for i in results: +# print(i); + +print(part1); +print(part2); diff --git a/2018/aoc2018-d09.py b/2018/aoc2018-d09.py new file mode 100644 index 0000000..3a300b9 --- /dev/null +++ b/2018/aoc2018-d09.py @@ -0,0 +1,50 @@ +#advent of code 2018
+#day 09
+#part 1 and part 2
+
+from collections import deque
+import time
+
+#parsing input is hardcoded for 1st and 7th word in text
+f = open("input.txt", 'r');
+inputline = f.readline().split();
+playercount = int(inputline[0]); #input1
+lastmarble = int(inputline[6]); #input2
+
+testinput = False;
+if testinput:
+ playercount = 30; # 09 / 10 / 13 / 17 / 21 / 30
+ lastmarble = 5807; # 25 / 1618 / 7999 / 1104 / 6111 / 5807
+ # 32 / 8317 / 146373 / 2764 / 54718 / 37305
+
+def MarbleGame(playercount, lastmarble):
+ playerlist = [];
+ player = 1;
+ for p in range(playercount+1):
+ playerlist.append(0);
+
+ marblelist = deque([0]);
+
+ for m in range(1, lastmarble+1):
+ if(m%23==0):
+ playerlist[player] += m;
+ marblelist.rotate(7);
+ playerlist[player] += marblelist.pop();
+ marblelist.rotate(-1);
+ else:
+ marblelist.rotate(-1);
+ marblelist.append(m);
+ player +=1;
+ if (player > playercount):
+ player = 1;
+
+ p1 = max(playerlist);
+ return p1;
+
+t1 = time.time();
+part1 = MarbleGame(playercount, lastmarble);
+part2 = MarbleGame(playercount, lastmarble*100);
+t2 = time.time();
+print("part 1 = ", part1);
+print("part 2 = ", part2);
+print("runtime ", round(t2-t1,3), " sec");
|