Floyd's triangle: Difference between revisions

Added XBasic
(Add PL/M)
(Added XBasic)
 
(6 intermediate revisions by 2 users not shown)
Line 463:
92 93 94 95 96 97 98 99 100 101 102 103 104 105
</pre>
 
=={{header|APL}}==
{{works with|Dyalog APL}}
<syntaxhighlight lang="apl">floyd←{
max←⍵×(⍵+1)÷2
tri←↑(⍳max)⊂⍨(0,⍳max-1)∊+\0,⍳⍵
wdt←⌈⍀⊖≢∘⍕¨tri
↑,/wdt{' ',(-⍺××⍵)↑⍕⍵}¨tri
}</syntaxhighlight>
{{out}}
<syntaxhighlight lang="apl"> floyd 5
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
floyd 14
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</syntaxhighlight>
 
=={{header|AppleScript}}==
Line 1,738 ⟶ 1,769:
PRINT
FloydTriangle (14)</syntaxhighlight>
 
==={{header|True BASIC}}===
{{trans|QBasic}}
<syntaxhighlight lang="qbasic">SUB floydtriangle (fila)
DIM numcolum(0)
MAT REDIM numcolum(fila)
FOR colum = 1 TO fila
LET numcolum(colum) = LEN(STR$(colum+fila*(fila-1)/2))
NEXT colum
PRINT "output for "; STR$(fila)
PRINT
LET thisnum = 1
FOR r = 1 TO fila
FOR colum = 1 TO r
PRINT (" " & STR$(thisnum))[LEN(" " & STR$(thisnum))-numcolum(colum)+1:maxnum]; " ";
LET thisnum = thisnum+1
NEXT colum
PRINT
NEXT r
END SUB
 
CALL FLOYDTRIANGLE (5)
PRINT
CALL FLOYDTRIANGLE (14)
END</syntaxhighlight>
 
==={{header|XBasic}}===
{{works with|Windows XBasic}}
<syntaxhighlight lang="qbasic">PROGRAM "Floyd's triangle"
VERSION "0.0001"
 
DECLARE FUNCTION Entry ()
DECLARE FUNCTION FloydTriangle (n)
 
FUNCTION Entry ()
FloydTriangle (5)
PRINT
FloydTriangle (14)
END FUNCTION
 
FUNCTION FloydTriangle (fila)
DIM numColum[fila]
FOR colum = 1 TO fila
t$ = STR$(colum + fila * (fila - 1) / 2)
numColum[colum] = LEN(t$)
NEXT colum
 
PRINT "output for "; STR$(fila)
PRINT
thisNum = 1
FOR r = 1 TO fila
FOR colum = 1 TO r
PRINT RIGHT$(" " + STR$(thisNum), numColum[colum]); " ";
INC thisNum
NEXT colum
PRINT
NEXT r
END FUNCTION
END PROGRAM</syntaxhighlight>
 
==={{header|Yabasic}}===
Line 2,634 ⟶ 2,724:
</pre>
 
 
=={{header|Draco}}==
<syntaxhighlight lang="draco">proc width(word n) word:
word w;
w := 0;
while n>0 do
w := w + 1;
n := n / 10
od;
w
corp
 
proc floyd(word rows) void:
word n, row, col, maxno;
maxno := rows * (rows+1)/2;
n := 1;
for row from 1 upto rows do
for col from 1 upto row do
write(n : 1+width(maxno - rows + col));
n := n+1
od;
writeln()
od
corp
 
proc main() void:
floyd(5);
writeln();
floyd(14)
corp</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|EasyLang}}==
Line 4,678 ⟶ 4,819:
[[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}}==
<syntaxhighlight lang="modula2">MODULE FloydTriangle;
Line 6,015 ⟶ 6,206:
92 93 94 95 96 97 98 99 100 101 102 103 104 105</pre>
 
=={{header|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
= <Prout <Floyd 5>>
<Prout <Floyd 14>>;
};
 
Floyd {
s.N, <Rows s.N>: e.Rows,
e.Rows: e.X (e.MaxRow),
<Each Width e.MaxRow>: e.ColWidths =
<Each ((e.ColWidths)) FormatRow e.Rows>;
}
 
FormatRow {
(e.W) () = '\n';
(s.W e.WS) (s.C e.CS) = <Cell <+ 1 s.W> s.C> <FormatRow (e.WS) (e.CS)>;
};
 
Cell {
s.Width s.N, <Repeat s.Width ' '> <Symb s.N>: e.Rfill,
<Last s.Width e.Rfill>: (e.X) e.Cell = e.Cell;
}
 
Rows {
s.Rows = <Rows s.Rows 1 1>;
s.Rows s.Row s.N, <+ s.Rows 1>: s.Row = ;
s.Rows s.Row s.N, <+ s.N s.Row>: s.Next =
(<Row s.N <- s.Next 1>>)
<Rows s.Rows <+ s.Row 1> s.Next>;
}
 
Row {
s.To s.To = s.To;
s.From s.To = s.From <Row <+ s.From 1> s.To>;
};
 
Each {
s.F e.X = <Each () s.F e.X>;
(e.Arg) s.F = ;
(e.Arg) s.F t.I e.X = <Mu s.F e.Arg t.I> <Each (e.Arg) s.F e.X>;
};
 
Width {
s.N, <Symb s.N>: e.X, <Lenw e.X>: s.Width e.X = s.Width;
};
 
Repeat {
0 s.X = ;
s.N s.X = s.X <Repeat <- s.N 1> s.X>;
};</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|REXX}}==
===version 1===
Line 6,561 ⟶ 6,823:
92 93 94 95 96 97 98 99 100 101 102 103 104 105
</pre>
 
=={{header|SETL}}==
<syntaxhighlight lang="setl">program floyd_triangle;
floyd(5);
print;
floyd(14);
print;
 
proc floyd(rows);
maxno := rows * (rows+1) div 2;
n := 1;
loop for row in [1..rows] do
loop for col in [1..row] do
nprint(lpad(str n, 1 + #str (maxno - rows + col)));
n +:=1;
end loop;
print;
end loop;
end proc;
end program;
</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|Sidef}}==
2,122

edits