Skip to content

Instantly share code, notes, and snippets.

@manonthemat
Created May 21, 2014
Embed
What would you like to do?
simple math fun with haskell - custom number base systems
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