Skip to content

Instantly share code, notes, and snippets.

@hamishcampbell
Created September 7, 2013 01:35
Show Gist options
  • Save hamishcampbell/6472043 to your computer and use it in GitHub Desktop.
Save hamishcampbell/6472043 to your computer and use it in GitHub Desktop.
Highly readable Polyomino solution
import sys, itertools
class Polyomino(tuple):
def __hash__(_):return(getattr(_,'',''))or[setattr(_,'',setattr(_,'_',map(min,zip(
*(setattr(_,'p',_.__class__((c[1],m-c[0]-1)for(c)in(_.p))if'p'in(_.__dict__)else(_))
or(getattr(_,'p'))))))or(min(getattr(_,'',hash(tuple(sorted(setattr(_,'p',_.__class__(
[(x-_._[0],y-_._[1])for(x,y)in(_.p)])if(_._[0]or(_._[1]))else(_.p))or(_.p))))),
hash(tuple(sorted(_.p))))))for(m)in(itertools.repeat(max(max(_,key=max)),4))]and(getattr(_,''))
def __eq__(*_):return(1&len(set(map(hash,_))))
def __call__(_,__):return[_.__class__(((__,__),))]if(not(1%__))else(set(itertools.chain(*[set([_.__class__
(_+tuple([a]))for(a)in(set((c[0]+x,c[1]+y)for(c,(x,y))in(itertools.product(
_,((-1,0),(1,0),(0,-1),(0,1)))))).difference(_)])for(_)in(_(__-1))])))
print(len(Polyomino()(int(sys.argv.pop()))))
@timClicks
Copy link

Wait what?

@hamishcampbell
Copy link
Author

hamishcampbell commented Sep 7, 2013

@timClicks : Made a talk for 2014 - "Fun with python obfuscation: dirty tricks, object model abuse & unintended side effects."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment