Towers of Hanoi: Difference between revisions

m
→‎Python - Graphic: (Updated caption positions and arrows directions)
m (→‎Python Graphic: (repositioned captions))
m (→‎Python - Graphic: (Updated caption positions and arrows directions))
Line 3,509:
a, b = ab
xs, ys = tpl[a], tpl[b]
 
w = 3 * (2 + (2 * max(map(max, filter(len, tpl[:-1])))))
 
def delta(i):
Line 3,515 ⟶ 3,517:
) else [xs[0]] + ys
 
tkns = moveName(('left', 'mid', 'right'))(ab)
caption = ' '.join(tkns)
return tuple(map(delta, [0, 1, 2])) + (
moveName(('left',caption if tkns[0] != 'mid' else caption.rjust(w, 'right '))(ab),
)
 
Line 3,549 ⟶ 3,553:
 
 
# moveName :: (String, String, String) -> (Int, Int) -> [String]
def moveName(labels):
'''(from, to) index pair represented as an a -> b string.'''
def go(ab):
a, b = ab
return [labels[a] +, ' -> ' +, labels[b]] if a < b else [
labels[b], ' <- ', labels[a]
]
return lambda ab: go(ab)
 
Line 3,681 ⟶ 3,687:
______
________________________
left -> right
 
____
______ __
________________________
left -> mid
 
______ ____ __
________________________
mid <- right
right -> mid
 
__
______ ____
________________________
left -> right
 
__
____ ______
________________________
midleft <-> left mid
 
__ ____ ______
________________________
mid -> right
 
____
__ ______
________________________
left -> right
 
__
9,659

edits