diff options
Diffstat (limited to 'challenge-105')
| -rw-r--r-- | challenge-105/colin-crain/perl/ch-1.pl | 78 | ||||
| -rw-r--r-- | challenge-105/colin-crain/perl/ch-2.pl | 82 | ||||
| -rw-r--r-- | challenge-105/colin-crain/python/ch-1.py | 20 | ||||
| -rw-r--r-- | challenge-105/colin-crain/python/ch-2.py | 32 | ||||
| -rw-r--r-- | challenge-105/colin-crain/raku/ch-1.raku | 20 | ||||
| -rw-r--r-- | challenge-105/colin-crain/raku/ch-2.raku | 29 |
6 files changed, 261 insertions, 0 deletions
diff --git a/challenge-105/colin-crain/perl/ch-1.pl b/challenge-105/colin-crain/perl/ch-1.pl new file mode 100644 index 0000000000..a3ce3d6e74 --- /dev/null +++ b/challenge-105/colin-crain/perl/ch-1.pl @@ -0,0 +1,78 @@ +#! /opt/local/bin/perl
+#
+# i-told-you-for-the-nth-time.pl
+
+# 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
+#
+# method:
+#
+# r^n = x :x > 0
+# —> n log r = log x
+# —> log r = (log x) / n
+# —> r = e ^ ( (log x) / n )
+#
+# sounds good. Lets make it.
+
+# problems:
+# works, but the first example has no decimal places, the second many, but
+# the example truncates to two. We will use two as our model, and
+# then strip trailing 0s and the decimal point should we arrive at it during
+# the stripping process. All of this is merely cosmetic sugar to make our
+# results match the examples. The math is solid however you format it.
+#
+# © 2021 colin crain
+## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
+
+
+
+use warnings;
+use strict;
+use feature ":5.26";
+use feature qw(signatures);
+no warnings 'experimental::signatures';
+
+
+sub nroot($n, $x) {
+ my $res = sprintf "%2.2f", exp( (log $x) / $n );
+ $res =~ s/\.?0*$//;
+ return $res;
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+use Test::More;
+
+is nroot(5, 248832), 12, 'ex-1';
+is nroot(5, 34), 2.02, 'ex-2';
+
+
+is nroot(3, 125), 5, '5^3';
+is nroot(x), 2.02, 'ex-2';
+is nroot(4, 49), 2.02, 'ex-2';
+is nroot(5, 34), 2.02, 'ex-2';
+is nroot(5, 34), 2.02, 'ex-2';
+
+
+done_testing();
diff --git a/challenge-105/colin-crain/perl/ch-2.pl b/challenge-105/colin-crain/perl/ch-2.pl new file mode 100644 index 0000000000..1e2e4e97de --- /dev/null +++ b/challenge-105/colin-crain/perl/ch-2.pl @@ -0,0 +1,82 @@ +#! /opt/local/bin/perl
+#
+# name-game.pl
+#
+# 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!
+#
+# rules:
+# (X), (X), bo-b (Y)
+# Bonana-fanna fo-f (Y)
+# Fee fi mo-m (Y)
+# (X)!
+#
+# If the name starts with a b, f, or m, that sound simply is not
+# repeated. For example: Billy becomes "Billy Billy bo-illy"; Fred
+# becomes "bonana fanna fo-red"; Marsha becomes "fee fi mo-arsha"[2]
+#
+#
+#
+# © 2021 colin crain
+## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
+
+
+
+use warnings;
+use strict;
+use feature ":5.26";
+use feature qw(signatures);
+no warnings 'experimental::signatures';
+
+my $name = shift @ARGV || "Katie";
+make_song($name, chop_syl($name));
+
+sub chop_syl ($name) {
+ $name =~ /([^aeiou]?)(.*)/i;
+ my ($head, $tail) = ($1, $2);
+ return ($head, lc($tail));
+}
+
+
+sub make_song ($name, $head, $tail) {
+ my ($b, $f, $m) = ('' x 3);
+ $b = 'b' unless substr($head, 0, 1) eq 'B';
+ $f = 'f' unless substr($head, 0, 1) eq 'F';
+ $m = 'm' unless substr($head, 0, 1) eq 'M';
+
+ say<<"END";
+ ${name}, ${name}, bo-${b}${tail},
+ Bonana-fanna fo-${f}${tail}
+ Fee fi mo-${m}${tail}
+ ${name}!
+END
+
+}
+
+
+
+
+
+
+
+
+
+
+# use Test::More;
+#
+# is
+#
+# done_testing();
diff --git a/challenge-105/colin-crain/python/ch-1.py b/challenge-105/colin-crain/python/ch-1.py new file mode 100644 index 0000000000..5354ab0f92 --- /dev/null +++ b/challenge-105/colin-crain/python/ch-1.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3
+#
+#
+# nth-root.py
+#
+#
+#
+# © 2021 colin crain
+## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
+
+import math
+
+def nroot( n, x ):
+ return math.exp( math.log(x) / n )
+
+m = 3
+y = 125
+
+print( nroot(m, y) )
+
diff --git a/challenge-105/colin-crain/python/ch-2.py b/challenge-105/colin-crain/python/ch-2.py new file mode 100644 index 0000000000..7e88a72b5e --- /dev/null +++ b/challenge-105/colin-crain/python/ch-2.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3
+#
+#
+# name-game.py
+#
+#
+#
+# © 2021 colin crain
+## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
+
+
+import re
+import sys
+
+def makeSong( name ):
+ m = re.search("([^aeiouy]?)(.*)", name, re.I)
+ (h, t) = m.group(1,2)
+
+ print(f'''
+ {name}, {name}, bo-{"b" if h != "B" else ""}{t}
+ Bonana-fanna fo-{"f" if h != "F" else ""}{t}
+ Fee fi mo-{"m" if h != "M" else ""}{t}
+ {name}!
+ ''')
+
+for name in sys.argv[1:]:
+ makeSong(name)
+
+
+
+
+
diff --git a/challenge-105/colin-crain/raku/ch-1.raku b/challenge-105/colin-crain/raku/ch-1.raku new file mode 100644 index 0000000000..0e4230ad32 --- /dev/null +++ b/challenge-105/colin-crain/raku/ch-1.raku @@ -0,0 +1,20 @@ +#!/usr/bin/env perl6 +# +# +# nth-root.raku +# +# +# +# © 2021 colin crain +## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## + + + +unit sub MAIN (Int $n = 3, Int $x = 125) ; + +.fmt("%2.2f").say for nroot($n, $x); + + +sub nroot( Int $n, Int $x where { $x > 0 } ) { + return exp( (log $x) / $n ); +} diff --git a/challenge-105/colin-crain/raku/ch-2.raku b/challenge-105/colin-crain/raku/ch-2.raku new file mode 100644 index 0000000000..81dfeb2aaa --- /dev/null +++ b/challenge-105/colin-crain/raku/ch-2.raku @@ -0,0 +1,29 @@ +#!/usr/bin/env perl6 +# +# +# name-game.raku +# +# +# +# © 2021 colin crain +## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## + + + +unit sub MAIN (Str $name = 'Katie') ; + +make_song($name); + +sub make_song ($name) { + + $name ~~ m:i/ (<-[aeiouy]>?) (.*) /; + my ($h, $t) = ( $0, $1.lc ); + + + say qq:to/END/; + {$name}, {$name}, bo-{$h~~/b/??''!!'b'}{$t}, + Bonana-fanna fo-{$h~~/f/??''!!'f'}{$t} + Fee fi mo-{$h~~/m/??''!!'m'}{$t} + {$name}! + END +} |
