aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Russell <ac.russell@live.com>2019-11-10 02:05:55 -0500
committerAdam Russell <ac.russell@live.com>2019-11-10 02:05:55 -0500
commit5cd650edf4d85702e2f3d90622437a6bdd518130 (patch)
treeaa32119ef10b9e5a252bd5b1271085b869c84ce5
parent11a399aca6169d8ca634254d48a99328fffba237 (diff)
downloadperlweeklychallenge-club-5cd650edf4d85702e2f3d90622437a6bdd518130.tar.gz
perlweeklychallenge-club-5cd650edf4d85702e2f3d90622437a6bdd518130.tar.bz2
perlweeklychallenge-club-5cd650edf4d85702e2f3d90622437a6bdd518130.zip
initial commit
-rw-r--r--challenge-033/adam-russell/cxx/ch-1.cxx32
-rw-r--r--challenge-033/adam-russell/cxx/ch-2.cxx23
-rw-r--r--challenge-033/adam-russell/perl5/ch-1.pl19
-rw-r--r--challenge-033/adam-russell/perl5/ch-2.pl28
-rw-r--r--challenge-033/adam-russell/raku/ch-1.p60
-rw-r--r--challenge-033/adam-russell/raku/ch-2.p625
6 files changed, 127 insertions, 0 deletions
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..c0dc33f65e
--- /dev/null
+++ b/challenge-033/adam-russell/cxx/ch-1.cxx
@@ -0,0 +1,32 @@
+#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..d8c75a281b
--- /dev/null
+++ b/challenge-033/adam-russell/cxx/ch-2.cxx
@@ -0,0 +1,23 @@
+#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(5); 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..54a93db7ca
--- /dev/null
+++ b/challenge-033/adam-russell/perl5/ch-1.pl
@@ -0,0 +1,19 @@
+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..e69de29bb2
--- /dev/null
+++ b/challenge-033/adam-russell/raku/ch-1.p6
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..b0db73499c
--- /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;
+}