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 qualified Data.Map.Strict asBool M(bool)
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)
import Data.Bool (bool)
 
---------------- INTERSECTING NUMBER WHEELS --------------
 
clockWorkTick :: M.Map Char String -> (M.Map Char String, Char)
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 -------------------------- TEST -------------------------
 
-- TEST ---------------------------------------------------
main :: IO ()
main = do
let wheelSets =
[ [('A', "123")],
, [('A', "1B2"), ('B', "34")],
, [('A', "1DD"), ('D', "678")],
, [('A', "1BC"), ('B', "34"), ('C', "5B")]
]
putStrLn "State of each wheel-set after 20 clicks:\n"
mapM_ print $
fmap
( flip
(flip (mapAccumL (const . clockWorkTick)) (replicate 20 undefined) . M.fromList)
(replicate 20 undefined)
. M.fromList
)
wheelSets
putStrLn "\nInitial state of the wheel-sets:\n"
9,655

edits