June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -0,0 +1,39 @@
* Floyd's triangle 21/06/2018
FLOYDTRI PROLOG
L R5,NN nn
BCTR R5,0 -1
M R4,NN nn*(nn-1)
SRA R5,1 /2
A R5,NN m=(nn*(nn-1))/2+nn; max_value
CVD R5,XDEC binary to packed decimal (PL8)
EDMK ZN,XDEC+4 packed dec (PL4) to char (CL8)
S R1,=A(ZN) r1=number of spaces
L R9,=A(L'ZN+1) length(zn08)+1
SR R9,R1 s=length(m)+1
SR R8,R8 k=0
LA R6,1 i=1
DO WHILE=(C,R6,LE,NN) do i=1 to nn
LA R10,PG pgi=0
LA R7,1 j=1
DO WHILE=(CR,R7,LE,R6) do j=1 to i
LA R8,1(R8) k=k+1
XDECO R8,XDEC k
LA R11,XDEC+12 +12
SR R11,R9 -s
LR R2,R9 s
BCTR R2,0 -1
EX R2,MVCX mvc @PG+pgi,@XDEC+12-s,LEN=s
AR R10,R9 pgi+=s
LA R7,1(R7) j++
ENDDO , enddo j
XPRNT PG,L'PG print buffer
LA R6,1(R6) i++
ENDDO , enddo i
EPILOG
MVCX MVC 0(0,R10),0(R11) mvc PG,XDEC
NN DC F'14' number of rows
PG DC CL80' ' buffer
XDEC DS CL12 temp
ZN DC X'4020202020202020' mask CL8 7num
YREGS
END FLOYDTRI

View file

@ -0,0 +1,11 @@
100 :
110 REM FLOYD'S TRIANGLE
120 :
130 DEF FN Q(A) = INT ( LOG (A) / LOG (10)) + 1
140 N = 14
150 DIM P(N): P(0) = - 1: FOR J = 1 TO N: I = (N * N - N) / 2 + J
160 P(J) = P(J - 1) + FN Q(I) + 1: NEXT J
200 FOR R = 1 TO N: FOR C = 1 TO R
210 NR = NR + 1:COL = P(C) - ( FN Q(NR) - 1)
220 HTAB COL: PRINT NR;: NEXT C
230 PRINT : NEXT R

View file

@ -0,0 +1,12 @@
n = 14
num = 1
last = (n^2 - n + 2) DIV 2
FOR row = 1 TO n
col = last
FOR num = num TO num + row - 1
@% = LEN(STR$(col)) + 1 : REM set column width
PRINT num ;
col += 1
NEXT
PRINT
NEXT row

View file

@ -1,3 +1,5 @@
0" :swor fo rebmuN">:#,_&>55v
>1+\1-:#v_$$1+\1- 55+,:v>$$@+
^,*84.:\<+1\+1/2*+1:::\_^#:,<
0" :seniL">:#,_&>:!#@_55+,:00p::1+*2/1v
vv+1:\-1p01g5-\g00<v`*9"o"\+`"c"\`9:::_
$>>\:::9`\"c"`+\9v:>>+00g1-:00p5p1-00g^
<v\*84-\g01+`*"o"<^<<p00:+1\+1/2*+1:::\
^>:#\1#,-#:\_$$.\:#^_$$>>1+\1-55+,:!#@_

View file

@ -0,0 +1,37 @@
MODULE FloydTriangle;
FROM FormatString IMPORT FormatString;
FROM Terminal IMPORT WriteString,WriteLn,ReadChar;
PROCEDURE WriteInt(n : INTEGER);
VAR buf : ARRAY[0..9] OF CHAR;
BEGIN
FormatString("%4i", buf, n);
WriteString(buf)
END WriteInt;
PROCEDURE Print(r : INTEGER);
VAR n,i,limit : INTEGER;
BEGIN
IF r<0 THEN RETURN END;
n := 1;
limit := 1;
WHILE r#0 DO
FOR i:=1 TO limit DO
WriteInt(n);
INC(n)
END;
WriteLn;
DEC(r);
INC(limit)
END
END Print;
BEGIN
Print(5);
WriteLn;
Print(14);
ReadChar
END FloydTriangle.

View file

@ -1 +1,14 @@
constant @floyd = gather for 1..* -> $s { take [++$ xx $s] }
# Printing:
sub say-floyd($n) {
my @formats = @floyd[$n-1].map: {"%{.chars}s"}
for @floyd[^$n] -> @i {
say ~(@i Z @formats).map: -> ($i, $f) { $i.fmt($f) }
}
}
say-floyd 5;
say-floyd 14;

View file

@ -3,9 +3,9 @@ parse arg N .; if N=='' | N=="," then N=5 /*Not specified? Then use the
mx=N * (N+1) % 2 - N /*calculate maximum value of any value.*/
say 'displaying a ' N " row Floyd's triangle:" /*show the header for Floyd's triangle.*/
say
#=1; do r=1 for N; i=0; _= /*construct Floyd's triangle row by row*/
do #=# for r; i=i+1 /*start to construct a row of triangle.*/
_=_ right(#, length( mx+i ) ) /*build a row of the Floyd's triangle. */
#=1; do r=1 for N; i=0; _= /*construct Floyd's triangle row by row*/
do #=# for r; i=i+1 /*start to construct a row of triangle.*/
_=_ right(#, length( mx+i ) ) /*build a row of the Floyd's triangle. */
end /*#*/
say substr(_, 2) /*remove 1st leading blank in the line.*/
end /*r*/ /*stick a fork in it, we're all done. */

View file

@ -3,8 +3,8 @@ parse arg N .; if N=='' | N=="," then N=6 /*Not specified? Then use the
mx=N * (N+1) % 2 - N /*calculate maximum value of any value.*/
say 'displaying a ' N " row Floyd's triangle in base 16:" /*show triangle header.*/
say
#=1; do r=1 for N; i=0; _= /*construct Floyd's triangle row by row*/
do #=# for r; i=i+1 /*start to construct a row of triangle.*/
#=1; do r=1 for N; i=0; _= /*construct Floyd's triangle row by row*/
do #=# for r; i=i+1 /*start to construct a row of triangle.*/
_=_ right( d2x(#), length( d2x(mx+i))) /*build a row of the Floyd's triangle. */
end /*#*/
say substr(_, 2) /*remove 1st leading blank in the line.*/

View file

@ -5,12 +5,12 @@ if radx=='' | radx=="," then radx=10 /* " " " " "
mx=N * (N+1) % 2 - N /*calculate maximum value of any value.*/
say 'displaying a ' N " row Floyd's triangle in base" radx':' /*display the header.*/
say
#=1; do r=1 for N; i=0; _= /*construct Floyd's triangle row by row*/
do #=# for r; i=i+1 /*start to construct a row of triangle.*/
#=1; do r=1 for N; i=0; _= /*construct Floyd's triangle row by row*/
do #=# for r; i=i+1 /*start to construct a row of triangle.*/
_=_ right(base(#, radx), length( base(mx+i, radx) ) ) /*build triangle row.*/
end /*#*/
say substr(_, 2) /*remove 1st leading blank in the line,*/
end /*r*/ /* [↑] introduced by first abutment. */
say substr(_, 2) /*remove 1st leading blank in the line,*/
end /*r*/ /* [↑] introduced by first abutment. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
base: procedure; parse arg x 1 ox,toB,inB /*obtain number, toBase, inBase. */