Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -0,0 +1,60 @@
|
|||
* 12*12 multiplication table 14/08/2015
|
||||
MULTTABL CSECT
|
||||
USING MULTTABL,R12
|
||||
LR R12,R15
|
||||
LA R10,0 buffer pointer
|
||||
LA R3,BUFFER
|
||||
MVC 0(4,R3),=C' | '
|
||||
LA R10,4(R10)
|
||||
LA R5,12
|
||||
LA R4,1 i=1
|
||||
LOOPN LA R3,BUFFER do i=1 to 12
|
||||
AR R3,R10
|
||||
XDECO R4,XDEC i
|
||||
MVC 0(4,R3),XDEC+8 output i
|
||||
LA R10,4(R10)
|
||||
LA R4,1(R4)
|
||||
BCT R5,LOOPN end i
|
||||
XPRNT BUFFER,52
|
||||
XPRNT PORT,52 border
|
||||
LA R5,12
|
||||
LA R4,1 i=1 (R4)
|
||||
LOOPI LA R10,0 do i=1 to 12
|
||||
MVC BUFFER,=CL52' '
|
||||
LA R3,BUFFER
|
||||
AR R3,R10
|
||||
XDECO R4,XDEC
|
||||
MVC 0(2,R3),XDEC+10
|
||||
LA R10,2(R10)
|
||||
LA R3,BUFFER
|
||||
AR R3,R10
|
||||
MVC 0(2,R3),=C'| '
|
||||
LA R10,2(R10)
|
||||
LA R7,12
|
||||
LA R6,1 j=1 (R6)
|
||||
LOOPJ CR R6,R4 do j=1 to 12
|
||||
BNL MULT
|
||||
LA R3,BUFFER
|
||||
AR R3,R10
|
||||
MVC 0(4,R3),=C' '
|
||||
LA R10,4(R10)
|
||||
B NEXTJ
|
||||
MULT LR R9,R4 i
|
||||
MR R8,R6 i*j in R8R9
|
||||
LA R3,BUFFER
|
||||
AR R3,R10
|
||||
XDECO R9,XDEC
|
||||
MVC 0(4,R3),XDEC+8
|
||||
LA R10,4(R10)
|
||||
NEXTJ LA R6,1(R6)
|
||||
BCT R7,LOOPJ end j
|
||||
ELOOPJ XPRNT BUFFER,52
|
||||
LA R4,1(R4)
|
||||
BCT R5,LOOPI end i
|
||||
ELOOPI XR R15,R15
|
||||
BR R14
|
||||
BUFFER DC CL52' '
|
||||
XDEC DS CL12
|
||||
PORT DC C'--+-------------------------------------------------'
|
||||
YREGS
|
||||
END MULTTABL
|
||||
14
Task/Multiplication-tables/ALGOL-W/multiplication-tables.alg
Normal file
14
Task/Multiplication-tables/ALGOL-W/multiplication-tables.alg
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
begin
|
||||
% print a school style multiplication table %
|
||||
i_w := 3; s_w := 0; % set output formating %
|
||||
write( " " );
|
||||
for i := 1 until 12 do writeon( " ", i );
|
||||
write( " +" );
|
||||
for i := 1 until 12 do writeon( "----" );
|
||||
for i := 1 until 12 do begin
|
||||
write( i, "|" );
|
||||
for j := 1 until i - 1 do writeon( " " );
|
||||
for j := i until 12 do writeon( " ", i * j );
|
||||
end;
|
||||
|
||||
end.
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
::The Main Thing...
|
||||
cls
|
||||
set colum=12&set row=12
|
||||
call :multable
|
||||
echo.
|
||||
pause
|
||||
exit /b 0
|
||||
::/The Main Thing.
|
||||
|
||||
::The Functions...
|
||||
:multable
|
||||
echo.
|
||||
for /l %%. in (1,1,%colum%) do (
|
||||
call :numstr %%.
|
||||
set firstline=!firstline!!space!%%.
|
||||
set seconline=!seconline!-----
|
||||
)
|
||||
echo !firstline!
|
||||
echo !seconline!
|
||||
|
||||
::The next lines here until the "goto :EOF" prints the products...
|
||||
|
||||
for /l %%X in (1,1,%row%) do (
|
||||
for /l %%Y in (1,1,%colum%) do (
|
||||
if %%Y lss %%X (set "line%%X=!line%%X! ") else (
|
||||
set /a ans=%%X*%%Y
|
||||
call :numstr !ans!
|
||||
set "line%%X=!line%%X!!space!!ans!"
|
||||
)
|
||||
)
|
||||
echo.!line%%X! ^| %%X
|
||||
)
|
||||
goto :EOF
|
||||
|
||||
:numstr
|
||||
::This function returns the number of whitespaces to be applied on each numbers.
|
||||
set cnt=0&set proc=%1&set space=
|
||||
:loop
|
||||
set currchar=!proc:~%cnt%,1!
|
||||
if not "!currchar!"=="" set /a cnt+=1&goto loop
|
||||
set /a numspaces=5-!cnt!
|
||||
for /l %%A in (1,1,%numspaces%) do set "space=!space! "
|
||||
goto :EOF
|
||||
::/The Functions.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
0>51p0>52p51g52g*:51g52g`!*\!51g52g+*+0\3>01p::55+%68*+\!28v
|
||||
w^p2<y|!`+66:+1,+*84*"\"!:g25$_,#!>#:<$$_^#!:-1g10/+55\-**<<
|
||||
"$9"^x>$55+,51g1+:66+`#@_055+68*\>\#<1#*-#9:#5_$"+---">:#,_$
|
||||
|
|
@ -3,39 +3,39 @@
|
|||
#include <cmath> // for log10()
|
||||
#include <algorithm> // for max()
|
||||
|
||||
size_t get_table_column_width(const int min, const int max)
|
||||
size_t table_column_width(const int min, const int max)
|
||||
{
|
||||
unsigned int abs_max = std::max(max*max, min*min);
|
||||
|
||||
// abs_max is the largest absolute value we might see.
|
||||
// If we take the log10 and add one, we get the string width
|
||||
// of the largest possible absolute value.
|
||||
// Add one for a little whitespace guarantee.
|
||||
size_t colwidth = 1 + std::log10(abs_max) + 1;
|
||||
// Add one more for a little whitespace guarantee.
|
||||
size_t colwidth = 2 + std::log10(abs_max);
|
||||
|
||||
// If only one of them is less than 0, then some will
|
||||
// be negative.
|
||||
bool has_negative_result = (min < 0) && (max > 0);
|
||||
|
||||
// If some values may be negative, then we need to add some space
|
||||
// be negative. If some values may be negative, then we need to add some space
|
||||
// for a sign indicator (-)
|
||||
if(has_negative_result)
|
||||
colwidth++;
|
||||
|
||||
if (min < 0 && max > 0)
|
||||
++colwidth;
|
||||
return colwidth;
|
||||
}
|
||||
|
||||
struct Writer_
|
||||
{
|
||||
decltype(std::setw(1)) fmt_;
|
||||
Writer_(size_t w) : fmt_(std::setw(w)) {}
|
||||
template<class T_> Writer_& operator()(const T_& info) { std::cout << fmt_ << info; return *this; }
|
||||
};
|
||||
|
||||
void print_table_header(const int min, const int max)
|
||||
{
|
||||
size_t colwidth = get_table_column_width(min, max);
|
||||
Writer_ write(table_column_width(min, max));
|
||||
|
||||
// table corner
|
||||
std::cout << std::setw(colwidth) << " ";
|
||||
|
||||
write(" ");
|
||||
for(int col = min; col <= max; ++col)
|
||||
{
|
||||
std::cout << std::setw(colwidth) << col;
|
||||
}
|
||||
write(col);
|
||||
|
||||
// End header with a newline and blank line.
|
||||
std::cout << std::endl << std::endl;
|
||||
|
|
@ -43,22 +43,18 @@ void print_table_header(const int min, const int max)
|
|||
|
||||
void print_table_row(const int num, const int min, const int max)
|
||||
{
|
||||
size_t colwidth = get_table_column_width(min, max);
|
||||
Writer_ write(table_column_width(min, max));
|
||||
|
||||
// Header column
|
||||
std::cout << std::setw(colwidth) << num;
|
||||
write(num);
|
||||
|
||||
// Spacing to ensure only the top half is printed
|
||||
for(int multiplicand = min; multiplicand < num; ++multiplicand)
|
||||
{
|
||||
std::cout << std::setw(colwidth) << " ";
|
||||
}
|
||||
write(" ");
|
||||
|
||||
// Remaining multiplicands for the row.
|
||||
for(int multiplicand = num; multiplicand <= max; ++multiplicand)
|
||||
{
|
||||
std::cout << std::setw(colwidth) << num * multiplicand;
|
||||
}
|
||||
write(num * multiplicand);
|
||||
|
||||
// End row with a newline and blank line.
|
||||
std::cout << std::endl << std::endl;
|
||||
|
|
@ -71,9 +67,7 @@ void print_table(const int min, const int max)
|
|||
|
||||
// Table body
|
||||
for(int row = min; row <= max; ++row)
|
||||
{
|
||||
print_table_row(row, min, max);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
|
|
|
|||
26
Task/Multiplication-tables/DCL/multiplication-tables.dcl
Normal file
26
Task/Multiplication-tables/DCL/multiplication-tables.dcl
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
$ max = 12
|
||||
$ h = f$fao( "!4* " )
|
||||
$ r = 0
|
||||
$ loop1:
|
||||
$ o = ""
|
||||
$ c = 0
|
||||
$ loop2:
|
||||
$ if r .eq. 0 then $ h = h + f$fao( "!4SL", c )
|
||||
$ p = r * c
|
||||
$ if c .ge. r
|
||||
$ then
|
||||
$ o = o + f$fao( "!4SL", p )
|
||||
$ else
|
||||
$ o = o + f$fao( "!4* " )
|
||||
$ endif
|
||||
$ c = c + 1
|
||||
$ if c .le. max then $ goto loop2
|
||||
$ if r .eq. 0
|
||||
$ then
|
||||
$ write sys$output h
|
||||
$ n = 4 * ( max + 2 )
|
||||
$ write sys$output f$fao( "!''n*-" )
|
||||
$ endif
|
||||
$ write sys$output f$fao( "!4SL", r ) + o
|
||||
$ r = r + 1
|
||||
$ if r .le. max then $ goto loop1
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
defmodule RC do
|
||||
def multiplication_tables(n) do
|
||||
IO.write " X |"
|
||||
Enum.each(1..n, fn i -> :io.fwrite("~4B", [i]) end)
|
||||
IO.puts "\n---+" <> String.duplicate("----", n)
|
||||
Enum.each(1..n, fn j ->
|
||||
:io.fwrite("~2B |", [j])
|
||||
Enum.each(1..n, fn i ->
|
||||
if i<j, do: (IO.write " "), else: :io.fwrite("~4B", [i*j])
|
||||
end)
|
||||
IO.puts ""
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
RC.multiplication_tables(12)
|
||||
11
Task/Multiplication-tables/Fortran/multiplication-tables-2.f
Normal file
11
Task/Multiplication-tables/Fortran/multiplication-tables-2.f
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
Cast forth a twelve times table, suitable for chanting at school.
|
||||
INTEGER I,J !Steppers.
|
||||
CHARACTER*52 ALINE !Scratchpad.
|
||||
WRITE(6,1) (I,I = 1,12) !Present the heading.
|
||||
1 FORMAT (" ×|",12I4,/," --+",12("----")) !Alas, can't do overprinting with underlines now.
|
||||
DO 3 I = 1,12 !Step down the lines.
|
||||
WRITE (ALINE,2) I,(I*J, J = 1,12) !Prepare one line.
|
||||
2 FORMAT (I3,"|",12I4) !Aligned with the heading.
|
||||
ALINE(5:1 + 4*I) = "" !Scrub the unwanted part.
|
||||
3 WRITE (6,"(A)") ALINE !Print the text.
|
||||
END !"One one is one! One two is two! One three is three!...
|
||||
10
Task/Multiplication-tables/Fortran/multiplication-tables-3.f
Normal file
10
Task/Multiplication-tables/Fortran/multiplication-tables-3.f
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
Cast forth a twelve times table, suitable for chanting at school.
|
||||
INTEGER I,J !Steppers.
|
||||
CHARACTER*16 FORMAT !Scratchpad.
|
||||
WRITE(6,1) (I,I = 1,12) !Present the heading.
|
||||
1 FORMAT (" ×|",12I4,/," --+",12("----")) !Alas, can't do overprinting with underlines now.
|
||||
DO 3 I = 1,12 !Step down the lines.
|
||||
WRITE (FORMAT,2) (I - 1)*4,13 - I !Spacing for omitted fields, count of wanted fields.
|
||||
2 FORMAT ("(I3,'|',",I0,"X,",I0,"I4)") !The format of the FORMAT statement.
|
||||
3 WRITE (6,FORMAT) I,(I*J, J = I,12) !Use it.
|
||||
END !"One one is one! One two is two! One three is three!...
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
(function (m, n) {
|
||||
|
||||
// [m..n]
|
||||
function range(m, n) {
|
||||
return Array.apply(null, Array(n - m + 1)).map(function (x, i) {
|
||||
return m + i;
|
||||
});
|
||||
}
|
||||
|
||||
// Monadic bind (chain) for lists
|
||||
function chain(xs, f) {
|
||||
return [].concat.apply([], xs.map(f));
|
||||
}
|
||||
|
||||
var lstRange = range(m, n),
|
||||
|
||||
lstTable = [['x'].concat(lstRange)].concat(
|
||||
chain(lstRange, function (y) {
|
||||
return [[y].concat(
|
||||
chain(lstRange, function (x) {
|
||||
return x < y ? [''] : [x * y]; // triangle only
|
||||
})
|
||||
)]
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
/* FORMATTING OUTPUT */
|
||||
|
||||
// [[a]] -> bool -> s -> s
|
||||
function wikiTable(lstRows, blnHeaderRow, strStyle) {
|
||||
return '{| class="wikitable" ' + (
|
||||
strStyle ? 'style="' + strStyle + '"' : ''
|
||||
) + lstRows.map(function (lstRow, iRow) {
|
||||
var strDelim = ((blnHeaderRow && !iRow) ? '!' : '|');
|
||||
|
||||
return '\n|-\n' + strDelim + ' ' + lstRow.map(function (v) {
|
||||
return typeof v === 'undefined' ? ' ' : v;
|
||||
}).join(' ' + strDelim + strDelim + ' ');
|
||||
}).join('') + '\n|}';
|
||||
}
|
||||
|
||||
// Formatted as WikiTable
|
||||
return wikiTable(
|
||||
lstTable, true,
|
||||
'text-align:center;width:33em;height:33em;table-layout:fixed;'
|
||||
) + '\n\n' +
|
||||
|
||||
// or simply stringified as JSON
|
||||
JSON.stringify(lstTable);
|
||||
|
||||
})(1, 12);
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
[["x",1,2,3,4,5,6,7,8,9,10,11,12],
|
||||
[1,1,2,3,4,5,6,7,8,9,10,11,12],
|
||||
[2,"",4,6,8,10,12,14,16,18,20,22,24],
|
||||
[3,"","",9,12,15,18,21,24,27,30,33,36],
|
||||
[4,"","","",16,20,24,28,32,36,40,44,48],
|
||||
[5,"","","","",25,30,35,40,45,50,55,60],
|
||||
[6,"","","","","",36,42,48,54,60,66,72],
|
||||
[7,"","","","","","",49,56,63,70,77,84],
|
||||
[8,"","","","","","","",64,72,80,88,96],
|
||||
[9,"","","","","","","","",81,90,99,108],
|
||||
[10,"","","","","","","","","",100,110,120],
|
||||
[11,"","","","","","","","","","",121,132],
|
||||
[12,"","","","","","","","","","","",144]]
|
||||
12
Task/Multiplication-tables/Julia/multiplication-tables.julia
Normal file
12
Task/Multiplication-tables/Julia/multiplication-tables.julia
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
println(" X | 1 2 3 4 5 6 7 8 9 10 11 12")
|
||||
println("---+------------------------------------------------")
|
||||
|
||||
for i=1:12, j=0:12
|
||||
if j == 0
|
||||
@printf("%2d | ", i)
|
||||
elseif i <= j
|
||||
@printf("%3d%c", i * j, j == 12 ? '\n' : ' ')
|
||||
else
|
||||
print(" ")
|
||||
end
|
||||
end
|
||||
|
|
@ -1,83 +1,60 @@
|
|||
/*REXX program displays a 12x12 multiplication boxed grid table, grid */
|
||||
/* will be displayed in "boxing" characters for ASCII or EBCDIC.*/
|
||||
parse arg high . /*get optional grid size from CL.*/
|
||||
if high=='' then high=12 /*not specified? Use default. */
|
||||
ebcdic= 'f0'==1 /*is this an EBCDIC machine? */
|
||||
/*REXX program displays a NxN multiplication table (in a boxed grid). */
|
||||
parse arg high . /*get optional grid size from the C.L. */
|
||||
if high=='' then high=12 /*Not specified? Then use the default.*/
|
||||
bar = '│' ; dash = '─' /*(vertical) bar; horizontal bar (dash)*/
|
||||
bj = '┴' ; tj = '┬' /*bottom and top junctions (or tees).*/
|
||||
cj = '┼' /*center junction (or cross). */
|
||||
lj = '├' ; rj = '┤' /*left and right junctions (or tees).*/
|
||||
tlc = '┌' ; trc = '┐' /* top left and right corners. */
|
||||
blc = '└' ; brc = '┘' /*bottom " " " " */
|
||||
/* [↑] define stuff to hold box glyphs*/
|
||||
cell = cj || copies(dash, 5) /*define the top of the cell. */
|
||||
sep = copies(cell, high+1)rj /*build the table separator. */
|
||||
sepL = length(sep) /*length of the separator line. */
|
||||
width= length(cell)-1 /*width of the table cells. */
|
||||
size = width-1 /*width for the table numbers. */
|
||||
box. = left('', width) /*construct all the cells. */
|
||||
|
||||
if ebcdic then do /*══════════EBCDIC═══════════════*/
|
||||
bar='fa'x /*vertical bar. */
|
||||
dash='bf'x /*horizontal dash. */
|
||||
bj ='cb'x /*bottom junction. */
|
||||
tj ='cc'x /* top junction. */
|
||||
cj ='8f'x /*center junction (cross). */
|
||||
lj ='eb'x /* left junction. */
|
||||
rj ='ec'x /* right junction. */
|
||||
tlc='ac'x /*top left corner. */
|
||||
trc='bc'x /*top right corner. */
|
||||
blc='ab'x /*bottom left corner. */
|
||||
brc='bb'x /*bottom right corner. */
|
||||
end
|
||||
else do /*══════════ASCII════════════════*/
|
||||
bar='b3'x /*vertical bar. */
|
||||
dash='c4'x /*horizontal dash. */
|
||||
bj ='c1'x /*bottom junction. */
|
||||
tj ='c2'x /* top junction. */
|
||||
cj ='c5'x /*center junction (cross). */
|
||||
lj ='c3'x /* left junction. */
|
||||
rj ='b4'x /* right junction. */
|
||||
tlc='da'x /*top left corner. */
|
||||
trc='bf'x /*top right corner. */
|
||||
blc='c0'x /*bottom left corner. */
|
||||
brc='d9'x /*bottom right corner. */
|
||||
end
|
||||
do j=0 to high /*step through zero ───► high. */
|
||||
_=right(j, size-1)'x ' /*build the "label" (border) number. */
|
||||
box.0.j=_ /*build the top label cell. */
|
||||
box.j.0=_ /*build the left label cell. */
|
||||
end /*j*/
|
||||
|
||||
cell=cj || copies(dash,5) /*define the top of the cell. */
|
||||
sep=copies(cell,high+1)rj /*build the table separator. */
|
||||
sepL=length(sep) /*length of separator line. */
|
||||
width=length(cell)-1 /*width of the table cells. */
|
||||
size=width-1 /*width for table numbers. */
|
||||
box.=left('',width) /*construct all the cells. */
|
||||
box.0.0=centre('times', width) /*redefine box.0.0 with 'X'. */
|
||||
|
||||
do j=0 to high /*step through zero to H (12). */
|
||||
_=right(j,size-1)'x ' /*build "label"/border number. */
|
||||
box.0.j=_ /*build top label cell. */
|
||||
box.j.0=_ /*build left label cell. */
|
||||
end /*j*/
|
||||
|
||||
box.0.0=centre('times',width) /*redefine box.0.0 with 'X'. */
|
||||
|
||||
do row=1 for high /*step through 1 to H (12). */
|
||||
do col=row to high /*step through row to H (12). */
|
||||
box.row.col=right(row*col,size)' ' /*build a mult. cell. */
|
||||
do row=1 for high /*step through one ───► high. */
|
||||
do col=row to high /*step through row ───► high. */
|
||||
box.row.col=right(row*col, size)' ' /*build a multiplication cell. */
|
||||
end /*col*/
|
||||
end /*row*/
|
||||
|
||||
do row=0 to high /*step through all the lines. */
|
||||
asep=sep /*allow use of a modified sep. */
|
||||
do row=0 to high /*step through all the lines. */
|
||||
asep=sep /*allow use of a modified separator. */
|
||||
if row==0 then do
|
||||
asep=overlay(tlc,asep,1) /*make a better tlc. */
|
||||
asep=overlay(trc,asep,sepL) /*make a better trc. */
|
||||
asep=translate(asep,tj,cj) /*make a better tj. */
|
||||
asep=overlay(tlc, asep, 1) /*make a better tlc. */
|
||||
asep=overlay(trc, asep, sepL) /*make a better trc. */
|
||||
asep=translate(asep, tj ,cj) /*make a better tj. */
|
||||
end
|
||||
else asep=overlay(lj,asep,1) /*make a better lj. */
|
||||
else asep=overlay(lj, asep ,1) /*make a better lj. */
|
||||
|
||||
say asep /*display a table grid line. */
|
||||
if row==0 then call buildLine 00 /*display a blank grid line. */
|
||||
call buildLine row /*build one line of the grid. */
|
||||
if row==0 then call buildLine 00 /*display a blank grid line. */
|
||||
say asep /*display a table grid line. */
|
||||
if row==0 then call buildLine 00 /*display a blank grid line. */
|
||||
call buildLine row /*build one line of the grid. */
|
||||
if row==0 then call buildLine 00 /*display a blank grid line. */
|
||||
end /*row*/
|
||||
|
||||
asep=sep /*allow use of a modified sep. */
|
||||
asep=overlay(blc,asep,1) /*make a better bot left corner.*/
|
||||
asep=overlay(brc,asep,sepL) /*make a better bot right corner.*/
|
||||
asep=translate(asep,bj,cj) /*make a better bot junction. */
|
||||
say asep /*display a table grid line. */
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────BUILDLINE subroutine────────────────*/
|
||||
buildLine: w=; parse arg arow /*start with a blank cell. */
|
||||
asep=sep /*allow use of a modified separator. */
|
||||
asep=overlay(blc, asep, 1) /*make a better bottom left corner. */
|
||||
asep=overlay(brc, asep, sepL) /*make a better bottom right corner. */
|
||||
asep=translate(asep, bj, cj) /*make a better bottom junction. */
|
||||
say asep /*display a table grid line. */
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*────────────────────────────────────────────────────────────────────────────*/
|
||||
buildLine: w=; parse arg arow /*start with a blank cell. */
|
||||
|
||||
do col=0 to high /*step through 0 to H (12). */
|
||||
w=w||bar||box.arow.col /*build one cell at a time. */
|
||||
do col=0 to high /*step through zero ───► high. */
|
||||
w=w||bar||box.arow.col /*build one cell at a time. */
|
||||
end /*col*/
|
||||
say w || bar /*finish building the last cell. */
|
||||
say w || bar /*finish building the last cell. */
|
||||
return
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
def multiplication_table(n)
|
||||
puts " " + ((" %3d" * n) % (1..n).to_a)
|
||||
puts " |" + (" %3d" * n) % [*1..n]
|
||||
puts "----+" + "----" * n
|
||||
1.upto(n) do |x|
|
||||
print "%3d " % x
|
||||
print "%3d |" % x
|
||||
1.upto(x-1) {|y| print " "}
|
||||
x.upto(n) {|y| print " %3d" % (x*y)}
|
||||
puts ""
|
||||
puts
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
nmax=12, xx=3
|
||||
s= blanks(xx)+" |"
|
||||
for j=1:nmax
|
||||
s=s+part(blanks(xx)+string(j),$-xx:$)
|
||||
end
|
||||
printf("%s\n",s)
|
||||
s=strncpy("-----",xx)+" +"
|
||||
for j=1:nmax
|
||||
s=s+" "+strncpy("-----",xx)
|
||||
end
|
||||
printf("%s\n",s)
|
||||
for i=1:nmax
|
||||
s=part(blanks(xx)+string(i),$-xx+1:$)+" |"
|
||||
for j = 1:nmax
|
||||
if j >= i then
|
||||
s=s+part(blanks(xx)+string(i*j),$-xx:$)
|
||||
else
|
||||
s=s+blanks(xx+1)
|
||||
end
|
||||
end
|
||||
printf("%s\n",s)
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue