Show ASCII table: Difference between revisions
Content added Content deleted
(Add QB64) |
m (→{{header|Haskell}}: Tidied) |
||
Line 2,455: | Line 2,455: | ||
import Data.List (transpose) |
import Data.List (transpose) |
||
import Data.List.Split (chunksOf) |
import Data.List.Split (chunksOf) |
||
import Text.Printf (printf) |
|||
----------------------- ASCII TABLE ---------------------- |
|||
⚫ | |||
⚫ | |||
asciiTable :: String |
asciiTable :: String |
||
asciiTable = |
asciiTable = |
||
unlines $ |
unlines $ |
||
( |
(printf "%-12s" =<<) |
||
<$> transpose |
<$> transpose |
||
(chunksOf 16 $ asciiEntry <$> [32 .. 127]) |
(chunksOf 16 $ asciiEntry <$> [32 .. 127]) |
||
Line 2,469: | Line 2,469: | ||
asciiEntry n |
asciiEntry n |
||
| null k = k |
| null k = k |
||
| otherwise = |
| otherwise = concat [printf "%3d" n, " : ", k] |
||
concat |
|||
[justifyRight 4 ' ' (show n), " : ", k] |
|||
where |
where |
||
k = asciiName n |
k = asciiName n |
||
Line 2,483: | Line 2,481: | ||
| otherwise = [chr n] |
| otherwise = [chr n] |
||
justifyLeft, justifyRight :: Int -> Char -> String -> String |
|||
--------------------------- TEST ------------------------- |
|||
justifyLeft n c s = take n (s <> replicate n c) |
|||
⚫ | |||
justifyRight n c = (drop . length) <*> (replicate n c <>)</lang> |
|||
⚫ | |||
</lang> |
|||
{{Out}} |
{{Out}} |
||
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p |
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p |