mirror of
https://github.com/peter-tanner/advent-of-code-2020.git
synced 2024-11-30 10:50:17 +08:00
some more changes for day 10
This commit is contained in:
parent
5e8fc1afb2
commit
3e0c92c972
8
10/a.py
8
10/a.py
|
@ -12,21 +12,19 @@ def a(transformers):
|
||||||
v_ = min(set(range(v+1,v+4)).intersection(transformers))
|
v_ = min(set(range(v+1,v+4)).intersection(transformers))
|
||||||
dv.append(v_ - v)
|
dv.append(v_ - v)
|
||||||
v = v_
|
v = v_
|
||||||
# print(dv)
|
|
||||||
|
|
||||||
count = dict(Counter(dv))
|
count = dict(Counter(dv))
|
||||||
return count[3]*count[1]
|
return count[3]*count[1]
|
||||||
|
|
||||||
def b(c, v, transformers):
|
def b(c, v, transformers):
|
||||||
for v_ in set(range(v+1,v+4)).intersection(lines):
|
for v_ in set(range(v+1,v+4)).intersection(lines):
|
||||||
# print(v_)
|
|
||||||
if v_ == max(transformers):
|
if v_ == max(transformers):
|
||||||
c += 1
|
c += 1
|
||||||
else:
|
else:
|
||||||
c = b(c, v_, transformers)
|
c = b(c, v_, transformers)
|
||||||
return c
|
return c
|
||||||
# print(b(0, 0, lines)) #This is a recursive solution. IT works but it'll take an eternity to go through the whole list of transformers.
|
# print(b(0, 0, lines))
|
||||||
#My solution: Split the set by 'gaps' (where there is only one path through to the next number), then multiply together
|
## This is a recursive solution. IT works but it'll take an eternity to go through the whole list of transformers.
|
||||||
|
## My solution: Split the set by 'gaps' (where there is only one path through to the next number), then multiply together. defintely not the most optimal but it's logical for me and it works! :)
|
||||||
def b_optimized(transformers):
|
def b_optimized(transformers):
|
||||||
rel = { v: set(range(v+1,v+4)).intersection(transformers) for v in transformers }
|
rel = { v: set(range(v+1,v+4)).intersection(transformers) for v in transformers }
|
||||||
rel.pop(max(transformers))
|
rel.pop(max(transformers))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user