aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-11-10 18:18:42 +0000
committerGitHub <noreply@github.com>2019-11-10 18:18:42 +0000
commitf0e6c82778ceefcef00460223e58520657b549ca (patch)
tree60c8dcab565d0c12a2e588473b66a73d312aa7e0
parent08f9a0232261d0b6d4cb6f58f4acd400183af0d9 (diff)
parent32482b0f526d53c90f78a4c77ce556f8c5ec292f (diff)
downloadperlweeklychallenge-club-f0e6c82778ceefcef00460223e58520657b549ca.tar.gz
perlweeklychallenge-club-f0e6c82778ceefcef00460223e58520657b549ca.tar.bz2
perlweeklychallenge-club-f0e6c82778ceefcef00460223e58520657b549ca.zip
Merge pull request #920 from adamcrussell/challenge-033
Challenge 033
-rw-r--r--challenge-033/adam-russell/blog.txt1
-rw-r--r--challenge-033/adam-russell/cxx/ch-1.cxx37
-rw-r--r--challenge-033/adam-russell/cxx/ch-2.cxx27
-rw-r--r--challenge-033/adam-russell/perl5/ch-1.pl20
-rw-r--r--challenge-033/adam-russell/perl5/ch-2.pl28
-rw-r--r--challenge-033/adam-russell/raku/ch-1.p617
-rw-r--r--challenge-033/adam-russell/raku/ch-2.p625
7 files changed, 155 insertions, 0 deletions
diff --git a/challenge-033/adam-russell/blog.txt b/challenge-033/adam-russell/blog.txt
new file mode 100644
index 0000000000..8cf44e9f7f
--- /dev/null
+++ b/challenge-033/adam-russell/blog.txt
@@ -0,0 +1 @@
+https://adamcrussell.livejournal.com/11383.html
diff --git a/challenge-033/adam-russell/cxx/ch-1.cxx b/challenge-033/adam-russell/cxx/ch-1.cxx
new file mode 100644
index 0000000000..20228caabb
--- /dev/null
+++ b/challenge-033/adam-russell/cxx/ch-1.cxx
@@ -0,0 +1,37 @@
+/**
+* Create a script that accepts one or more files
+* specified on the command-line and count the
+* number of times letters appeared in the files.
+**/
+#include <map>
+#include <cctype>
+#include <vector>
+#include <iostream>
+
+int main(int argc, char** argv){
+ std::string input;
+ std::vector<std::pair<char, int>> v;
+ std::map<char, int> letter_counts;
+ do{
+ getline(std::cin, input);
+ if(!input.empty()){
+ for(char letter: input){
+ letter = tolower(letter);
+ if(letter != ' ' && letter != '\t' && letter != '\n' && letter != '.'){
+ if(letter_counts.find(letter) != letter_counts.end()){
+ letter_counts[letter] += 1;
+ }
+ else{
+ letter_counts[letter] = 1;
+ }
+ }
+ }
+ }
+ }while(!input.empty());
+ std::copy(letter_counts.begin(), letter_counts.end(), std::back_inserter<std::vector<std::pair<char, int>>>(v));
+ std::vector<std::pair<char, int>>::iterator iter = v.begin();
+ while(iter != v.end()){
+ std::cout << iter->first << ": " << iter->second << std::endl;
+ iter++;
+ }
+}
diff --git a/challenge-033/adam-russell/cxx/ch-2.cxx b/challenge-033/adam-russell/cxx/ch-2.cxx
new file mode 100644
index 0000000000..ea45f839ff
--- /dev/null
+++ b/challenge-033/adam-russell/cxx/ch-2.cxx
@@ -0,0 +1,27 @@
+/**
+* Write a script to print 11x11 multiplication
+* table, only the top half triangle.
+**/
+#include <iostream>
+
+int main(int argc, char **argv){
+ std::cout << " x| 1 2 3 4 5 6 7 8 9 10 11" << std::endl;
+ std::cout << " ---+------------------------------------------------" << std::endl;
+ for(int x = 1; x <= 11; x++){
+ std::cout.width(6); std::cout << x << "|";
+ for(int y = 1; y <= 11; y++){
+ if(y < x){
+ std::cout.width(4); std::cout << std::right << " ";
+ }
+ else{
+ if(y < 10){
+ std::cout.width(4); std::cout << std::right << x*y;
+ }
+ else{
+ std::cout.width(6); std::cout << std::right << x*y;
+ }
+ }
+ }
+ std::cout << std::endl;
+ }
+}
diff --git a/challenge-033/adam-russell/perl5/ch-1.pl b/challenge-033/adam-russell/perl5/ch-1.pl
new file mode 100644
index 0000000000..f869e3ec4d
--- /dev/null
+++ b/challenge-033/adam-russell/perl5/ch-1.pl
@@ -0,0 +1,20 @@
+use strict;
+use warnings;
+##
+# Create a script that accepts one or more files
+# specified on the command-line and count the
+# number of times letters appeared in the files.
+##
+MAIN:{
+ my %letter_count;
+ while(<>){
+ chomp;
+ my @characters = split(//, $_);
+ for my $c (@characters){
+ $letter_count{$c}++ if $c=~m/[[:alpha:]]/;
+ }
+ }
+ for my $key (sort keys %letter_count){
+ print "$key: $letter_count{$key}\n";
+ }
+}
diff --git a/challenge-033/adam-russell/perl5/ch-2.pl b/challenge-033/adam-russell/perl5/ch-2.pl
new file mode 100644
index 0000000000..c366a980c5
--- /dev/null
+++ b/challenge-033/adam-russell/perl5/ch-2.pl
@@ -0,0 +1,28 @@
+use strict;
+use warnings;
+##
+# Write a script to print 11x11 multiplication
+# table, only the top half triangle.
+##
+use Perl6::Form;
+sub print_table11{
+ my($x,$x1,$x2,$x3,$x4,$x5,$x6,$x7,$x8,$x9,$x10,$x11);
+ my $header = form
+ ' x| 1 2 3 4 5 6 7 8 9 10 11',
+ ' ---+----------------------------------------------';
+ print "$header";
+ for $x (1 .. 11){
+ my @a;
+ @a = (0) x ($x -1) if $x > 1;
+ push @a, ($x .. 11);
+ ($x1,$x2,$x3,$x4,$x5,$x6,$x7,$x8,$x9,$x10,$x11) = map {$_ == 0 ? "" : $_} map { $x * $_ } @a;
+ my $row = form
+ ' {>>}|{>>}{>>}{>>}{>>}{>>}{>>}{>>}{>>}{>>}{>>>}{>>>}',
+ $x,$x1,$x2,$x3,$x4,$x5,$x6,$x7,$x8,$x9,$x10,$x11;
+ print "$row";
+ }
+}
+
+MAIN:{
+ print_table11;
+}
diff --git a/challenge-033/adam-russell/raku/ch-1.p6 b/challenge-033/adam-russell/raku/ch-1.p6
new file mode 100644
index 0000000000..628c774a6e
--- /dev/null
+++ b/challenge-033/adam-russell/raku/ch-1.p6
@@ -0,0 +1,17 @@
+##
+# Create a script that accepts one or more files
+# specified on the command-line and count the
+# number of times letters appeared in the files.
+##
+sub MAIN {
+ my %letter_count;
+ for $*IN.lines() -> $line {
+ my @characters = $line.split("");
+ for @characters -> $c {
+ %letter_count{$c}++ if $c~~m/<alpha>/;
+ }
+ }
+ for sort keys %letter_count -> $key {
+ print "$key: %letter_count{$key}\n";
+ }
+}
diff --git a/challenge-033/adam-russell/raku/ch-2.p6 b/challenge-033/adam-russell/raku/ch-2.p6
new file mode 100644
index 0000000000..74f93bc817
--- /dev/null
+++ b/challenge-033/adam-russell/raku/ch-2.p6
@@ -0,0 +1,25 @@
+##
+# Write a script to print 11x11 multiplication
+# table, only the top half triangle.
+##
+use Form;
+sub print_table11 {
+ my ($x,$x1,$x2,$x3,$x4,$x5,$x6,$x7,$x8,$x9,$x10,$x11);
+ my $header = form
+ ' x| 1 2 3 4 5 6 7 8 9 10 11',
+ ' ---+----------------------------------------------';
+ print $header;
+ for 1 .. 11 -> $x {
+ my @a;
+ @a = (0) xx ($x -1) if $x > 1;
+ @a.append($x .. 11);
+ my @b = map({$_ == 0 ?? "" !! $_}, map({ $x * $_ }, @a));
+ print sprintf '%5s|', $x;
+ my $s = sprintf '%4s%4s%4s%4s%4s%4s%4s%4s%4s%5s%5s', @b;
+ say $s;
+ }
+}
+
+sub MAIN {
+ print_table11;
+}