• Home
  • About
  • RSS Feeds
  • Posts
  • Comments

val it: α → α = fun

  • Uncategorized
« 梅田望夫『ウェブ進化論』
reddit のおすすめリスト »

AA 折れ線グラフ問題

This entry was posted by Jun Mukai on Wednesday, 15 March, 2006
> >OSS web 今日の一行 >。 > >import List
import System.Environment

levels = unfoldr f . ((,) 0)
where f (n, 'R':rest) = Just ((n, '/'), (n+1, rest))
f (n, 'F':rest) = Just ((n-1, '\\'), (n-1, rest))
f (n, 'C':rest) = Just ((n, '_'), (n, rest))
f _ = Nothing

visualize ls l = map (\l' -> if l == fst l' then snd l' else ' ') ls

plot str = unlines $ map (visualize ls) [maxl, maxl-1 .. minimum ls']
where ls = levels str
ls' = fst $ unzip ls
maxl = maximum ls'

test = "RCRFCRFFCCRFFRRCRRCCFRFRFF"

main = getArgs >>= mapM_ (\l -> putStrLn l >> putStrLn (plot l)) > >こんなところでしょうか。あんまり面倒なことはしないで素直に解いています。ところで > >他の解答を見てみると、アルゴリズム自体は >花谷さんの答え >と同じだなぁ。ありきたりですね。って mapAccumL なんていう関数もありましたねぇ……。言われないと思い出せてません。とほほ。 >

Category: Uncategorized
You can follow any responses to this entry via
RSS.
Both comments and trackbacks are currently closed.

Comments are closed.

  • Archives

  • disclaimer

    ここで述べられていることは私の個人的な意見に基づくものであり、私の雇用者には一切の関係はありません。
© 2016 val it: α → α = fun powered by WordPress. Regal Theme Designed by Gauson Design
Log in | Top