Non-decimal radices/Output: Difference between revisions

m
→‎{{header|Haskell}}: (updated baseDigits function)
m (→‎{{header|Haskell}}: (added a further radix (32) to the test))
m (→‎{{header|Haskell}}: (updated baseDigits function))
Line 581:
 
tableRows :: [[String]]
tableRows = ((([intToDigitsbaseDigits] <*> bases) <*>) . return) <$> [1 .. 33]
 
digits :: Array Int Char
digits = listArray (0, 35) (['0' .. '9'] <> ['A' .. 'Z'])
 
intToDigitsbaseDigits :: Int -> Int -> String
intToDigitsbaseDigits base n =
| base > 36 = elseconst "Needs numeric glyphs beyond Z"
let b = abs base
| otherwise = reverse . unfoldr remQuot
in if b <= 36
where
then reverse $
remQuot 0 = unfoldrNothing
remQuot n (\x ->=
let (q, r) = quotRem n if x > 0base
in Just (digits ! r, q)
then let (q, r) = quotRem x b
in Just (digits ! r, q)
else Nothing)
n
else "Needs numeric glyphs beyond Z"
 
-- TEST AND TABULATION---------------------------------------------------------
9,655

edits