Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -0,0 +1,33 @@
# procedure to print a Floyd's Triangle with n lines #
PROC floyds triangle = ( INT n )VOID:
BEGIN
# calculate the number of the highest number that will be printed #
# ( the sum of the integers 1, 2, ... n ) #
INT max number = ( n * ( n + 1 ) ) OVER 2;
# determine the widths required to print the numbers of the final row #
[ n ]INT widths;
INT number := max number + 1;
FOR col FROM n BY -1 TO 1 DO
widths[ col ] := - ( UPB whole( number -:= 1, 0 ) + 1 )
OD;
# print the triangle #
INT element := 0;
FOR row TO n DO
FOR col TO row DO
print( ( whole( element +:= 1, widths[ col ] ) ) )
OD;
print( ( newline ) )
OD
END; # floyds triangle #
main: (
floyds triangle( 5 );
print( ( newline ) );
floyds triangle( 14 )
)

View file

@ -0,0 +1,46 @@
using System;
using System.Text;
public class FloydsTriangle
{
internal static void Main(string[] args)
{
int count;
if (args.Length >= 1 && int.TryParse(args[0], out count) && count > 0)
{
Console.WriteLine(MakeTriangle(count));
}
else
{
Console.WriteLine(MakeTriangle(5));
Console.WriteLine();
Console.WriteLine(MakeTriangle(14));
}
}
public static string MakeTriangle(int rows)
{
int maxValue = (rows * (rows + 1)) / 2;
int digit = 0;
StringBuilder output = new StringBuilder();
for (int row = 1; row <= rows; row++)
{
for (int column = 0; column < row; column++)
{
int colMaxDigit = (maxValue - rows) + column + 1;
if (column > 0)
{
output.Append(' ');
}
digit++;
output.Append(digit.ToString().PadLeft(colMaxDigit.ToString().Length));
}
output.AppendLine();
}
return output.ToString();
}
}

View file

