Intersecting number wheels: Difference between revisions
m
→{{header|Haskell}}: Tidied, applied Ormolu.
m (→{{header|Haskell}}: Tidied, applied Ormolu.) |
|||
Line 893:
terminating at the first digit found, and printing a map-accumulation of that recursion over a list of given length but arbitrary content.
<lang haskell>import
import Data.Char (isDigit)▼
import Data.List (mapAccumL)▼
import qualified Data.Map.Strict as M
import Data.Maybe (fromMaybe)
▲import Data.List (mapAccumL)
▲import Data.Char (isDigit)
---------------- INTERSECTING NUMBER WHEELS --------------
clockWorkTick ::
M.Map Char String ->
(M.Map Char String, Char)
clockWorkTick = flip click 'A'
where
Line 906 ⟶ 909:
let wheel = fromMaybe ['?'] (M.lookup name wheels)
v = head wheel
in bool
click
(,)
(isDigit v || '?' == v)
(M.insert name (leftRotate wheel) wheels)
v
leftRotate :: [a] -> [a]
leftRotate = take . length <*> (tail . cycle)
▲-- TEST ---------------------------------------------------
main :: IO ()
main = do
let wheelSets =
[ [('A', "123")],
]
putStrLn "State of each wheel-set after 20 clicks:\n"
mapM_ print $
fmap
( flip
(replicate 20 undefined)
. M.fromList
)
wheelSets
putStrLn "\nInitial state of the wheel-sets:\n"
|