aboutsummaryrefslogtreecommitdiff
path: root/challenge-105
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-03-27 12:21:59 +0000
committerGitHub <noreply@github.com>2021-03-27 12:21:59 +0000
commitefb27bda09a621e8212761b7b084e39c10f1745f (patch)
tree9a68c9c2c728302cdec68e661ec53abd701b1524 /challenge-105
parent99f7d0df506e8b6e8aa200532a125a43d5f38744 (diff)
parentfa0008580d9bb5aba4a15bf03d77cb184baba26c (diff)
downloadperlweeklychallenge-club-efb27bda09a621e8212761b7b084e39c10f1745f.tar.gz
perlweeklychallenge-club-efb27bda09a621e8212761b7b084e39c10f1745f.tar.bz2
perlweeklychallenge-club-efb27bda09a621e8212761b7b084e39c10f1745f.zip
Merge pull request #3775 from pauloscustodio/paulo-custodio
Paulo custodio
Diffstat (limited to 'challenge-105')
-rw-r--r--challenge-105/paulo-custodio/awk/ch-1.awk8
-rw-r--r--challenge-105/paulo-custodio/basic/ch-1.bas27
-rw-r--r--challenge-105/paulo-custodio/basic/ch-2.bas38
-rw-r--r--challenge-105/paulo-custodio/bc/ch-1.bc8
-rw-r--r--challenge-105/paulo-custodio/perl/ch-1.pl9
-rw-r--r--challenge-105/paulo-custodio/t/awk.t32
-rw-r--r--challenge-105/paulo-custodio/t/bc.t4
-rw-r--r--challenge-105/paulo-custodio/t/test-1.yaml2
8 files changed, 89 insertions, 39 deletions
diff --git a/challenge-105/paulo-custodio/awk/ch-1.awk b/challenge-105/paulo-custodio/awk/ch-1.awk
index c4a5b8c716..8a7d648136 100644
--- a/challenge-105/paulo-custodio/awk/ch-1.awk
+++ b/challenge-105/paulo-custodio/awk/ch-1.awk
@@ -16,7 +16,13 @@
# Input: $N = 5, $k = 34
# Output: 2.02
+
+function round(n) {
+ ROUND_FACTOR = 10000
+ return int(n*ROUND_FACTOR+0.5)/ROUND_FACTOR;
+}
+
BEGIN {
- print ARGV[2] ^ (1 / ARGV[1]);
+ print round(ARGV[2] ^ (1 / ARGV[1]));
exit 0;
}
diff --git a/challenge-105/paulo-custodio/basic/ch-1.bas b/challenge-105/paulo-custodio/basic/ch-1.bas
new file mode 100644
index 0000000000..790f9314b9
--- /dev/null
+++ b/challenge-105/paulo-custodio/basic/ch-1.bas
@@ -0,0 +1,27 @@
+' Challenge 105
+'
+' TASK #1 › Nth root
+' Submitted by: Mohammad S Anwar
+' You are given positive numbers $N and $k.
+'
+' Write a script to find out the $Nth root of $k. For more information, please
+' take a look at the wiki page.
+'
+' Example
+' Input: $N = 5, $k = 248832
+' Output: 12
+'
+' Input: $N = 5, $k = 34
+' Output: 2.02
+
+const ROUND_FACTOR as double = 10000.0
+
+function round(n as double) as double
+ round = int(n*ROUND_FACTOR+0.5)/ROUND_FACTOR
+end function
+
+dim n as integer, k as integer
+
+n=val(command(1))
+k=val(command(2))
+print trim(str(round(k^(1/n))))
diff --git a/challenge-105/paulo-custodio/basic/ch-2.bas b/challenge-105/paulo-custodio/basic/ch-2.bas
new file mode 100644
index 0000000000..11bd8d95ef
--- /dev/null
+++ b/challenge-105/paulo-custodio/basic/ch-2.bas
@@ -0,0 +1,38 @@
+' Challenge 105
+'
+' TASK #2 › The Name Game
+' Submitted by: Mohammad S Anwar
+' You are given a $name.
+'
+' Write a script to display the lyrics to the Shirley Ellis song The Name Game.
+' Please checkout the wiki page for more information.
+'
+' Example
+' Input: $name = "Katie"
+' Output:
+'
+' Katie, Katie, bo-batie,
+' Bonana-fanna fo-fatie
+' Fee fi mo-matie
+' Katie!
+
+sub print_song(sName as string)
+ dim sEnd as string, b as string, f as string, m as string
+
+ sEnd = lcase(sName)
+ if sEnd>="b" and sEnd<="z" _
+ and left(sEnd,1)<>"e" _
+ and left(sEnd,1)<>"i" _
+ and left(sEnd,1)<>"o" _
+ and left(sEnd,1)<>"u" then sEnd=mid(sEnd,2)
+ if left(sName,1)<>"B" then b="b"
+ if left(sName,1)<>"F" then f="f"
+ if left(sName,1)<>"M" then m="m"
+
+ print sName;", ";sName;", bo-";b;sEnd;","
+ print "Bonana-fanna fo-";f;sEnd
+ print "Fee fi mo-";m;sEnd
+ print sName;"!"
+end sub
+
+print_song command(1)
diff --git a/challenge-105/paulo-custodio/bc/ch-1.bc b/challenge-105/paulo-custodio/bc/ch-1.bc
index 5974bc5aaf..bc4e24aa33 100644
--- a/challenge-105/paulo-custodio/bc/ch-1.bc
+++ b/challenge-105/paulo-custodio/bc/ch-1.bc
@@ -18,7 +18,7 @@ Input: $N = 5, $k = 34
Output: 2.02
*/
-scale = 16
+scale = 4
/* A function to return the integer part of x */
define i(x) {
@@ -38,6 +38,10 @@ define p(x,y) {
return ( e( y * l(x) ) )
}
+define round(n) {
+ return i(n*10000+0.5)/10000
+}
+
n = read();
k = read();
-print p(k, (1/n)), "\n";
+print round(p(k, (1/n))), "\n";
diff --git a/challenge-105/paulo-custodio/perl/ch-1.pl b/challenge-105/paulo-custodio/perl/ch-1.pl
index 174725e377..a80bd4df57 100644
--- a/challenge-105/paulo-custodio/perl/ch-1.pl
+++ b/challenge-105/paulo-custodio/perl/ch-1.pl
@@ -20,5 +20,12 @@ use strict;
use warnings;
use 5.030;
+use constant ROUND_FACTOR => 10000;
+
my($n, $k) = @ARGV;
-say $k ** (1/$n);
+say round($k ** (1/$n));
+
+sub round {
+ my($n) = @_;
+ return int($n*ROUND_FACTOR+0.5)/ROUND_FACTOR;
+}
diff --git a/challenge-105/paulo-custodio/t/awk.t b/challenge-105/paulo-custodio/t/awk.t
deleted file mode 100644
index 9fc273ee43..0000000000
--- a/challenge-105/paulo-custodio/t/awk.t
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-use 5.030;
-use Test::More;
-
-is capture("gawk -f ./awk/ch-1.awk 5 248832"), "12\n";
-is capture("gawk -f ./awk/ch-1.awk 5 34 "), "2.0244\n";
-
-
-is capture("gawk -f ./awk/ch-2.awk Katie"), <<END;
-Katie, Katie, bo-batie,
-Bonana-fanna fo-fatie
-Fee fi mo-matie
-Katie!
-END
-
-is capture("gawk -f ./awk/ch-2.awk Billy"), <<END;
-Billy, Billy, bo-illy,
-Bonana-fanna fo-filly
-Fee fi mo-milly
-Billy!
-END
-
-done_testing;
-
-sub capture {
- my($cmd) = @_;
- my $out = `$cmd`;
- return $out =~ s/\r//gr;
-}
diff --git a/challenge-105/paulo-custodio/t/bc.t b/challenge-105/paulo-custodio/t/bc.t
index 372e5f58c9..7036d96800 100644
--- a/challenge-105/paulo-custodio/t/bc.t
+++ b/challenge-105/paulo-custodio/t/bc.t
@@ -5,8 +5,8 @@ use warnings;
use 5.030;
use Test::More;
-is capture("echo 5 248832 | bc -lq ./bc/ch-1.bc"), "11.9999999999999998\n";
-is capture("echo 5 34 | bc -lq ./bc/ch-1.bc"), "2.0243974584998848\n";
+is capture("echo 5 248832 | bc -lq ./bc/ch-1.bc"), "11.9999\n";
+is capture("echo 5 34 | bc -lq ./bc/ch-1.bc"), "2.0242\n";
done_testing;
diff --git a/challenge-105/paulo-custodio/t/test-1.yaml b/challenge-105/paulo-custodio/t/test-1.yaml
index f39ad216d9..32c417741e 100644
--- a/challenge-105/paulo-custodio/t/test-1.yaml
+++ b/challenge-105/paulo-custodio/t/test-1.yaml
@@ -7,4 +7,4 @@
cleanup:
args: 5 34
input:
- output: 2.02439745849989
+ output: 2.0244