Abelian sandpile model/Identity: Difference between revisions

Content added Content deleted
(→‎{{header|Python}}: Added a functionally composed draft.)
(→‎Python :: Functional: Pruned residual magic numbers.)
Line 990: Line 990:
'''The stable final state of a sand-pile.
'''The stable final state of a sand-pile.
'''
'''
def p(xs):
return all([4 > x for x in xs])
xs = list(rows)
xs = list(rows)
w = len(xs)
w = len(xs)

def p(xs):
return all([x <= w for x in xs])
return list(chunksOf(w)(
return list(chunksOf(w)(
until(p)(
until(p)(
Line 1,007: Line 1,008:
'''
'''
def go(xs):
def go(xs):
mbi = findIndex(lambda x: 3 < x)(xs)
mbi = findIndex(lambda x: w < x)(xs)
surplus = 1 + w
if None is mbi:
if None is mbi:
return xs
return xs
Line 1,014: Line 1,016:
return [
return [
1 + k if i in neighbours else (
1 + k if i in neighbours else (
k - 4 if mbi == i else k
k - surplus if mbi == i else k
) for (i, k) in enumerate(xs)
) for (i, k) in enumerate(xs)
]
]