Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,6 @@
import Text.Printf
main :: IO ()
main = mapM_ f [0..33] where
f :: Int -> IO ()
f n = printf " %3o %2d %2X\n" n n n -- binary not supported

View file

@ -0,0 +1,6 @@
import Numeric
main :: IO ()
main = mapM_ f [0..33] where
f :: Int -> IO ()
f n = putStrLn $ " " ++ showOct n "" ++ " " ++ show n ++ " " ++ showHex n ""

View file

@ -0,0 +1,40 @@
import Data.List (unfoldr, transpose, intercalate)
import Data.Array (Array, listArray, (!))
import Data.Monoid ((<>))
-- ARBITRARY RADICES ---------------------------------------
bases :: [Int]
bases = abs <$> [2, 7, 8, 10, 12, 16, 32]
tableRows :: [[String]]
tableRows = ((([baseDigits] <*> bases) <*>) . return) <$> [1 .. 33]
digits :: Array Int Char
digits = listArray (0, 35) (['0' .. '9'] <> ['A' .. 'Z'])
baseDigits :: Int -> Int -> String
baseDigits base
| base > 36 = const "Needs glyphs beyond Z"
| otherwise = reverse . unfoldr remQuot
where
remQuot 0 = Nothing
remQuot n =
let (q, r) = quotRem n base
in Just (digits ! r, q)
-- TEST AND TABULATION-------------------------------------
table :: String -> [[String]] -> [String]
table delim rows =
intercalate delim <$>
transpose
((fmap =<< flip justifyRight ' ' . maximum . fmap length) <$> transpose rows)
justifyRight :: Int -> Char -> String -> String
justifyRight n c s = drop (length s) (replicate n c <> s)
main :: IO ()
main =
mapM_
putStrLn
(table " " (([fmap show, fmap $ const "----"] <*> [bases]) <> tableRows))