Skip to main content
1 of 4
globby
  • 1.2k
  • 8
  • 25

Python with PIL - A trivial and non-optimal solution, 961 bytes

It takes ~2 minutes to run the first two test cases, and >10 minutes to run the third on my system because of the quickly made up, terribly resource intensive, and absolutely repulsive algorithm complexity. Despite this, it does meet requirements. It is not optimally golfed either, this is simply to try to demonstrate a silly approach at solving the problem.

from PIL import Image,ImageDraw
a=lambda x,y,w,h:filter(lambda x:0<=x[0]<w and 0<=x[1]<h,[(x-1,y-1),(x,y-1),(x+1,y-    1),(x-1,y),(x,y),(x+1,y),(x-1,y+1),(x,y+1),(x+1,y+1)])
def b(c):
 d=0,255,0;e,f=c.size;g=c.load();h,i=[],[];j=Image.new("RGB",(e,f));k=ImageDraw.Draw(j)
 for l in range(e):
  for m in range(e):
   n=g[l,m][:-1]
   if n==d and(l,m)not in i:
    o=[(l,m)];p=[];q=1
    while q:
     q=0;r=o[:]
     for s in o:
      t=filter(lambda x:g[x[0],x[1]][:-1]==d and(x[0],x[1]) not in r,a(s[0],s[1],e,f))
      if t:
       r+=t
       if len(t)<8:
        p+=[s]
       q=1
     o=r
    h+=[p]
    for u in o:
     i+=[u]
   i+=[(l,m)]
 p=map(lambda x:"#"+str(x)*6,'123456789ab');v=0;k.rectangle((0,0,e,f),fill=p[0])
 for n in p[1:]:
  w=e/20*v;x=e-w;k.ellipse((w,w,x,x),fill=n);v+=1
 y=j.load();z=0
 for l in h:
  v=[]
  for m in l:
   s=y[m[0],m[1]]
   if s not in v:
    v+=[s]
  v=max(v);z+=p.index("#"+''.join(map(lambda x:hex(x)[2:],v)))
 return z

Takes a PIL image object, and returns the score.

##Steps it takes:##

  1. Isolate green circles (inefficiently)
  • Find all neighbours of some pixel n, if any are green pixels then add them to the circle
  • Determine rough outline by filtering out pixels that have 8 neighbours
  1. Draw a target representation
  • Create a blank canvas
  • Draw a unique colored background (easy to implement misses)
  • Draw nested ellipses with unique colors
  1. Determine which scoring zones each circle is in by determining the color(s) of the target which would be underneath the circle
  2. Choose the higher of the scoring zones (if multiple) and add the score to the total
  3. Return the total
globby
  • 1.2k
  • 8
  • 25