Intersecting number wheels: Difference between revisions

Content deleted Content added
Hout (talk | contribs)
→‎Python: Functional composition: Added a functionally composed variant (map-accumulation of a recursion)
Hout (talk | contribs)
→‎Python: Functional composition: Changed type of leftRotate (compacting output), and added legend.
Line 767: Line 767:




# leftRotate :: [a] -> [a]
# leftRotate :: [a] -> String
def leftRotate(xs):
def leftRotate(xs):
''' A list shifted cyclically towards
''' A string shifted cyclically towards
the left by one position.
the left by one position.
'''
'''
return list(islice(cycle(xs), 1, 1 + len(xs)))
return ''.join(islice(cycle(xs), 1, 1 + len(xs)))




Line 780: Line 780:
'''First twenty values from each set of test wheels.'''
'''First twenty values from each set of test wheels.'''


print('New state of wheel sets, after 20 clicks of each:\n')
for wheels, series in [
for wheels, series in [
mapAccumL(compose(const)(clockWorkTick))(
mapAccumL(compose(const)(clockWorkTick))(
Line 851: Line 852:
main()</lang>
main()</lang>
{{Out}}
{{Out}}
<pre>New state of wheel sets, after 20 clicks of each:
<pre>

({'A': ['3', '1', '2']}, '12312312312312312312')
({'A': ['2', '1', 'B'], 'B': ['4', '3']}, '13214213214213214213')
({'A': '312'}, '12312312312312312312')
({'A': ['D', '1', 'D'], 'D': ['7', '8', '6']}, '16718617816718617816')
({'A': '21B', 'B': '43'}, '13214213214213214213')
({'A': ['C', '1', 'B'], 'B': ['3', '4'], 'C': ['5', 'B']}, '13514314513413514314')</pre>
({'A': 'D1D', 'D': '786'}, '16718617816718617816')
({'A': 'C1B', 'B': '34', 'C': '5B'}, '13514314513413514314')</pre>


=={{header|REXX}}==
=={{header|REXX}}==