last day (15 days later) » 

11:28 AM
1
A: Solve a game of Accordion

Pietu1998Python 3, 274 bytes def g(p): q=lambda a:[[i,a]for i in range(len(p)-a)if p[i][:-1]in p[i+a][:-1]or p[i][-1]in p[i+a]] for n in q(1)+q(3): s=sum(n);c=p[:s]+p[s+1:];c[n[0]]=p[s] if[]!=g(c):return p[n[0]]+' <- '+p[s]+','+g(c) return''if len(p)<2else[] print(g(input().split(','))[:-1]or'')...

 
Use functools.lru_cache instead of writing your own.
 
@orlp I would, but as list is unhashable it doesn't work.
 
Then use tuples.
 
@orlp OK, but that would require changes to the code (e.g. str.split returns list). I'd prefer the two programs to be functionally equivalent.
 
You could do h=lambda p:lru_cache(None)(g)(''.join(p)).
 
11:28 AM
@orlp That becomes another problem with c[n[0]]=p[s]. I'll just go with these changes and standard lru_cache
 
h=lambda p:lru_cache(None)(lambda q:g(list(q)))(tuple(p))
 
That still has the same problem, tuples can't be assigned to either
 
hold on let me actually read what everything does
first thing first by the way
you can remove maxsize=
 
Well that's not really a problem since I count only the bytes of the golfed solution
That sort of helps
 
second you can use from functools import*
 
11:31 AM
Again, I'm not golfing the cache thing, it's just to make testing possible
 
oh
well then you want something that memoizes it without having to edit it
 
That's basically what I was doing before
The functools thing is a lot faster though, so I'll just go with that
 
11:45 AM
@Pietu1998 you can safe a bit
remove []!=
and do return' 'if len(p)<2else[]
 
Yeah, and then just change [:-1] to [:-2] to get rid of the comma
 

last day (15 days later) »