Comment detail

文字列で+を表示する (Nested Flatten)

This comment is reply for 10105 kozima: 最初にこんなリストを作って, :: ...(文字列で+を表示する). Go to thread root.

#10105に感銘。Haskellで再現させてみました。
quarterが1/4。
quarterとquarterの上下左右を入れ替えたものの合成がhalf。
rot90halfがhalfを90度回転させたもの。
halfとrot90halfの合成が最終結果。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
doukaku291 s = zipWith (\x y -> zipWith max x y) half rot90Half
  where
    ss n      = replicate n ' '
    len       = length s
    width     = len * 3 + 1
    quartar   = [(ss len) ++ s ++ (ss len) ++ " "] ++
                (replicate (len - 1) $ ss width)   ++
                [s ++ (ss len) ++ s ++ " "]        ++
                replicate (len * 2) (ss width)
    half      = zipWith max quartar $ reverse $ map (\x -> reverse x) quartar
    rot90Half = reverse $ take width $ foldr rot (replicate width []) half
      where rot (c:cs) (r:rs) = (c:r):(rot cs rs)

main = mapM_ putStrLn $ doukaku291 "doukaku"

Index

Feed

Other

Link

Pathtraq

loading...