September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1,40 @@
import Data.Monoid ((<>))
import Data.Array (Array, listArray, (!))
import Data.List (unfoldr, transpose, intercalate)
-- 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
((\col ->
let width = maximum (length <$> col)
justifyRight n c s = drop (length s) (replicate n c <> s)
in justifyRight width ' ' <$> col) <$>
transpose rows)
main :: IO ()
main =
mapM_
putStrLn
(table " " (([(show <$>), (const "----" <$>)] <*> [bases]) <> tableRows))