Created
May 21, 2014 18:28
-
-
Save manonthemat/37231afb95252bfba76b to your computer and use it in GitHub Desktop.
simple math fun with haskell - custom number base systems
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Char (digitToInt) | |
numberToBaseString :: Int -> Int -> String | |
numberToBaseString n base | |
| n < base = show n | |
| otherwise = numberToBaseString ((n - (n `mod` base)) `div` base) base ++ show (n `mod` base) | |
baseStringToValue :: String -> Int -> Int | |
baseStringToValue n base | |
| n == [] = 0 | |
| otherwise = base * (baseStringToValue (init n) base) + digitToInt (last n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment