diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-03-27 13:42:30 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-03-27 13:42:30 +0000 |
| commit | 0527e3bc2557a0d3c4b3ec34d76a2e2e4f651e21 (patch) | |
| tree | 0e5c08222b1d7f9cc28fcbbd2d5e13d094c388ca /challenge-105 | |
| parent | a4462260e75e2b5d02c6951d8b9c7f52d9c595c8 (diff) | |
| download | perlweeklychallenge-club-0527e3bc2557a0d3c4b3ec34d76a2e2e4f651e21.tar.gz perlweeklychallenge-club-0527e3bc2557a0d3c4b3ec34d76a2e2e4f651e21.tar.bz2 perlweeklychallenge-club-0527e3bc2557a0d3c4b3ec34d76a2e2e4f651e21.zip | |
- Added solutions by Laurent Rosenfeld.
Diffstat (limited to 'challenge-105')
| -rw-r--r-- | challenge-105/laurent-rosenfeld/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-105/laurent-rosenfeld/perl/ch-1.pl | 8 | ||||
| -rw-r--r-- | challenge-105/laurent-rosenfeld/perl/ch-2.pl | 23 | ||||
| -rw-r--r-- | challenge-105/laurent-rosenfeld/python/ch-1.py | 7 | ||||
| -rw-r--r-- | challenge-105/laurent-rosenfeld/raku/ch-1.raku | 6 | ||||
| -rw-r--r-- | challenge-105/laurent-rosenfeld/raku/ch-2.raku | 22 |
6 files changed, 67 insertions, 0 deletions
diff --git a/challenge-105/laurent-rosenfeld/blog.txt b/challenge-105/laurent-rosenfeld/blog.txt new file mode 100644 index 0000000000..6db9cdd3bc --- /dev/null +++ b/challenge-105/laurent-rosenfeld/blog.txt @@ -0,0 +1 @@ +http://blogs.perl.org/users/laurent_r/2021/03/perl-weekly-challenge-105-nth-root-and-the-name-game.html diff --git a/challenge-105/laurent-rosenfeld/perl/ch-1.pl b/challenge-105/laurent-rosenfeld/perl/ch-1.pl new file mode 100644 index 0000000000..2e79c73f6d --- /dev/null +++ b/challenge-105/laurent-rosenfeld/perl/ch-1.pl @@ -0,0 +1,8 @@ +use strict; +use warnings; +use feature "say"; + +my $input = $ARGV[0] // 248832; +for my $i (1..10) { + printf "%2i\t%10.3f\n", $i, $input ** (1/$i); +} diff --git a/challenge-105/laurent-rosenfeld/perl/ch-2.pl b/challenge-105/laurent-rosenfeld/perl/ch-2.pl new file mode 100644 index 0000000000..3dee05016a --- /dev/null +++ b/challenge-105/laurent-rosenfeld/perl/ch-2.pl @@ -0,0 +1,23 @@ +use strict; +use warnings; +use feature "say"; + +say "Please enter the name: "; +my $name = <STDIN>; +chomp $name; +my %vowels = map { $_ => 1} qw<a e i o u>; +my ($start, $suffix) = ($1, $2) if $name =~ /(\w)(\w+)/; +my @y; +if (exists $vowels{lc $start}) { + @y = ("bo-$suffix", "fo-$suffix", "mo-$suffix"); +} else { + $y[0] = $start eq 'B' ? "bo-$suffix" : "bo-b$suffix"; + $y[1] = $start eq 'F' ? "fo-$suffix" : "fo-f$suffix"; + $y[2] = $start eq 'M' ? "mo-$suffix" : "mo-m$suffix"; +} +say "\n", <<~EOF; + $name, $name, $y[0] + Bonana-fanna $y[1] + Fee fi $y[2]) + $name! + EOF diff --git a/challenge-105/laurent-rosenfeld/python/ch-1.py b/challenge-105/laurent-rosenfeld/python/ch-1.py new file mode 100644 index 0000000000..49273e2f7a --- /dev/null +++ b/challenge-105/laurent-rosenfeld/python/ch-1.py @@ -0,0 +1,7 @@ +#!/usr/bin/python + +import sys +input = int(sys.argv[1]) if len(sys.argv) > 1 else 248832 +for i in range(1, 11): + root = input ** (1/i) + print('{:2d}'.format(i), " ", root) diff --git a/challenge-105/laurent-rosenfeld/raku/ch-1.raku b/challenge-105/laurent-rosenfeld/raku/ch-1.raku new file mode 100644 index 0000000000..97f6d748a0 --- /dev/null +++ b/challenge-105/laurent-rosenfeld/raku/ch-1.raku @@ -0,0 +1,6 @@ +use v6; + +my $input = @*ARGS[0] // 248832; +for 1..10 -> $i { + printf "%2i\t%10.3f\n", $i, $input ** (1/$i); +} diff --git a/challenge-105/laurent-rosenfeld/raku/ch-2.raku b/challenge-105/laurent-rosenfeld/raku/ch-2.raku new file mode 100644 index 0000000000..efdad81aac --- /dev/null +++ b/challenge-105/laurent-rosenfeld/raku/ch-2.raku @@ -0,0 +1,22 @@ +use v6; + +my $name = prompt "Please enter the name: "; +my $vowels = Set.new(<a e i o u>); +my $consonants = Set.new('a'..'z') (-) $vowels; +my ($start, $suffix) = ($0, $1) if $name ~~ /(\w)(\w+)/; + +my @y; +if $start.lc (elem) $consonants { + @y[0] = $start eq 'B' ?? "bo-$suffix" !! "bo-b$suffix"; + @y[1] = $start eq 'F' ?? "fo-$suffix" !! "fo-f$suffix"; + @y[2] = $start eq 'M' ?? "mo-$suffix" !! "mo-m$suffix"; +} else { + @y = "bo-$suffix", "fo-$suffix", "mo-$suffix"; +} + +say qq:to/END/; + $name, $name, @y[0] + Bonana-fanna @y[1] + Fee fi @y[2]) + $name! + END |
