Intersecting number wheels: Difference between revisions

Content added Content deleted
m (→‎{{header|Haskell}}: Tidied, applied Ormolu.)
m (→‎{{header|Haskell}}: Tidied, pruned out one import, preferring a guard to bool.)
Line 893: 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.
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 Data.Bool (bool)
<lang haskell>import Data.Char (isDigit)
import Data.Char (isDigit)
import Data.List (mapAccumL)
import Data.List (mapAccumL)
import qualified Data.Map.Strict as M
import qualified Data.Map.Strict as M
Line 907: Line 906:
where
where
click wheels name =
click wheels name =
let wheel = fromMaybe ['?'] (M.lookup name wheels)
let go m c
v = head wheel
| isDigit c = (m, c)
in bool
| otherwise = click m c
click
in ( go . flip (M.insert name . leftRotate) wheels
(,)
<*> head
(isDigit v || '?' == v)
)
(M.insert name (leftRotate wheel) wheels)
(fromMaybe ['?'] (M.lookup name wheels))
v


leftRotate :: [a] -> [a]
leftRotate :: [a] -> [a]