#! perl -w
#
# Multiplication (or addition) tables in various bases
#
# Copyright 2016 Ken Takusagawa
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

$operator='*';
sub multiply {
    my($base,$a,$b)=@_;
    my$answer= `echo "obase=$base;$a$operator$b"|bc`;
    chomp$answer;
    $answer
}
for(0..9,'A'..'Z'){
    push @convert,$_;
}
$start=2;
$html_op=qq(<th style="text-align:center">$operator</th>);
for$base(2..16){
    print qq(<p>Base $base<br/><table border="1" style="text-align:right">);
    print qq(<tr>$html_op);
    for$i($start..$base-1){
	print "<th>$convert[$i]</th>";
    }
    print "$html_op</tr>\n";
    for$i($start..$base-1){
	print "<tr><th>$convert[$i]</th>";
	for$j($start..$base-1){
	    #print"$base $i $j ",&multiply($base,$i,$j),"\n";
	    print "<td>",&multiply($base,$i,$j),"</td>";
	}
	print "<th>$convert[$i]</th></tr>\n";
    }
    print qq(<tr><th style="text-align:center">$operator</th>);
    for$i($start..$base-1){
	print "<th>$convert[$i]</th>";
    }
    print "$html_op</tr>\n";
    print "</table></p>"
}
print "\n";
