Personal tools

Eth1winter pygame whizzrd

From Eth0Wiki

Jump to: navigation, search

Whizzrd's entry (543 chars, score 134)

import math

def c(x,l,n):
    if x<0:
        return 0
    if(x>=(n*n)):
	return 0
    if l[x] % 2 == 0:
       return l[x]
    else:
        return l[x] * -1

def f(x,l,n):
	return c(x-(n+1),l,n) + c(x-n,l,n)+ c(x-(n-1),l,n)+ c(x-1,l,n)+ c(x+1,l,n)+c(x+(n-1),l,n)+ c(x+n,l,n)+ c(x+(n+1),l,n)

def s(l):
	z=[0,[0,0]]
	t=len(l)
	n=int(math.sqrt(t))
	r=range(t)
	o=[f(i,l,n) for i in r]
	for i in r:
		y=int(math.ceil(i/n))
		x = i-(n*y)
		if z[0]<o[i]:
			z=[o[i],[x+1,n-y]]
	return z

def d(p):
	l=[]
	for j in p.split('\n'):
		for k in j.split(' '):
			l.append(int(k))
	return l

def AreaMax(p):
	return s(d(p))

Revised version (Floes + VeXocide, 351 chars, score 207

def C(x,l,n):
  return x>=0 and x<n*n and l[x]*(1,-1)[l[x]&1]

def F(x,l,n):
  return C(x-(n+1),l,n)+C(x-n,l,n)+C(x-(n-1),l,n)+C(x-1,l,n)+C(x+1,l,n)+C(x+(n-1),l,n)+C(x+n,l,n)+C(x+(n+1),l,n)

def AreaMax(p):
  m=0
  l=map(int,p.split())
  t=len(l)
  n=int(t**.5)
  r=range(t)
  o=[F(i,l,n) for i in r]
  for i in r:
    y=i/n
    x=i-(n*y)
    if o[i]>m:
      m,C=o[i],(x+1,n-y)
  return m,C