[ create a new paste ] login | about

Link: http://codepad.org/0XCZ4sBt    [ raw code | output | fork ]

neetsdkasu - Haskell, pasted on Jul 29:
1
2
3
4
5
6
7
8
9
10
11
12
main = print $ length . filter id $ map (\x -> solve x == solve2 x) [1..100]

solve n = ans where
    ans = fst $ foldl h (0, 0) $ map g [1..n]
    g x = (x, f 0 x)
    f a 1 = a
    f a x = f (a + 1 - mod x 2) (div x 2)
    h a@(_, ac) v@(_, vc) = if ac > vc then a else v


-- 解説見て書いた
solve2 n = last $ takeWhile (<= n) [2 ^ x | x <- [0..]]


Output:
1
100


Create a new paste based on this one


Comments: