September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -0,0 +1,30 @@
|
|||
import Data.Maybe (fromMaybe, maybe)
|
||||
import Data.Bool (bool)
|
||||
|
||||
table :: [Int] -> [[Maybe Int]]
|
||||
table xs =
|
||||
let axis = Just <$> xs
|
||||
in (Nothing : axis) :
|
||||
zipWith
|
||||
(:)
|
||||
axis
|
||||
[ [ bool (Just (x * y)) Nothing (x > y)
|
||||
| y <- xs ]
|
||||
| x <- xs ]
|
||||
|
||||
-- TEST ---------------------------------------------------
|
||||
main :: IO ()
|
||||
main =
|
||||
(putStrLn . unlines) $
|
||||
(showTable . table) <$> [[13 .. 20], [1 .. 12], [95 .. 100]]
|
||||
|
||||
-- FORMATTING ---------------------------------------------
|
||||
showTable :: [[Maybe Int]] -> String
|
||||
showTable xs =
|
||||
let w = 1 + (length . show) (fromMaybe 0 $ (last . last) xs)
|
||||
gap = replicate w ' '
|
||||
rows = (maybe gap (rjust w ' ' . show) =<<) <$> xs
|
||||
in unlines $ head rows : [] : tail rows
|
||||
|
||||
rjust :: Int -> Char -> String -> String
|
||||
rjust n c = (drop . length) <*> (replicate n c ++)
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
import Data.List (groupBy)
|
||||
import Data.Function (on)
|
||||
import Control.Monad (join)
|
||||
|
||||
main :: IO ()
|
||||
main =
|
||||
mapM_ print $
|
||||
fmap (uncurry (*)) <$>
|
||||
groupBy
|
||||
(on (==) fst)
|
||||
(filter (uncurry (>=)) $ join ((<*>) . fmap (,)) [1 .. 12])
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
import Data.Monoid ((<>))
|
||||
import Data.List (intercalate, transpose)
|
||||
|
||||
multTable :: Int -> [[String]]
|
||||
multTable n =
|
||||
let xs = [1 .. n]
|
||||
in xs >>=
|
||||
\x ->
|
||||
[ show x <> ":" :
|
||||
(xs >>=
|
||||
\y ->
|
||||
[ if y < x
|
||||
then mempty
|
||||
else show (x * y)
|
||||
])
|
||||
]
|
||||
|
||||
table :: String -> [[String]] -> [String]
|
||||
table delim rows =
|
||||
let justifyRight c n s = drop (length s) (replicate n c <> s)
|
||||
in intercalate delim <$>
|
||||
transpose
|
||||
((fmap =<< justifyRight ' ' . maximum . fmap length) <$> transpose rows)
|
||||
|
||||
main :: IO ()
|
||||
main = (putStrLn . unlines . table " " . multTable) 12
|
||||
Loading…
Add table
Add a link
Reference in a new issue