These are your personal leaderboard times. Rank is your position on that leaderboard: 1 means you were the first person to get that star, 2 means the second, 100 means the 100th, etc. Score is the number of points you got for that rank: 100 for 1st, 99 for 2nd, ..., 1 for 100th, and 0 otherwise.
--------Part 1--------- --------Part 2--------- Day Time Rank Score Time Rank Score 6 00:23:27 7702 0 00:29:24 7014 0 5 01:03:23 8200 0 >24h 42291 0 4 00:09:38 2952 0 00:21:03 2406 0 3 02:45:54 14721 0 03:33:28 13593 0 2 >24h 99119 0 >24h 94923 0 1 >24h 179306 0 >24h 134346 0
Part 1
def get_values(input_list):
data = [0]*8
i = 0
x = input_list[i]
# 0
t = x.split(':')[1]
data[0] = list(map(int,t.split()))
i += 3
# 1
for index in range(1,8):
data[index] = []
x = input_list[i]
while len(x) > 1:
data[index].append(list(map(int,x.split())))
i += 1
x = input_list[i]
i += 2
return data
def get_min(data):
ans = 123456789012
for x in data[0]:
t = x
for i in range(1,8):
b = 0
for r in data[i]:
if t >= r[1] and t < r[1] + r[2] :
t = r[0] + t - r[1]
b = 1
break
ans = min(ans,t)
return ans
def solve(input_list):
data = get_values(input_list)
print(get_min(data))
def main():
file_name = 'sample.txt'
file_name = 'input.txt'
r_list = []
with open(file_name,'r') as file:
for x in file:
r_list.append(x[:-1])
solve(r_list)
main()
Part 2
def get_values(input_list):
data = [0]*8
i = 0
x = input_list[i]
# 0
t = x.split(':')[1]
data[0] = list(map(int,t.split()))
i += 3
# 1
for index in range(1,8):
data[index] = []
x = input_list[i]
while len(x) > 1:
data[index].append(list(map(int,x.split())))
i += 1
x = input_list[i]
i += 2
return data
def get_min(data):
ans = 123456789012345
for xi in range(0,len(data[0]),2):
x = data[0][xi]
aa = [[data[0][xi],data[0][xi]+data[0][xi+1]-1]]
for i in range(1,8):
an = []
i1 = -1
for a in aa:
i1 += 1
i2 = -1
is_add = 0
for r in data[i]:
i2 += 1
rl = r[1]
rr = r[1] + r[2] - 1
d = r[0] - r[1]
if rl <= a[0] and a[1] <= rr:
an.append([a[0]+d,a[1]+d])
is_add = 1
elif a[0] <= rl and rr <= a[1]:
an.append([rl+d,rr+d])
is_add = 1
if a[0] < rl:
aa.append([a[0],rl-1])
if rr > a[1]:
aa.append([rr+1,a[1]])
elif a[0] < rl and rl <= a[1] and a[1] <= rr:
is_add = 1
an.append([rl+d,a[1]+d])
aa.append([a[0],rl-1])
elif rl <=a[0] and a[0] <= rr and rr < a[1]:
is_add = 1
an.append([a[0]+d,rr+d])
aa.append([rr+1,a[1]])
if not is_add:
an.append([a[0],a[1]])
aa = an
for r in aa:
ans = min(ans,r[0])
return ans
def solve(input_list):
data = get_values(input_list)
print(get_min(data))
def main():
file_name = 'sample.txt'
file_name = 'input.txt'
r_list = []
with open(file_name,'r') as file:
for x in file:
r_list.append(x[:-1])
solve(r_list)
main()
Part 1
def f1(text):
t1 = text.split(':')[1]
[w,l] = t1.split('|')
ans = -1
w = w.split()
for x in l.split():
if x in w:
ans += 1
if ans == -1:
return 0
return 2**ans
def solve(input_list):
ans = 0
for x in input_list:
ans += f1(x)
print(ans)
return ans
def main():
# file_name = 'sample.txt'
file_name = 'input.txt'
r_list = []
with open(file_name,'r') as file:
for x in file:
r_list.append(x[:-1])
solve(r_list)
main()
Part 2
def f1(text):
t1 = text.split(':')[1]
[w,l] = t1.split('|')
ans = 0
w = w.split()
for x in l.split():
if x in w:
ans += 1
return ans
def solve(input_list):
ans = 0
ladd=[]
for x in range(len(input_list)):
ladd.append(1)
for i in range(len(input_list)):
t = f1(input_list[i])
for i1 in range(t):
ladd[i+i1+1] += ladd[i]
for x in ladd:
ans += x
print(ans)
return ans
def main():
file_name = 'sample.txt'
file_name = 'input.txt'
r_list = []
with open(file_name,'r') as file:
for x in file:
r_list.append(x[:-1])
solve(r_list)
main()
Part 1
import re
def touch(text_input,i0,j0):
ans = 0
for i in range(max(0,i0-1),min(len(text_input),i0+2)):
for j in range(max(0,j0-1),min(len(text_input[i]),j0+2)):
if not text_input[i][j].isdigit() and text_input[i][j] != '.':
return True
return False
def solve(input_list):
ans = 0
for i in range(len(input_list)):
to_add = False
num_text = ''
for j in range(len(input_list[i])):
if input_list[i][j].isdigit():
if touch(input_list,i,j):
to_add = True
num_text += input_list[i][j]
else:
if to_add:
ans += int(num_text)
to_add = False
num_text=''
if to_add:
ans += int(num_text)
to_add = False
print(ans)
return ans
def main():
# file_name = 'sample.txt'
file_name = 'input.txt'
r_list = []
with open(file_name,'r') as file:
for x in file:
r_list.append(x[:140])
solve(r_list)
main()
Part 2
import re
def touch(text_input,i0,j0):
ans = 0
for i in range(max(0,i0-1),min(len(text_input),i0+2)):
for j in range(max(0,j0-1),min(len(text_input[i]),j0+2)):
if not text_input[i][j].isdigit() and text_input[i][j] == '*':
return f'{i}-{j}'
return ''
def add_map(m,x,v):
if x in m:
m[x].append(v)
else:
m[x]=[v]
def solve(input_list):
ans = 0
map_ans = {}
for i in range(len(input_list)):
to_add = False
num_text = ''
key = ''
for j in range(len(input_list[i])):
if input_list[i][j].isdigit():
if len(touch(input_list,i,j)):
to_add = True
key = touch(input_list,i,j)
num_text += input_list[i][j]
else:
if to_add:
add_map(map_ans,key,int(num_text))
key = ''
to_add = False
num_text=''
if to_add:
add_map(map_ans,key,int(num_text))
to_add = False
for key,value in map_ans.items():
if len(value) == 2:
ans += value[0]*value[1]
print(ans)
return ans
def main():
# file_name = 'sample.txt'
file_name = 'input.txt'
r_list = []
with open(file_name,'r') as file:
for x in file:
r_list.append(x[:140])
solve(r_list)
main()