天下一なんちゃらの例題を解いてみたよ
http://www.klab.jp/tenka1programer/bosyu.html
ここを見て,
import Data.Char import Data.Bits fromhexchar x | isDigit x = (ord x) - (ord '0') | True = (ord (toLower x)) - (ord 'a') + 10 fromhexstr (x:y:xs) = ((fromhexchar x) * 16 + (fromhexchar y)):(fromhexstr xs) fromhexstr [] = [] utf8len (x:y:z:xs) | x < 128 = 1 + utf8len (y:z:xs) | x < 196 = 1 + utf8len (z:xs) | otherwise = 1 + utf8len xs utf8len [] = 0 main = getContents >>= print.utf8len.fromhexstr.(filter (not.isSpace))
こんなのを書いて,
http://www16.atwiki.jp/tokoroten/pages/1153.html
ここを見て,
import Data.Char utf8len (x:xs) | (x == 'f' || x == 'e') = 1 + utf8len (drop 5 xs) | (x == 'd' || x == 'c') = 1 + utf8len (drop 3 xs) | otherwise = 1 + utf8len (tail xs) utf8len [] = 0 main = getContents >>= print.utf8len.(filter (not.isSpace))
こんなのを書いた.
$ echo e4bba5e4b88be381aee69687e5ad97e58897e381af5554462d\ 38e38292e69687e5ad97e382a8e383b3e382b3e383bce38387e382a\ 3e383b3e382b0e5bda2e5bc8fe381a8e38199e3828b3136e980b2e69\ 5b0e381aee38390e382a4e38388e58897e381a7e38182e3828be380\ 82 | runhaskell ./tenka2.hs 41
うん.久々のHaskellで鈍ってるかなぁーって思ったんだけど,鈍ってたのはHaskellの腕じゃなくて,問題をシンプルに解く発想力のほうだった.
おわり