Non-decimal radices/Output: Difference between revisions
Content added Content deleted
m (→{{header|Haskell}}: (added a further radix (32) to the test)) |
m (→{{header|Haskell}}: (updated baseDigits function)) |
||
Line 581: | Line 581: | ||
tableRows :: [[String]] |
tableRows :: [[String]] |
||
tableRows = ((([ |
tableRows = ((([baseDigits] <*> bases) <*>) . return) <$> [1 .. 33] |
||
digits :: Array Int Char |
digits :: Array Int Char |
||
digits = listArray (0, 35) (['0' .. '9'] <> ['A' .. 'Z']) |
digits = listArray (0, 35) (['0' .. '9'] <> ['A' .. 'Z']) |
||
baseDigits :: Int -> Int -> String |
|||
baseDigits base |
|||
⚫ | |||
let b = abs base |
|||
| otherwise = reverse . unfoldr remQuot |
|||
in if b <= 36 |
|||
where |
|||
then reverse $ |
|||
remQuot 0 = Nothing |
|||
remQuot n = |
|||
let (q, r) = quotRem n base |
|||
⚫ | |||
then let (q, r) = quotRem x b |
|||
⚫ | |||
else Nothing) |
|||
n |
|||
⚫ | |||
-- TEST AND TABULATION--------------------------------------------------------- |
-- TEST AND TABULATION--------------------------------------------------------- |