Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
33
Task/Show-ASCII-table/Haskell/show-ascii-table.hs
Normal file
33
Task/Show-ASCII-table/Haskell/show-ascii-table.hs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import Data.Char (chr)
|
||||
import Data.List (transpose)
|
||||
import Data.List.Split (chunksOf)
|
||||
import Text.Printf (printf)
|
||||
|
||||
----------------------- ASCII TABLE ----------------------
|
||||
|
||||
asciiTable :: String
|
||||
asciiTable =
|
||||
unlines $
|
||||
(printf "%-12s" =<<)
|
||||
<$> transpose
|
||||
(chunksOf 16 $ asciiEntry <$> [32 .. 127])
|
||||
|
||||
asciiEntry :: Int -> String
|
||||
asciiEntry n
|
||||
| null k = k
|
||||
| otherwise = concat [printf "%3d" n, " : ", k]
|
||||
where
|
||||
k = asciiName n
|
||||
|
||||
asciiName :: Int -> String
|
||||
asciiName n
|
||||
| 32 > n = []
|
||||
| 127 < n = []
|
||||
| 32 == n = "Spc"
|
||||
| 127 == n = "Del"
|
||||
| otherwise = [chr n]
|
||||
|
||||
|
||||
--------------------------- TEST -------------------------
|
||||
main :: IO ()
|
||||
main = putStrLn asciiTable
|
||||
Loading…
Add table
Add a link
Reference in a new issue