无心人 发表于 2013-4-7 15:41:13

牛顿迭代计算整数平方根let nsqrtN (x, y, a) = (div (x + (div a x))2, x, a)
let nsqrtLast (x, y, a) = abs(x-y)<=1
let nsqrtResult (x, y, a) =if (x*x<=a) then x else (x-1)
let nsqrt a = if (a<4) then 1 else nsqrtResult \$ until nsqrtLast nsqrtN (1, a, a)

无心人 发表于 2013-4-20 14:09:20


let divisors n = Data.List.sort \$ (\(x, y)->x ++ y) \$ unzip [(x, div n x)|x<-, mod n x == 0]
页: 1 2 3 4 5 [6]
查看完整版本: Haskell自我娱乐帖