February 3, 2008
via. 日本野望の会ブログ: http://www.yabooo.org/archives/60
「3の倍数と3の付く数字だけアホになり、8の倍数だけ気持ち良くなります」
というやつ。
Haskellで剰余も文字列マッチも使わずにやってみた。
import Data.List
mul_of_3 = cycle [False, False, True]
mul_of_8 = cycle [False, False, False, False, False, False, False, True]
include_3 = iter ([False, False, True] ++ (replicate 7 False)) 1
where
expand = concatMap (replicate 10)
iter bs n = let rest = drop n $ iter (expand bs) (n*10)
in bs ++ (zipWith (||) (cycle bs) rest)
merge x y z n = show n ++
(if x || y then "~~~" else "") ++
(if z then "ooOOo" else "")
nabeatsu = zipWith4 merge include_3 mul_of_3 mul_of_8 [1..]
main = mapM_ putStrLn $ take 40 nabeatsu
ghcじゃ日本語リテラル使えないorz
- (no subject)
merge関数のif文に括弧がないとダメなことに気がついたので修正orz

Comment Thanks