Data update
This commit is contained in:
parent
8e4e15fa56
commit
72eb4943cb
1853 changed files with 35514 additions and 9441 deletions
34
Task/Align-columns/Miranda/align-columns.miranda
Normal file
34
Task/Align-columns/Miranda/align-columns.miranda
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#! /usr/bin/mira -exec
|
||||
main :: [sys_message]
|
||||
main = [Stdout (align (alignment algm) '$' (read file))]
|
||||
where [cmd, file, algm] = $*
|
||||
|
||||
alignment :: [char]->num->[char]->[char]
|
||||
alignment "left" = ljustify
|
||||
alignment "center" = cjustify
|
||||
alignment "right" = rjustify
|
||||
alignment x = error "Alignment must be left, center, or right"
|
||||
|
||||
align :: (num->[char]->[char])->char->[char]->[char]
|
||||
align just sep text = (lay . map (alignline just sep cols) . lines) text
|
||||
where cols = colwidths sep text
|
||||
|
||||
split :: *->[*]->[[*]]
|
||||
split sep = s []
|
||||
where s acc [] = [acc]
|
||||
s acc (a:as) = acc:s [] as, if a==sep
|
||||
= s (acc++[a]) as, otherwise
|
||||
|
||||
colwidths :: char->[char]->[num]
|
||||
colwidths sep text = (map max . transpose . map (extend maxwidth 0)) widths
|
||||
where widths = map (map (#) . split sep) (lines text)
|
||||
maxwidth = max (map (#) widths)
|
||||
|
||||
alignline :: (num->[char]->[char])->char->[num]->[char]->[char]
|
||||
alignline just sep cols = concat . map (++" ") . zipwith just cols . split sep
|
||||
|
||||
zipwith :: (*->**->***)->[*]->[**]->[***]
|
||||
zipwith f xs ys = map f' (zip2 xs ys) where f' (x,y) = f x y
|
||||
|
||||
extend :: num->*->[*]->[*]
|
||||
extend n k ls = ls ++ take (n-#ls) (repeat k)
|
||||
Loading…
Add table
Add a link
Reference in a new issue