Comment detail

2進数の記述 (Nested Flatten)

This comment is reply for 4553 anekos: (2進数の記述). Go to thread root.

リストで書くのはめんどくさいので。

1
2
3
4
5
6
b :: Integer -> Integer
b 0 = 0
b x = b' x + 2 * b (div x 10)
    where b' x = if odd x then 1 else 0

main = print $ b 01101001  -- 10

Index

Feed

Other

Link

Pathtraq

loading...