LoginSignup
0

More than 5 years have passed since last update.

第18回オフラインリアルタイムどう書く Haskellで解けなかった

Posted at

Haskell

http://qiita.com/Nabetani/items/ad47666c2f2f44ada1e7
http://nabetani.sakura.ne.jp/hena/ord18notfork/

module Main where

main = do
    let order = "42873x.3."
    print order

data Customer = Normal | Claimer deriving (Eq, Show)
type Line = [Customer]

checkers :: [Int]
checkers = [2,7,3,5,2]

regist :: [Line] -> [Line]
regist lines = map regist' $ zip [0..] lines where
  regist' nl = dropNormal (checkers !! regidx) line where
    (regidx, line) = nl
    dropNormal 0 l = l
    dropNormal n l@(c:cs) = case c of 
      Normal  -> dropNormal (n-1)  cs
      Claimer -> l

timeElapsed :: String -> [Line]
timeElapsed cs = timeElapsed' cs [] where
  timeElapsed' (c:cs) lines = case c of
    '.' -> timeElapsed' cs $ regist lines
    'x' -> timeElapsed' cs $ lineup 1 Claimer lines
    otherwise -> timeElapsed' cs $ lineup (read [c]) Normal lines

  lineup :: Int -> Customer -> [Line] -> [Line]
  lineup n customer ls = lineup' (replicate n customer) ls where
    lineup' cs ls = undefined

lineup' で詰まった..orz

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0