Non-decimal radices/Output: Difference between revisions
Content added Content deleted
(→{{header|Haskell}}: (removed redundant import)) |
(→{{header|Haskell}}: (a less partial draft of intToDigits)) |
||
Line 577: | Line 577: | ||
-- ARBITRARY RADICES ---------------------------------------------------------- |
-- ARBITRARY RADICES ---------------------------------------------------------- |
||
bases :: [Int] |
bases :: [Int] |
||
bases = [2, 7, 8, 10, 12, 16] |
bases = abs <$> [2, 7, 8, 10, 12, 16] |
||
tableRows :: [[String]] |
tableRows :: [[String]] |
||
Line 584: | Line 584: | ||
intToDigits :: Int -> Int -> String |
intToDigits :: Int -> Int -> String |
||
intToDigits base n = |
intToDigits base n = |
||
let |
let b = abs base |
||
ds = take b (['0' .. '9'] <> ['A' .. 'Z']) |
|||
in reverse $ |
|||
in if b <= 36 |
|||
then reverse $ |
|||
unfoldr |
|||
(\x -> |
|||
if x > 0 |
|||
then let (q, r) = quotRem x b |
|||
in Just (ds !! r, q) |
|||
⚫ | |||
else Nothing) |
|||
⚫ | |||
else "Needs numeric glyphs beyond Z" |
|||
-- TEST AND TABULATION--------------------------------------------------------- |
-- TEST AND TABULATION--------------------------------------------------------- |