euler-0.1.0.0

Safe HaskellSafe
LanguageHaskell2010

Euler.Util.Digit

Contents

Synopsis

Documentation

>>> import Test.QuickCheck

Conversions to list of digits

digits Source #

Arguments

:: (Integral a, Integral b) 
=> b

Base

-> a

Number to convert

-> [b] 

Digits of a positive integer.

textDigits :: Text -> [Int] Source #

Same as stringDigits, for Text instead of String.

stringDigits :: String -> [Int] Source #

Get the values of numeric characters from a string, ignoring any non-numeric characters.

>>> stringDigits " 0 x0 42a"
[0,0,4,2]

Conversions to single digits

charIntMaybe :: Char -> Maybe Int Source #

Maps the ten numeric ascii characters to their numeric values, and all other characters to Nothing.

>>> charIntMaybe '0'
Just 0
>>> charIntMaybe '9'
Just 9
>>> charIntMaybe 'a'
Nothing

Conversions from digits to integers

unDigits Source #

Arguments

:: (Integral a, Integral b) 
=> b

Base

-> [b]

Digits

-> a 

The positive integer represented by a list of digits,

Other stuff

intPalindrome Source #

Arguments

:: (Integral a, Integral b) 
=> b

Base

-> a

Number to test

-> Bool 

intPalindrome b n indicates whether the base-b representation n is a palindrome.

>>> intPalindrome 10 <$> [33, 13431, 21, 335]
[True,True,False,False]

Zero and one are palindromes in any base.

\(Positive n) -> intPalindrome (n+1) 0
\(Positive n) -> intPalindrome (n+1) 1