tasks a-s

This commit is contained in:
Ingy döt Net 2013-04-10 23:57:08 -07:00
parent 47bf37c096
commit b83f433714
12433 changed files with 156208 additions and 123 deletions

View file

@ -0,0 +1,16 @@
import Data.List
import Numeric
import Text.Printf
-- Use the built-in function showIntAtBase.
toBin n = showIntAtBase 2 ("01" !!) n ""
-- Implement our own version.
toBin' 0 = []
toBin' x = (toBin' $ x `div` 2) ++ (show $ x `mod` 2)
printToBin n = putStrLn $ printf "%4d %14s %14s" n (toBin n) (toBin' n)
main = do
putStrLn $ printf "%4s %14s %14s" "N" "toBin" "toBin'"
mapM_ printToBin [5, 50, 9000]