From 5cd650edf4d85702e2f3d90622437a6bdd518130 Mon Sep 17 00:00:00 2001 From: Adam Russell Date: Sun, 10 Nov 2019 02:05:55 -0500 Subject: initial commit --- challenge-033/adam-russell/cxx/ch-1.cxx | 32 ++++++++++++++++++++++++++++++++ challenge-033/adam-russell/cxx/ch-2.cxx | 23 +++++++++++++++++++++++ challenge-033/adam-russell/perl5/ch-1.pl | 19 +++++++++++++++++++ challenge-033/adam-russell/perl5/ch-2.pl | 28 ++++++++++++++++++++++++++++ challenge-033/adam-russell/raku/ch-1.p6 | 0 challenge-033/adam-russell/raku/ch-2.p6 | 25 +++++++++++++++++++++++++ 6 files changed, 127 insertions(+) create mode 100644 challenge-033/adam-russell/cxx/ch-1.cxx create mode 100644 challenge-033/adam-russell/cxx/ch-2.cxx create mode 100644 challenge-033/adam-russell/perl5/ch-1.pl create mode 100644 challenge-033/adam-russell/perl5/ch-2.pl create mode 100644 challenge-033/adam-russell/raku/ch-1.p6 create mode 100644 challenge-033/adam-russell/raku/ch-2.p6 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 +#include +#include +#include + +int main(int argc, char** argv){ + std::string input; + std::vector> v; + std::map 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>>(v)); + std::vector>::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 + +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 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; +} -- cgit From 32482b0f526d53c90f78a4c77ce556f8c5ec292f Mon Sep 17 00:00:00 2001 From: Adam Russell Date: Sun, 10 Nov 2019 13:12:09 -0500 Subject: solution for challenge 033 --- challenge-033/adam-russell/blog.txt | 1 + challenge-033/adam-russell/cxx/ch-1.cxx | 5 +++++ challenge-033/adam-russell/cxx/ch-2.cxx | 10 +++++++--- challenge-033/adam-russell/perl5/ch-1.pl | 1 + challenge-033/adam-russell/raku/ch-1.p6 | 17 +++++++++++++++++ challenge-033/adam-russell/raku/ch-2.p6 | 2 +- 6 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 challenge-033/adam-russell/blog.txt 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 index c0dc33f65e..20228caabb 100644 --- a/challenge-033/adam-russell/cxx/ch-1.cxx +++ b/challenge-033/adam-russell/cxx/ch-1.cxx @@ -1,3 +1,8 @@ +/** +* 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 #include #include diff --git a/challenge-033/adam-russell/cxx/ch-2.cxx b/challenge-033/adam-russell/cxx/ch-2.cxx index d8c75a281b..ea45f839ff 100644 --- a/challenge-033/adam-russell/cxx/ch-2.cxx +++ b/challenge-033/adam-russell/cxx/ch-2.cxx @@ -1,8 +1,12 @@ +/** +* Write a script to print 11x11 multiplication +* table, only the top half triangle. +**/ #include 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; + 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++){ @@ -14,7 +18,7 @@ int main(int argc, char **argv){ std::cout.width(4); std::cout << std::right << x*y; } else{ - std::cout.width(5); std::cout << std::right << x*y; + std::cout.width(6); std::cout << std::right << x*y; } } } diff --git a/challenge-033/adam-russell/perl5/ch-1.pl b/challenge-033/adam-russell/perl5/ch-1.pl index 54a93db7ca..f869e3ec4d 100644 --- a/challenge-033/adam-russell/perl5/ch-1.pl +++ b/challenge-033/adam-russell/perl5/ch-1.pl @@ -4,6 +4,7 @@ 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(<>){ diff --git a/challenge-033/adam-russell/raku/ch-1.p6 b/challenge-033/adam-russell/raku/ch-1.p6 index e69de29bb2..628c774a6e 100644 --- a/challenge-033/adam-russell/raku/ch-1.p6 +++ 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//; + } + } + 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 index b0db73499c..74f93bc817 100644 --- a/challenge-033/adam-russell/raku/ch-2.p6 +++ b/challenge-033/adam-russell/raku/ch-2.p6 @@ -16,7 +16,7 @@ sub print_table11 { 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; + say $s; } } -- cgit