@ -1,3 +1,3 @@
def floyd(rowcount=5):
return [list(range(i*(i-1)//2+1, i*(i+1)//2+1))
for i in range(1, rowcount+1)]
return [list(range(i*(i-1)//2+1, i*(i+1)//2+1))
for i in range(1, rowcount+1)]

View file

@ -1,11 +1,11 @@
/*REXX pgm constructs & displays Floyd's triangle for any number of rows*/
parse arg rows .; if rows=='' then rows=5 /*use 5 rows if not given. */
mV = rows * (rows+1) % 2 /*calculate the max value. */
say 'displaying a' rows "row Floyd's triangle:"; say
#=1; do r=1 for rows; i=0; _=''
do #=# for r; i=i+1
_ = _ right(#, length(mV-rows+i))
end /*#*/
say substr(_,2) /*suppress a leading blank.*/
end /*r*/
parse arg rows .; if rows=='' then rows=5 /*Not specified? Use default*/
maxV = rows * (rows+1) % 2 /*calculate the max value. */
say 'displaying a' rows "row Floyd's triangle:"; say /*show header*/
#=1; do r=1 for rows; i=0; _= /*row by row.*/
do #=# for r; i=i+1 /*start a row*/
_ = _ right(#, length(maxV-rows+i)) /*build a row*/
end /*#*/ /*row is done*/
say substr(_,2) /*suppress the 1st leading blank,*/
end /*r*/ /* [↑] introduced by 1st abutt.*/
/*stick a fork in it, we're done.*/

View file

@ -1,11 +1,11 @@
/*REXX pgm displays Floyd's triangle for any number of rows in base 16.*/
parse arg rows .; if rows=='' then rows=6 /*use 6 rows if not given. */
mV = rows * (rows+1) % 2 /*calculate the max value. */
say 'displaying a' rows "row Floyd's triangle in base 16:"; say
#=1; do r=1 for rows; i=0; _=''
do #=# for r; i=i+1
_ = _ right(d2x(#), length(d2x(mV-rows+i)))
end /*#*/
say substr(_,2) /*suppress a leading blank.*/
end /*r*/
parse arg rows .; if rows=='' then rows=6 /*Not specified? Use default*/
maxV = rows * (rows+1) % 2 /*calculate the max value. */
say 'displaying a' rows "row Floyd's triangle in base 16:"; say /*hdr*/
#=1; do r=1 for rows; i=0; _= /*row by row.*/
do #=# for r; i=i+1 /*start a row*/
_ = _ right(d2x(#), length(d2x(maxV - rows + i)))
end /*#*/ /* [↑] the triangle row is done.*/
say substr(_,2) /*suppress the 1st leading blank,*/
end /*r*/ /* [↑] introduced by 1st abutt.*/
/*stick a fork in it, we're done.*/

View file

@ -1,23 +1,23 @@
/*REXX pgm displays Floyd's triangle for any # of rows up to base 90.*/
parse arg rows b .; if rows=='' then rows=5 /*use 5 rows if not given. */
if b=='' then b=10 /*use base 10 if not given.*/
mV = rows * (rows+1) % 2 /*calculate the max value. */
say 'displaying a' rows "row Floyd's triangle in base" b':'; say
#=1; do r=1 for rows; i=0; _=''
do #=# for r; i=i+1
_ = _ right(base(#, b), length(base(mV-rows+i, b)))
end /*#*/
say substr(_,2) /*suppress a leading blank.*/
end /*r*/
parse arg rows b .; if rows=='' then rows=5 /*Not given? Use default.*/
if b=='' then b=10 /*use base 10 if not given.*/
maxV = rows * (rows+1) % 2 /*calculate the max value. */
say 'displaying a' rows "row Floyd's triangle in base" b':'; say
#=1; do r=1 for rows; i=0; _= /*row by row.*/
do #=# for r; i=i+1 /*start a row*/
_ = _ right(base(#, b), length(base(maxV-rows+i, b)))
end /*#*/ /*row is done*/
say substr(_,2) /*suppress the 1st leading blank,*/
end /*r*/ /* [↑] introduced by 1st abutt.*/
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────BASE subroutine─────────────────────*/
base: procedure; parse arg x 1 ox,toB,inB /*get a number, toBase, inBase*/
base: procedure; parse arg x 1 ox,toB,inB /*get number, toBase, inBase*/
@abc='abcdefghijklmnopqrstuvwxyz' /*lowercase Latin alphabet. */
@abcU=@abc; upper @abcU /*go whole hog and extend 'em. */
@@@='0123456789'@abc || @abcU /*prefix 'em with numeric digits.*/
@@@=@@@'<>[]{}()?~!@#$%^&*_=|\/;:¢¬' /*add some special chars as well.*/
/*handles up to base 90 special chars must be viewable.*/
numeric digits 1000 /*what the hey, support gihugics.*/
/*handles up to base 90, special chars must be viewable.*/
numeric digits 1000 /*what the hey, support gihugeics*/
maxB=length(@@@) /*max base (radix) supported here*/
if toB=='' | toB==',' then toB=10 /*if skipped, assume default (10)*/
if inB=='' | inB==',' then inB=10 /* " " " " " */
@ -27,16 +27,16 @@ if x=='' then call erm /* " " number.*/
sigX=left(x,1); if pos(sigX,"-+")\==0 then x=substr(x,2) /*X has sign?*/
else sigX= /*no sign. */
#=0; do j=1 for length(x) /*convert X, base inB ──► base 10*/
_=substr(x, j, 1) /*pick off a "digit" from X. */
_=substr(x, j, 1) /*pick off a numeral from X. */
v=pos(_, @@@) /*get the value of this "digit". */
if v==0 | v>inB then call erd x,j,inB /*illegal "digit"? */
#=#*inB+v-1 /*construct new num, dig by dig. */
end /*j*/
y=; do while #>=toB /*convert #, base 10 ──► base toB*/
y=substr(@@@, (#//toB)+1, 1)y /*construct the output number. */
#=#%toB /*... and whittle # down also. */
end /*while #≥toB*/
end /*j*/
y=
do while #>=toB /*convert #, base 10 ──► base toB*/
y=substr(@@@, (#//toB)+1, 1)y /*construct the number for output*/
#=#%toB /*··· and whittle # down also. */
end /*while #≥toB*/
y=sigX || substr(@@@, #+1, 1)y /*prepend the sign if it existed.*/
return y /*rturn the number in base toB. */

View file

@ -1,8 +1,9 @@
input " Number of rows:"; rows
html "<table>"
for r = 1 to rows ' r = rows
html "<TR align=right>"
for c = 1 to r ' c = columns
j = j + 1
print using("#####",j);" ";
next c
print
html "<TD> ";j;"</TD>"
next c
next r