I could have used this a week ago.
def fccstack(): newlimit = 0 while True: oldlimit = newlimit newlimit += 1 # extend z for x in xrange(oldlimit): for y in xrange((x+oldlimit)&1, oldlimit, 2): yield (x,y,oldlimit) # extend y for x in xrange(oldlimit): for z in xrange((x+oldlimit)&1, newlimit, 2): yield (x,oldlimit,z) # extend x for y in xrange(newlimit): for z in xrange((y+oldlimit)&1, newlimit, 2): yield (oldlimit,y,z) g = fccstack() for dummy in xrange(512): p,q,r = g.next() print "%d %d %d\t%d" % (p,q,r, p+q+r)
This lists coordinates of sites in a face-centred cubic lattice, filling the smallest cube that contains the number of sites required.