Skip to content

Instantly share code, notes, and snippets.

@gormster
Created August 9, 2018 07:25
Show Gist options
  • Save gormster/897f16a48aefa2e7f05be8e316f5044d to your computer and use it in GitHub Desktop.
Save gormster/897f16a48aefa2e7f05be8e316f5044d to your computer and use it in GitHub Desktop.
# coding: utf-8
import itertools
stars = [complex(x,y) for x,y in itertools.product(range(11),range(5)) if (x + y) % 2 == 0]
def print_flag(s):
lines = []
for y in range(5):
line = []
for x in range(11):
if complex(x,y) in s:
line.append("*")
else:
line.append(" ")
lines.append(line)
print '┌─────────────────────┐'
print '\n'.join('│%s│' % ' '.join(line) for line in lines)
print '\n'.join('│%s│' % ' '.join(line) for line in lines[-2::-1])
print '└─────────────────────┘'
flags = []
def first_connected(field, blob):
for i in field:
if any(1 < abs(i-star) < 2 for star in blob):
return i
return None
def check_flag(flag):
centres = len([s for s in flag if s.imag == 4])
others = len([s for s in flag if s.imag < 4])
if centres == 0:
return False
if others * 2 + centres != 13:
return False
connected = [flag[0]]
stars = set(flag) - set(connected)
for i in range(1,len(flag)):
s = first_connected(stars, connected)
if s is not None:
connected.append(s)
stars = set(flag) - set(connected)
else:
print "not connected %s to %s" % (stars, connected)
return False
return True
print check_flag([0+0j,1+1j,0+2j,1+3j,0+4j,2+4j,4+4j,6+4j,8+4j])
exit(0)
for n in [9]:
count = 0
print "%i centre stars" % (n * 2 - 13)
for flag in itertools.combinations(stars, n):
if check_flag(flag):
flags.append(flag)
count += 1
print_flag(flag)
print "%i total" % count
print "%i total flags " % len(flags)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment