updated
This commit is contained in:
@@ -17,14 +17,14 @@ def p1():
|
|||||||
for element in sample[1:]:
|
for element in sample[1:]:
|
||||||
if 'no' in element:
|
if 'no' in element:
|
||||||
continue
|
continue
|
||||||
data.append(element.split(' ', 1))
|
data.append(tuple(element.split(' ', 1)))
|
||||||
pwd[sample[0]] = data
|
pwd[sample[0]] = data
|
||||||
|
|
||||||
@functools.lru_cache(maxsize=256)
|
@functools.lru_cache(maxsize=256)
|
||||||
def contains_gold(y):
|
def contains_gold(y):
|
||||||
return 'shiny gold' == y or any(map(lambda x: contains_gold(x[1]), pwd[y]))
|
return 'shiny gold' == y or any(map(lambda x: contains_gold(x[1]), pwd[y]))
|
||||||
|
|
||||||
s = sum(map(lambda x: any(map(lambda x: contains_gold(x[1]), pwd[x])), pwd))
|
s = sum(map(lambda x: any(map(lambda y: contains_gold(y[1]), pwd[x])), pwd))
|
||||||
|
|
||||||
|
|
||||||
print(s)
|
print(s)
|
||||||
@@ -53,12 +53,12 @@ def p2(r):
|
|||||||
if part_one():
|
if part_one():
|
||||||
start = time.time()
|
start = time.time()
|
||||||
result1 = p1()
|
result1 = p1()
|
||||||
print(round(time.time() - start, 6), 's')
|
print(round(1000*(time.time() - start), 2), 'ms')
|
||||||
|
|
||||||
|
|
||||||
if part_two():
|
if part_two():
|
||||||
start = time.time()
|
start = time.time()
|
||||||
p2(result1)
|
p2(result1)
|
||||||
print(round(time.time() - start, 6), 's')
|
print(round(1000*(time.time() - start), 2), 'ms')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user