Intersecting number wheels: Difference between revisions
Content deleted Content added
→Python: Functional composition: Added a functionally composed variant (map-accumulation of a recursion) |
→Python: Functional composition: Changed type of leftRotate (compacting output), and added legend. |
||
Line 767: | Line 767: | ||
# leftRotate :: [a] -> |
# leftRotate :: [a] -> String |
||
def leftRotate(xs): |
def leftRotate(xs): |
||
''' A |
''' A string shifted cyclically towards |
||
the left by one position. |
the left by one position. |
||
''' |
''' |
||
return |
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': |
({'A': '312'}, '12312312312312312312') |
||
({'A': |
({'A': '21B', 'B': '43'}, '13214213214213214213') |
||
({'A': |
({'A': 'D1D', 'D': '786'}, '16718617816718617816') |
||
({'A': 'C1B', 'B': '34', 'C': '5B'}, '13514314513413514314')</pre> |
|||
=={{header|REXX}}== |
=={{header|REXX}}== |