Skip to main content
edited body
Source Link
tsn
  • 141
  • 3

Python 2, 528, 417, 393393, 381

Very long, bruteforce solution. It works but that's about it, the universe may end before getting the result for the last test case.

exec"fromexec u"from itertools import*;m=map;g=@w,n:([[w]],[[w[:i]]+s#i?range(1,len(w))#s?g(w[i:],n-1)])[n>1];r=@x:set(m(sum,[x[:i]#i?range(1,len(x))]));f=@w:1-all(m(@(x,y):not x&y,zip(m(r,w[:-1]),m(r,w[1:]))));a=@s,h:['\\n'.join([''.join(['[%s]'%(' '*(s-1)*2)#s?r])#r?o])#p?permutations(s)#o?g(p,h)if len(set([sum(r)#r?o]))<2 and~-f(o)][0]".replacetranslate("@","lambda{64:u"lambda ").replace("#","35:u" for ").replace("?","63:u" in "}) 

a is the main function:

>> a([1, 1, 2, 2], 2) '[][ ]\n[ ][]' 

Python 2, 528, 417, 393

Very long, bruteforce solution. It works but that's about it, the universe may end before getting the result for the last test case.

exec"from itertools import*;m=map;g=@w,n:([[w]],[[w[:i]]+s#i?range(1,len(w))#s?g(w[i:],n-1)])[n>1];r=@x:set(m(sum,[x[:i]#i?range(1,len(x))]));f=@w:1-all(m(@(x,y):not x&y,zip(m(r,w[:-1]),m(r,w[1:]))));a=@s,h:['\\n'.join([''.join(['[%s]'%(' '*(s-1)*2)#s?r])#r?o])#p?permutations(s)#o?g(p,h)if len(set([sum(r)#r?o]))<2 and~-f(o)][0]".replace("@","lambda ").replace("#"," for ").replace("?"," in ") 

a is the main function:

>> a([1, 1, 2, 2], 2) '[][ ]\n[ ][]' 

Python 2, 528, 417, 393, 381

Very long, bruteforce solution. It works but that's about it, the universe may end before getting the result for the last test case.

exec u"from itertools import*;m=map;g=@w,n:([[w]],[[w[:i]]+s#i?range(1,len(w))#s?g(w[i:],n-1)])[n>1];r=@x:set(m(sum,[x[:i]#i?range(1,len(x))]));f=@w:1-all(m(@(x,y):not x&y,zip(m(r,w[:-1]),m(r,w[1:]))));a=@s,h:['\\n'.join([''.join(['[%s]'%(' '*(s-1)*2)#s?r])#r?o])#p?permutations(s)#o?g(p,h)if len(set([sum(r)#r?o]))<2 and~-f(o)][0]".translate({64:u"lambda ",35:u" for ",63:u" in "}) 

a is the main function:

>> a([1, 1, 2, 2], 2) '[][ ]\n[ ][]' 
deleted 12 characters in body
Source Link
tsn
  • 141
  • 3

Python 2, 528, 417417, 393

Very long, bruteforce solution. It works but that's about it, the universe may end before getting the result for the last test case.

fromexec"from itertools import*;m=map;g=lambda wimport*;m=map;g=@w,n:[[w]]if n<=1 else[[w[([[w]],[[w[:i]]+s for i in i]]+s#i?range(1,len(w))for s in #s?g(w[i:],n-1)];r=lambda x])[n>1];r=@x:set(m(sum,[x[:i]for i in i]#i?range(1,len(x))]));f=lambda w;f=@w:not 1-all(m(lambda @(x,y):x.isdisjoint(y)not x&y,zip(m(r,w[:-1]),m(r,w[1:]))));a=lambda s;a=@s,h:['\n'['\\n'.join([''.join(["["+" "*['[%s]'%(' '*(s-1)*2)+"]"for s in #s?r])for r in #r?o])for p in #p?permutations(s)for o in #o?g(p,h)if len(set([sum(r)for r in #r?o]))<=1<2 and~-f(o)][0]][0]".replace("@","lambda ").replace("#"," for ").replace("?"," in ") 

a is the main function:

>> a([1, 1, 2, 2], 2) '[][ ]\n[ ][]' 

Python 2, 528, 417

Very long, bruteforce solution. It works but that's about it, the universe may end before getting the result for the last test case.

from itertools import*;m=map;g=lambda w,n:[[w]]if n<=1 else[[w[:i]]+s for i in range(1,len(w))for s in g(w[i:],n-1)];r=lambda x:set(m(sum,[x[:i]for i in range(1,len(x))]));f=lambda w:not all(m(lambda (x,y):x.isdisjoint(y),zip(m(r,w[:-1]),m(r,w[1:]))));a=lambda s,h:['\n'.join([''.join(["["+" "*((s-1)*2)+"]"for s in r])for r in o])for p in permutations(s)for o in g(p,h)if len(set([sum(r)for r in o]))<=1 and~-f(o)][0] 

a is the main function:

>> a([1, 1, 2, 2], 2) '[][ ]\n[ ][]' 

Python 2, 528, 417, 393

Very long, bruteforce solution. It works but that's about it, the universe may end before getting the result for the last test case.

exec"from itertools import*;m=map;g=@w,n:([[w]],[[w[:i]]+s#i?range(1,len(w))#s?g(w[i:],n-1)])[n>1];r=@x:set(m(sum,[x[:i]#i?range(1,len(x))]));f=@w:1-all(m(@(x,y):not x&y,zip(m(r,w[:-1]),m(r,w[1:]))));a=@s,h:['\\n'.join([''.join(['[%s]'%(' '*(s-1)*2)#s?r])#r?o])#p?permutations(s)#o?g(p,h)if len(set([sum(r)#r?o]))<2 and~-f(o)][0]".replace("@","lambda ").replace("#"," for ").replace("?"," in ") 

a is the main function:

>> a([1, 1, 2, 2], 2) '[][ ]\n[ ][]' 
deleted 190 characters in body
Source Link
tsn
  • 141
  • 3

Python 2, 528528, 417

Very long, bruteforce solution. It works but that's about it, the universe may end before getting the result for the last test case.

importfrom itertools def g(import*;m=map;g=lambda w,n): if[[w]]if n<=1:return[[w]]  return[[w[else[[w[:i]] + si]]+s for i in range(1,len(w)) for s in g(w[i:],n-1)] def];r=lambda r(x:set(m(sum,t=0)[x[: t=0;y=[] fori]for ei in range(1,len(x:t+=e;y+=[t] ))]));f=lambda returnw:not y defall(m(lambda f(wx,y): for ix.isdisjoint(y),o in enumeratezip(m(r,w[:-1]): a=r,m(or,w[1:]);b=r(w[i+1]) if));a=lambda lens,h:['\n'.join([0 for e in[''.join(["["+" b[:"*((s-1] if1)*2)+"]"for es in a[:-1]]r])>0:return 1 for returnr 0 defin a(s,ho]): for p in itertools.permutations(s): for o in g(p,h): if w=[sumlen(set([sum(r) for r in o] if not all(x==w[0] for x in w):continue if not)<=1 and~-f(o):return '\n'.join([''.join(["["+" "*((s-1)*2)+"]" for s in r]) for r in o])][0] 

a is the main function:

>> a([1, 1, 2, 2], 2) '[][ ]\n[ ][]' 

Python 2, 528

Very long, bruteforce solution. It works but that's about it, the universe may end before getting the result for the last test case.

import itertools def g(w,n): if n<=1:return[[w]]  return[[w[:i]] + s for i in range(1,len(w)) for s in g(w[i:],n-1)] def r(x,t=0): t=0;y=[] for e in x:t+=e;y+=[t]  return y def f(w): for i,o in enumerate(w[:-1]): a=r(o);b=r(w[i+1]) if len([0 for e in b[:-1] if e in a[:-1]])>0:return 1  return 0 def a(s,h): for p in itertools.permutations(s): for o in g(p,h):  w=[sum(r) for r in o] if not all(x==w[0] for x in w):continue if not f(o):return '\n'.join([''.join(["["+" "*((s-1)*2)+"]" for s in r]) for r in o]) 

a is the main function:

>> a([1, 1, 2, 2], 2) '[][ ]\n[ ][]' 

Python 2, 528, 417

Very long, bruteforce solution. It works but that's about it, the universe may end before getting the result for the last test case.

from itertools import*;m=map;g=lambda w,n:[[w]]if n<=1 else[[w[:i]]+s for i in range(1,len(w))for s in g(w[i:],n-1)];r=lambda x:set(m(sum,[x[:i]for i in range(1,len(x))]));f=lambda w:not all(m(lambda (x,y):x.isdisjoint(y),zip(m(r,w[:-1]),m(r,w[1:]))));a=lambda s,h:['\n'.join([''.join(["["+" "*((s-1)*2)+"]"for s in r])for r in o])for p in permutations(s)for o in g(p,h)if len(set([sum(r)for r in o]))<=1 and~-f(o)][0] 

a is the main function:

>> a([1, 1, 2, 2], 2) '[][ ]\n[ ][]' 
Fixed grammar mistake, added syntax highlighting
Source Link
user3094403
  • 8.4k
  • 7
  • 46
  • 71
Loading
Source Link
tsn
  • 141
  • 3
Loading