diff options
| -rw-r--r-- | challenge-140/cheok-yin-fung/befunge-93/ch-2.bf | 24 | ||||
| -rw-r--r-- | challenge-140/cheok-yin-fung/javascript/ch-2.js | 60 | ||||
| -rw-r--r-- | challenge-140/cheok-yin-fung/perl/ch-2.pl | 35 |
3 files changed, 119 insertions, 0 deletions
diff --git a/challenge-140/cheok-yin-fung/befunge-93/ch-2.bf b/challenge-140/cheok-yin-fung/befunge-93/ch-2.bf new file mode 100644 index 0000000000..1b1038980f --- /dev/null +++ b/challenge-140/cheok-yin-fung/befunge-93/ch-2.bf @@ -0,0 +1,24 @@ +v The Weekly Challenge Week 140 +v Task 2 Multiplication Table (in befunge-93) +>89*7+10p83*20p&30p&40p&50p060p180p011p89*556+*+21p30g40g*90p>>>>>v + v<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<v + @,"F"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<|+`g01*g04g03`*g04g03g05< +v<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<< +v >>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 60g30g1-`| +v ^<<<<<<<<<<<<<<<<^vp071p06+1g06<<<<<<<<<<<< <<<<<<<<<<<<<<<<< +v v<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<< +v >>>>>>>>>>>>>>> 70g40g`| ^p07+1g07< +v >70g60g*80g20gp80g1+80p^ +v < +v> ^ +v^ < + >71g21p ^ +v> 50g31g`31g50g1-41g-`*21g71g`*| + > ^ +v^ < +v |`g09+1g06 < + > 31g71g81g`+31p 41g81g71g`!71g81g`!*+41p ^ + ^ < +v >>>>>>>>>>>>>>11g1+11p031p041p060p11g20gg71p>>>>60g1+60p60g20gg81p^ +>$90g11g`#^_" :SNA">:#,_21g.".",@P +This program works for i*j < 79 only. diff --git a/challenge-140/cheok-yin-fung/javascript/ch-2.js b/challenge-140/cheok-yin-fung/javascript/ch-2.js new file mode 100644 index 0000000000..2ddffa5f97 --- /dev/null +++ b/challenge-140/cheok-yin-fung/javascript/ch-2.js @@ -0,0 +1,60 @@ +/* Very rough JavaScript*/ + + +document.write("<p>The Weekly Challenge Week 140</p>"); +document.write("<p>Task 2 Multiplication Table</p>"); +document.write("i: <input type=\"text\" placeholder=\"\" id=\"i\">"); +document.write("<br>"); +document.write("j: <input type=\"text\" placeholder=\"\" id=\"j\">"); +document.write("<br>"); +document.write("k: <input type=\"text\" placeholder=\"\" id=\"k\">"); +document.write("<br>"); + + +document.write("<button onclick=\"calc()\">Calculate</button>" ); + + +function calc() { + let i = parseInt(document.getElementById("i").value); + let j = parseInt(document.getElementById("j").value); + let k = parseInt(document.getElementById("k").value); + + if (isNaN(i) || isNaN(j) || isNaN(k)) { + window.alert("Unable to parse integer. Terminate calculation."); + return; + } + + if (i*j<k) { + window.alert("k > i*j. Terminate calculation."); + return; + } + + + document.write("<p>" + "i: "+ i + ";j: " +j+";k: " + k + "." + "</p>"); + + document.write("<table border=\"1\" style=\"text-align:right\">"); + + let _arr = []; + + for (var _i = 1; _i <= i; _i++) { + document.write("<tr>"); + for (var _j = 1; _j <= j; _j++) { + document.write("<td>"); + document.write(_i*_j); + _arr.push(_i*_j); + document.write("</td>"); + } + document.write("</tr>"); + } + + document.write("</table>"); + + let arr = _arr.sort(); + + document.write("<p> Answer: "+arr[k-1]+"</p>"); + + + return; +} + + diff --git a/challenge-140/cheok-yin-fung/perl/ch-2.pl b/challenge-140/cheok-yin-fung/perl/ch-2.pl new file mode 100644 index 0000000000..47335de088 --- /dev/null +++ b/challenge-140/cheok-yin-fung/perl/ch-2.pl @@ -0,0 +1,35 @@ +# The Weekly Challenge 140 +# Task 2 Multiplication Table +# Usage: $ ch-2.pl $i $j $k +use v5.12.0; +use warnings; +use Test::More tests => 3; + +my ($i,$j,$k) = ($ARGV[0], $ARGV[1], $ARGV[2]); + +say table2array($i,$j,$k) if defined($ARGV[2]); + + + +sub table2array { + my ($i,$j,$k) = ($_[0], $_[1], $_[2]); + + die "k value too large \n" unless $i*$j >= $k; + + my @_arr; + + for my $_i (1..$i) { + for my $_j (1..$j) { + push @_arr, $_i*$_j; + } + } + + my @arr = sort {$a<=>$b} @_arr; + + return $arr[$k-1]; +} + +ok table2array(2, 3, 4) == 3; +ok table2array(3, 3, 6) == 4; +ok table2array(9, 8, 71) == 64; + |
