module Main (main) where
import System
fold :: Int -> String -> String
fold n cs = let (h, t) = splitAt n cs
in if null t then h else h ++ "\n" ++ fold n t
main :: IO ()
main = do cs <- getContents
putStr $ unlines $ map (fold 30) $ lines cs
結果
>runghc fold.hs < fold.hs
module Main (main) where
import System
fold :: Int -> String -> Strin
g
fold n cs = let (h, t) = split
At n cs
in if null t the
n h else h ++ "\n" ++ fold n
t
main :: IO ()
main = do cs <- getContents
putStr $ unlines $ m
ap (fold 30) $ lines cs
type Program = ([Char], [Char])
progNew :: String -> Program
progNew str = ([], str)
progFetch :: Program -> [Char]
progFetch prog = snd prog
progShift :: Program -> Program
progShift (l, (r:rs)) = (l ++ [r], rs)
progUnshift :: Program -> Program
progUnshift (l, r) = (take ((length l) -1) l, (last l):r)
progSkip :: BrainF_ck -> Program -> Program
progSkip bf prog = if bfValue bf == 0 then skip prog else progShift prog
where skip p = if (head $ progFetch next) == ']' then next else skip next
where next = progShift p
progBack :: BrainF_ck -> Program -> Program
progBack bf prog = if bfValue bf == 0 then progShift prog else back prog
where back p = if (head $ progFetch prev) == '[' then prev else back prev
where prev = progUnshift p
import System
showStar :: Int -> IO ()
showStar n = do putStrLn $ (show n) ++ " : " ++ (repeatStar n)
repeatStar :: Int -> String
repeatStar n = take n $ repeat '*'
main = do args <- getArgs
mapM_ showStar $ map read args