Data update
This commit is contained in:
parent
0df55f9f24
commit
aec8ed51b6
1045 changed files with 18889 additions and 2777 deletions
27
Task/Floyds-triangle/Miranda/floyds-triangle.miranda
Normal file
27
Task/Floyds-triangle/Miranda/floyds-triangle.miranda
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
main :: [sys_message]
|
||||
main = [Stdout (lay (map floyd [5, 14]))]
|
||||
|
||||
floyd :: num->[char]
|
||||
floyd n = lay (map fmt rws)
|
||||
where rws = rows n
|
||||
cws = map ((+1).width) (last rws)
|
||||
fmt rw = concat (map (uncurry rjust) (zip2 cws rw))
|
||||
|
||||
|
||||
rows :: num->[[num]]
|
||||
rows n = rows' [1..n] [1..]
|
||||
where rows' [] ns = []
|
||||
rows' (l:ls) ns = row : rows' ls rest
|
||||
where (row, rest) = split l ns
|
||||
|
||||
split :: num->[*]->([*],[*])
|
||||
split n ls = (take n ls, drop n ls)
|
||||
|
||||
rjust :: num->num->[char]
|
||||
rjust w n = reverse (take w (reverse (show n) ++ repeat ' '))
|
||||
|
||||
width :: num->num
|
||||
width = (#) . show
|
||||
|
||||
uncurry :: (*->**->***)->(*,**)->***
|
||||
uncurry f (a,b) = f a b
|
||||
Loading…
Add table
Add a link
Reference in a new issue