[1..100]>>=pen #6173(2008/04/12 07:48 GMT) [ Haskell ] Rating1/1=1.00
数学的な性質を使ったバージョン。 やっていることは kozimaさんの #428 とほとんど同じです。 golf的なところ ・(1+r0%n) と1加えてから計算を進め最後に (tail $ show q1) と 結果の文字列を tail して先頭の「1」をとることにより循環部より 前部分のリーディング0の生成処理。 ・find ((/=r2).snd) [dM (10*r)] は if (b /= r2) then Just (a,b) else Nothing where (a,b) = dM (10*r) の意。
1 2 3 4 5 6 7 8 9 10 11 12 13 14
import Ratio import List toDecimal m n = show q0 ++ "." ++ (tail $ show q1) ++ cyc where (q0,r0) = divMod m n x = until ((==1).gcd 10.denominator) (10*) (1+r0%n) (m',n') = (numerator x, denominator x) dM = (`divMod` n') (q1,r1) = dM m' cyc | n' == 1 = "" | otherwise = "{" ++ (rs >>= show) ++ "}" where rs = q2: unfoldr f r2 where (q2,r2) = dM (10*r1) f r = find ((/=r2).snd) [dM (10*r)]
Rating1/1=1.00-0+
[ reply ]
[1..100]>>=pen
#6173()
[
Haskell
]
Rating1/1=1.00
Rating1/1=1.00-0+
[ reply ]