From d7fef5244c43526e4f1102f816130f55cf20e8a7 Mon Sep 17 00:00:00 2001 From: ihaveslowbrain Date: Fri, 20 Oct 2023 21:32:41 +0000 Subject: renamed few files --- 2018/aoc18-d01-2.py | 32 ------------- 2018/aoc18-d03.py | 77 ------------------------------- 2018/aoc18-d04-1.py | 123 -------------------------------------------------- 2018/aoc18-d05-1.py | 60 ------------------------ 2018/aoc18-d05-2.py | 72 ----------------------------- 2018/aoc2018-d01-2.py | 32 +++++++++++++ 2018/aoc2018-d03.py | 77 +++++++++++++++++++++++++++++++ 2018/aoc2018-d04-1.py | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2018/aoc2018-d05-1.py | 60 ++++++++++++++++++++++++ 2018/aoc2018-d05-2.py | 72 +++++++++++++++++++++++++++++ 10 files changed, 364 insertions(+), 364 deletions(-) delete mode 100644 2018/aoc18-d01-2.py delete mode 100644 2018/aoc18-d03.py delete mode 100644 2018/aoc18-d04-1.py delete mode 100644 2018/aoc18-d05-1.py delete mode 100644 2018/aoc18-d05-2.py create mode 100644 2018/aoc2018-d01-2.py create mode 100644 2018/aoc2018-d03.py create mode 100644 2018/aoc2018-d04-1.py create mode 100644 2018/aoc2018-d05-1.py create mode 100644 2018/aoc2018-d05-2.py diff --git a/2018/aoc18-d01-2.py b/2018/aoc18-d01-2.py deleted file mode 100644 index ee8bab2..0000000 --- a/2018/aoc18-d01-2.py +++ /dev/null @@ -1,32 +0,0 @@ -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/aoc18-d03.py b/2018/aoc18-d03.py deleted file mode 100644 index c304576..0000000 --- a/2018/aoc18-d03.py +++ /dev/null @@ -1,77 +0,0 @@ -import numpy as np - -f = open("input"); - -GRIDSIZE = 1000; - -cloth = np.full((GRIDSIZE,GRIDSIZE),0, dtype=int); - - -part1 = np.count_nonzero(cloth); -print(part1); - -for i in f: - for l in range(len(i)): - if i[l] == "@": - claim_id = int(i[1:(l)]); - l_at = l+1; - if i[l] == ",": - claim_l = int(i[l_at:(l)]); - l_at = l+1; - if i[l] == ":": - claim_t = int(i[l_at:(l)]); - l_at = l+1; - if i[l] == "x": - claim_w = int(i[l_at:(l)]); - #l_at = l+1; - claim_h = int(i[l+1:]); - - for x in range(claim_l, claim_l+claim_w, 1): - for y in range(claim_t, claim_t+claim_h, 1): - cloth[y,x] +=1; - -part1 = np.count_nonzero(cloth); -#print(part1); -part1 = 0; -for i in range(GRIDSIZE): - for j in range(GRIDSIZE): - part1 += 1*(cloth[i,j] > 1); - - -print("part1", part1); - - -f = open("input"); -for i in f: - #print(i); - for l in range(len(i)): - #print(l, i[l]); - if i[l] == "@": - claim_id = int(i[1:(l)]); - l_at = l+1; - if i[l] == ",": - claim_l = int(i[l_at:(l)]); - l_at = l+1; - if i[l] == ":": - claim_t = int(i[l_at:(l)]); - l_at = l+1; - if i[l] == "x": - claim_w = int(i[l_at:(l)]); - #l_at = l+1; - claim_h = int(i[l+1:]); - - #checkclaim = "#" + str(claim_id) +" @ "+str(claim_l)+","+str(claim_t)+": "+str(claim_w)+"x"+str(claim_h); - #print("",i, checkclaim); - #print(); - is_overlap = False; - for x in range(claim_l, claim_l+claim_w, 1): - for y in range(claim_t, claim_t+claim_h, 1): - if (cloth[y,x] > 1): - is_overlap = True; - - if not is_overlap: - part2 = claim_id; - break; - -print("part2", part2); - diff --git a/2018/aoc18-d04-1.py b/2018/aoc18-d04-1.py deleted file mode 100644 index 6f28be5..0000000 --- a/2018/aoc18-d04-1.py +++ /dev/null @@ -1,123 +0,0 @@ -import numpy as np - - -def datecompact(log): - d = log[1:5] + log[6:8] + log[9:11] + log[12:14] + log[15:17]; - return int(d); - -def action(log): - if (log[19] == "f"): - return 1; - elif (log[19] == "w"): - return 2; - else: - #return 3; - return int(log[24:].strip("\n # begins shift")); - return (log[24:].strip("\n # begins shift")); - #return int(log[24:].strip("#beginshft\n")); - -f = open("input"); -#f = open("testinput"); - -myinput = []; -guards = {}; - -for i in f: - #print(datecompact(i)); - myinput.append([datecompact(i),action(i)]); - if (action(i) != 1 and action(i) != 2 ): - try: - guards[action(i)] = 0; - except: - True; - - -for i in range(len(myinput)): - #print(i[0], " -- ", i[1]); - for j in range(len(myinput)): - if (myinput[i][0] < myinput[j][0]): - temp = myinput[i]; - myinput[i] = myinput[j]; - myinput[j] = temp; - - -#print(guards); - -#for i in range(len(myinput) -1): - #if (myinput[i][0] > myinput[i+1][0]): - #print("fuck"); -#for i in myinput: -# print(i[0], " -- ", i[1]); - -x1 = 0; - - -for l in myinput: - if l[1] == 2: - guards[g] += l[0] - x1 ; - elif l[1] == 1: - x1 = l[0]; - else: - g = l[1]; - - -tmax = 0; -bestg = ""; - -for g in guards.keys(): - print(g); - #''' - if (guards[g] >tmax): - tmax = guards[g]; - bestg = g; - #''' - -print("best guard ",bestg," - ", tmax); -#part1 = int(bestg)*tmax; -#print("part1", part1); - -#269357 too high -#256332 too high - - - -is_bestg = False; - -#timestat = np.array(60); -#timestat.fill(0); -timestat = np.full(60,0, dtype=int); - -#bestg = int(bestg); - -for l in myinput: - print("iterating", l[0], " ", l[1], " ", l[0]%100); - - if (is_bestg and (l[1] == 1 or l[1] == 2)): - print("yup"); - if l[1] == 1: - t1 = l[0]; - elif l[1] == 2: - t2 = l[0]; - for t in range(t1%100,t2%100,1): - timestat[t] += 1; - elif l[1] == bestg: - is_bestg = True; - elif l[1] != bestg: - print("not bestg"); - is_bestg = False; - -''' - guards[g] += l[0] - x1 ; - elif l[1] == 1: - x1 = l[0]; - else: - g = l[1]; -''' - -worsttime = (np.argmax(timestat)); - -part1 = int(bestg)*worsttime; - - -print("best guard ",bestg," - ", worsttime); -print("part1", part1); diff --git a/2018/aoc18-d05-1.py b/2018/aoc18-d05-1.py deleted file mode 100644 index b1d8ebc..0000000 --- a/2018/aoc18-d05-1.py +++ /dev/null @@ -1,60 +0,0 @@ - -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 diff --git a/2018/aoc18-d05-2.py b/2018/aoc18-d05-2.py deleted file mode 100644 index be01aa0..0000000 --- a/2018/aoc18-d05-2.py +++ /dev/null @@ -1,72 +0,0 @@ - -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))); -''' -def polymer_strip(inp): - is_poly = True; - while is_poly: - is_poly = False; - sub = ""; - for x in range(2,len(inp)): - - x1 = inp[x-2]; - x2 = inp[x-1]; - if polymer_d(x1,x2): - inp = sub + inp[x:]; - is_poly = True; - break; - else: - sub += x1; - return inp; -''' -def polymer_strip(inp): - is_poly = True; - while is_poly: - is_poly = False; - for x in range(1,len(inp)): - x1 = inp[x-1]; - x2 = inp[x]; - if polymer_d(x1,x2): - #print((x1+x2)); - inp = inp.replace((x1+x2),""); - #myinput = myinput[ - is_poly = True; - break; - return inp; - #is_poly = False; - -myinput = f.read(); - -#print("A", ord("A"), "Z", ord("Z")); - -inp_max = 999999; -inp_c = ""; - -for c in range(ord("A"),ord("Z")+1,1): - #print(chr(c)); - subinput = myinput; - subinput = subinput.replace(chr(c),""); - subinput = subinput.replace(chr(c+cdiff),""); - subinput = polymer_strip(subinput); - if (len(subinput) < inp_max): - inp_max = len(subinput); - inp_c = c; - -print("part 2 ",inp_max -1); - -#again, needed minus 1 on answer -#not sure why is that but it works diff --git a/2018/aoc2018-d01-2.py b/2018/aoc2018-d01-2.py new file mode 100644 index 0000000..ee8bab2 --- /dev/null +++ b/2018/aoc2018-d01-2.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-d03.py b/2018/aoc2018-d03.py new file mode 100644 index 0000000..c304576 --- /dev/null +++ b/2018/aoc2018-d03.py @@ -0,0 +1,77 @@ +import numpy as np + +f = open("input"); + +GRIDSIZE = 1000; + +cloth = np.full((GRIDSIZE,GRIDSIZE),0, dtype=int); + + +part1 = np.count_nonzero(cloth); +print(part1); + +for i in f: + for l in range(len(i)): + if i[l] == "@": + claim_id = int(i[1:(l)]); + l_at = l+1; + if i[l] == ",": + claim_l = int(i[l_at:(l)]); + l_at = l+1; + if i[l] == ":": + claim_t = int(i[l_at:(l)]); + l_at = l+1; + if i[l] == "x": + claim_w = int(i[l_at:(l)]); + #l_at = l+1; + claim_h = int(i[l+1:]); + + for x in range(claim_l, claim_l+claim_w, 1): + for y in range(claim_t, claim_t+claim_h, 1): + cloth[y,x] +=1; + +part1 = np.count_nonzero(cloth); +#print(part1); +part1 = 0; +for i in range(GRIDSIZE): + for j in range(GRIDSIZE): + part1 += 1*(cloth[i,j] > 1); + + +print("part1", part1); + + +f = open("input"); +for i in f: + #print(i); + for l in range(len(i)): + #print(l, i[l]); + if i[l] == "@": + claim_id = int(i[1:(l)]); + l_at = l+1; + if i[l] == ",": + claim_l = int(i[l_at:(l)]); + l_at = l+1; + if i[l] == ":": + claim_t = int(i[l_at:(l)]); + l_at = l+1; + if i[l] == "x": + claim_w = int(i[l_at:(l)]); + #l_at = l+1; + claim_h = int(i[l+1:]); + + #checkclaim = "#" + str(claim_id) +" @ "+str(claim_l)+","+str(claim_t)+": "+str(claim_w)+"x"+str(claim_h); + #print("",i, checkclaim); + #print(); + is_overlap = False; + for x in range(claim_l, claim_l+claim_w, 1): + for y in range(claim_t, claim_t+claim_h, 1): + if (cloth[y,x] > 1): + is_overlap = True; + + if not is_overlap: + part2 = claim_id; + break; + +print("part2", part2); + diff --git a/2018/aoc2018-d04-1.py b/2018/aoc2018-d04-1.py new file mode 100644 index 0000000..6f28be5 --- /dev/null +++ b/2018/aoc2018-d04-1.py @@ -0,0 +1,123 @@ +import numpy as np + + +def datecompact(log): + d = log[1:5] + log[6:8] + log[9:11] + log[12:14] + log[15:17]; + return int(d); + +def action(log): + if (log[19] == "f"): + return 1; + elif (log[19] == "w"): + return 2; + else: + #return 3; + return int(log[24:].strip("\n # begins shift")); + return (log[24:].strip("\n # begins shift")); + #return int(log[24:].strip("#beginshft\n")); + +f = open("input"); +#f = open("testinput"); + +myinput = []; +guards = {}; + +for i in f: + #print(datecompact(i)); + myinput.append([datecompact(i),action(i)]); + if (action(i) != 1 and action(i) != 2 ): + try: + guards[action(i)] = 0; + except: + True; + + +for i in range(len(myinput)): + #print(i[0], " -- ", i[1]); + for j in range(len(myinput)): + if (myinput[i][0] < myinput[j][0]): + temp = myinput[i]; + myinput[i] = myinput[j]; + myinput[j] = temp; + + +#print(guards); + +#for i in range(len(myinput) -1): + #if (myinput[i][0] > myinput[i+1][0]): + #print("fuck"); +#for i in myinput: +# print(i[0], " -- ", i[1]); + +x1 = 0; + + +for l in myinput: + if l[1] == 2: + guards[g] += l[0] - x1 ; + elif l[1] == 1: + x1 = l[0]; + else: + g = l[1]; + + +tmax = 0; +bestg = ""; + +for g in guards.keys(): + print(g); + #''' + if (guards[g] >tmax): + tmax = guards[g]; + bestg = g; + #''' + +print("best guard ",bestg," - ", tmax); +#part1 = int(bestg)*tmax; +#print("part1", part1); + +#269357 too high +#256332 too high + + + +is_bestg = False; + +#timestat = np.array(60); +#timestat.fill(0); +timestat = np.full(60,0, dtype=int); + +#bestg = int(bestg); + +for l in myinput: + print("iterating", l[0], " ", l[1], " ", l[0]%100); + + if (is_bestg and (l[1] == 1 or l[1] == 2)): + print("yup"); + if l[1] == 1: + t1 = l[0]; + elif l[1] == 2: + t2 = l[0]; + for t in range(t1%100,t2%100,1): + timestat[t] += 1; + elif l[1] == bestg: + is_bestg = True; + elif l[1] != bestg: + print("not bestg"); + is_bestg = False; + +''' + guards[g] += l[0] - x1 ; + elif l[1] == 1: + x1 = l[0]; + else: + g = l[1]; +''' + +worsttime = (np.argmax(timestat)); + +part1 = int(bestg)*worsttime; + + +print("best guard ",bestg," - ", worsttime); +print("part1", part1); 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 diff --git a/2018/aoc2018-d05-2.py b/2018/aoc2018-d05-2.py new file mode 100644 index 0000000..be01aa0 --- /dev/null +++ b/2018/aoc2018-d05-2.py @@ -0,0 +1,72 @@ + +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))); +''' +def polymer_strip(inp): + is_poly = True; + while is_poly: + is_poly = False; + sub = ""; + for x in range(2,len(inp)): + + x1 = inp[x-2]; + x2 = inp[x-1]; + if polymer_d(x1,x2): + inp = sub + inp[x:]; + is_poly = True; + break; + else: + sub += x1; + return inp; +''' +def polymer_strip(inp): + is_poly = True; + while is_poly: + is_poly = False; + for x in range(1,len(inp)): + x1 = inp[x-1]; + x2 = inp[x]; + if polymer_d(x1,x2): + #print((x1+x2)); + inp = inp.replace((x1+x2),""); + #myinput = myinput[ + is_poly = True; + break; + return inp; + #is_poly = False; + +myinput = f.read(); + +#print("A", ord("A"), "Z", ord("Z")); + +inp_max = 999999; +inp_c = ""; + +for c in range(ord("A"),ord("Z")+1,1): + #print(chr(c)); + subinput = myinput; + subinput = subinput.replace(chr(c),""); + subinput = subinput.replace(chr(c+cdiff),""); + subinput = polymer_strip(subinput); + if (len(subinput) < inp_max): + inp_max = len(subinput); + inp_c = c; + +print("part 2 ",inp_max -1); + +#again, needed minus 1 on answer +#not sure why is that but it works -- cgit v1.2.3