September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -9,6 +9,14 @@ toBin n = showIntAtBase 2 ("01" !!) n ""
|
|||
toBin1 0 = []
|
||||
toBin1 x = (toBin1 $ x `div` 2) ++ (show $ x `mod` 2)
|
||||
|
||||
-- Or even more efficient (due to fusion) and universal implementation
|
||||
toBin2 = foldMap show . reverse . toBase 2
|
||||
|
||||
toBase base = unfoldr modDiv
|
||||
where modDiv 0 = Nothing
|
||||
modDiv n = let (q, r) = (n `divMod` base) in Just (r, q)
|
||||
|
||||
|
||||
printToBin n = putStrLn $ printf "%4d %14s %14s" n (toBin n) (toBin1 n)
|
||||
|
||||
main = do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue