Skip to content

Instantly share code, notes, and snippets.

View jbum's full-sized avatar

Jim Bumgardner jbum

View GitHub Profile
# KenKen (aka Calcudoku, Mathdoku, Kendoku, Inkies) - contributed by Jim Bumgardner
# https://en.wikipedia.org/wiki/KenKen
#
# Puzzles sourced from the Inkies collection at Krazydad.com
from Numberjack import *
#
# Ensure that the sum of the segments
# in cc == res
def pointPhysics():
global pts # array of points on a sphere, specified as (lat,lon) pairs
new_pts = []
for i in xrange(nbrPoints):
(clat,clon) = pts[i] # center point for gnomonic projection (projects to 0,0)
fx,fy = (0,0)
for j in xrange(nbrPoints):
if j == i:
continue
jlat,jlon = pts[j]
# these projections come from http://mathworld.wolfram.com/GnomonicProjection.html
def gnomonic(lat, lon, clat, clon): # point, centroid both given in radians
# print "g",lat,lon,clat,clon
cosc = sin(clat) * sin(lat) + cos(clat) * cos(lat) * \
cos(lon - clon) # cosine of angular distance
x = (cos(lat) * sin(lon - clon)) / cosc
y = (cos(clat) * sin(lat) - sin(clat) * cos(lat) * cos(lon - clon)) / cosc
return (x, y)
def ignomonic(gx, gy, clat, clon):