Floyd's triangle: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add Refal) |
Not a robot (talk | contribs) (Add Miranda) |
||
Line 4,760: | Line 4,760: | ||
[[File:FloydTriangleMaxima14.png|thumb|center]] |
[[File:FloydTriangleMaxima14.png|thumb|center]] |
||
=={{header|Miranda}}== |
|||
<Syntaxhighlight lang="miranda">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</syntaxhighlight> |
|||
{{out}} |
|||
<pre> 1 |
|||
2 3 |
|||
4 5 6 |
|||
7 8 9 10 |
|||
11 12 13 14 15 |
|||
1 |
|||
2 3 |
|||
4 5 6 |
|||
7 8 9 10 |
|||
11 12 13 14 15 |
|||
16 17 18 19 20 21 |
|||
22 23 24 25 26 27 28 |
|||
29 30 31 32 33 34 35 36 |
|||
37 38 39 40 41 42 43 44 45 |
|||
46 47 48 49 50 51 52 53 54 55 |
|||
56 57 58 59 60 61 62 63 64 65 66 |
|||
67 68 69 70 71 72 73 74 75 76 77 78 |
|||
79 80 81 82 83 84 85 86 87 88 89 90 91 |
|||
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|||
</pre> |
|||
=={{header|Modula-2}}== |
=={{header|Modula-2}}== |
||
<syntaxhighlight lang="modula2">MODULE FloydTriangle; |
<syntaxhighlight lang="modula2">MODULE FloydTriangle; |