From 12f87d5a45a360caa7f10b408d956082e7038ee4 Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 20 Jan 2021 02:01:49 +0100 Subject: Test for part 1 --- challenge-001/abigail/t/ctest.ini | 2 ++ challenge-001/abigail/t/input-1-1 | 1 + challenge-001/abigail/t/output-1-1.exp | 2 ++ 3 files changed, 5 insertions(+) create mode 100644 challenge-001/abigail/t/ctest.ini create mode 100644 challenge-001/abigail/t/input-1-1 create mode 100644 challenge-001/abigail/t/output-1-1.exp diff --git a/challenge-001/abigail/t/ctest.ini b/challenge-001/abigail/t/ctest.ini new file mode 100644 index 0000000000..9919062e21 --- /dev/null +++ b/challenge-001/abigail/t/ctest.ini @@ -0,0 +1,2 @@ +[names] +1-1 = The challenge diff --git a/challenge-001/abigail/t/input-1-1 b/challenge-001/abigail/t/input-1-1 new file mode 100644 index 0000000000..8bf4a74aa0 --- /dev/null +++ b/challenge-001/abigail/t/input-1-1 @@ -0,0 +1 @@ +Perl Weekly Challenge diff --git a/challenge-001/abigail/t/output-1-1.exp b/challenge-001/abigail/t/output-1-1.exp new file mode 100644 index 0000000000..180b2cd17a --- /dev/null +++ b/challenge-001/abigail/t/output-1-1.exp @@ -0,0 +1,2 @@ +PErl WEEkly ChallEngE +5 -- cgit From d355d83bafe3c6ca5f15003f834e01c7e04cfe16 Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 20 Jan 2021 02:10:23 +0100 Subject: Test with no e --- challenge-001/abigail/t/ctest.ini | 1 + challenge-001/abigail/t/input-1-2 | 1 + challenge-001/abigail/t/output-1-2.exp | 2 ++ 3 files changed, 4 insertions(+) create mode 100644 challenge-001/abigail/t/input-1-2 create mode 100644 challenge-001/abigail/t/output-1-2.exp diff --git a/challenge-001/abigail/t/ctest.ini b/challenge-001/abigail/t/ctest.ini index 9919062e21..158e3552c7 100644 --- a/challenge-001/abigail/t/ctest.ini +++ b/challenge-001/abigail/t/ctest.ini @@ -1,2 +1,3 @@ [names] 1-1 = The challenge +1-2 = No e diff --git a/challenge-001/abigail/t/input-1-2 b/challenge-001/abigail/t/input-1-2 new file mode 100644 index 0000000000..2e0f5b7508 --- /dev/null +++ b/challenge-001/abigail/t/input-1-2 @@ -0,0 +1 @@ +foo bar baz quux diff --git a/challenge-001/abigail/t/output-1-2.exp b/challenge-001/abigail/t/output-1-2.exp new file mode 100644 index 0000000000..674aefe381 --- /dev/null +++ b/challenge-001/abigail/t/output-1-2.exp @@ -0,0 +1,2 @@ +foo bar baz quux +0 -- cgit From ce2bdf54ee1c50019eb30eacd1907d80b8b89967 Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 20 Jan 2021 02:18:34 +0100 Subject: README file --- challenge-001/abigail/README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 challenge-001/abigail/README.md diff --git a/challenge-001/abigail/README.md b/challenge-001/abigail/README.md new file mode 100644 index 0000000000..5655dfed12 --- /dev/null +++ b/challenge-001/abigail/README.md @@ -0,0 +1,21 @@ +# Solutions by Abigail + +## [Challenge #1](https://perlweeklychallenge.org/blog/perl-weekly-challenge-001/#challenge-1) + +Write a script to replace the character `e` with `E` in the string +`"Perl Weekly Challenge"`. Also print the number of times the character +`e` is found in the string. + +### Solutions + + +## [Challenge #2](https://perlweeklychallenge.org/blog/perl-weekly-challenge-001 +/#challenge-2) + +Write a one-liner to solve the *FizzBuzz* problem and print the +numbers `1` through `20`. However, any number divisible by `3` should +be replaced by the word `fizz` and any divisible by `5` by the word +`buzz` Those numbers that are both divisible by `3` and `5` become +`fizzbuzz`. + +### Solutions -- cgit From a3f1e846d55e92499b385d9cf58b2a5d87fca83d Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 20 Jan 2021 02:21:15 +0100 Subject: Perl solution for week 1/part 1 --- challenge-001/abigail/README.md | 1 + challenge-001/abigail/perl/ch-1.pl | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 challenge-001/abigail/perl/ch-1.pl diff --git a/challenge-001/abigail/README.md b/challenge-001/abigail/README.md index 5655dfed12..e21e3a20af 100644 --- a/challenge-001/abigail/README.md +++ b/challenge-001/abigail/README.md @@ -7,6 +7,7 @@ Write a script to replace the character `e` with `E` in the string `e` is found in the string. ### Solutions +* [Perl](perl/ch-1.pl) ## [Challenge #2](https://perlweeklychallenge.org/blog/perl-weekly-challenge-001 diff --git a/challenge-001/abigail/perl/ch-1.pl b/challenge-001/abigail/perl/ch-1.pl new file mode 100644 index 0000000000..8fd893fb93 --- /dev/null +++ b/challenge-001/abigail/perl/ch-1.pl @@ -0,0 +1,15 @@ +#!/opt/perl/bin/perl + +use 5.032; + +use strict; +use warnings; +no warnings 'syntax'; + +use experimental 'signatures'; +use experimental 'lexical_subs'; + +while (<>) { + my $changes = y/e/E/; + say $_, $changes +} -- cgit From 057e4bce55bfc00c96073913cb49d7bf614e322e Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 20 Jan 2021 02:23:41 +0100 Subject: C solution for week 1/part 1 --- challenge-001/abigail/c/ch-1.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 challenge-001/abigail/c/ch-1.c diff --git a/challenge-001/abigail/c/ch-1.c b/challenge-001/abigail/c/ch-1.c new file mode 100644 index 0000000000..fabd2d2f22 --- /dev/null +++ b/challenge-001/abigail/c/ch-1.c @@ -0,0 +1,25 @@ +# include +# include +# include + +int main (void) { + char * line = NULL; + size_t len = 0; + size_t strlen; + + while ((strlen = getline (&line, &len, stdin)) != -1) { + char * line_ptr = line; + size_t e_count = 0; + while (* line_ptr) { + if (* line_ptr == 'e') { + * line_ptr = 'E'; + e_count ++; + } + line_ptr ++; + } + printf ("%s%zu\n", line, e_count); + } + free (line); + + return (0); +} -- cgit From 51e02c802d7f433b447a983241c91f5ed8c9d756 Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 20 Jan 2021 02:32:58 +0100 Subject: AWK solution for week 1, part 1 --- challenge-001/abigail/README.md | 2 ++ challenge-001/abigail/awk/ch-1.awk | 5 +++++ 2 files changed, 7 insertions(+) create mode 100644 challenge-001/abigail/awk/ch-1.awk diff --git a/challenge-001/abigail/README.md b/challenge-001/abigail/README.md index e21e3a20af..6c4b4b565b 100644 --- a/challenge-001/abigail/README.md +++ b/challenge-001/abigail/README.md @@ -7,6 +7,8 @@ Write a script to replace the character `e` with `E` in the string `e` is found in the string. ### Solutions +* [AWK](awk/ch-1.awk) +* [C](c/ch-1.c) * [Perl](perl/ch-1.pl) diff --git a/challenge-001/abigail/awk/ch-1.awk b/challenge-001/abigail/awk/ch-1.awk new file mode 100644 index 0000000000..66adcae5c7 --- /dev/null +++ b/challenge-001/abigail/awk/ch-1.awk @@ -0,0 +1,5 @@ +{ + count = gsub ("e", "E") + print $0 + print count +} -- cgit From cf50c590754a88bb4247fb390705d28a6e54d66d Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 20 Jan 2021 02:50:14 +0100 Subject: Node.js solution for week 1, part 1 --- challenge-001/abigail/README.md | 1 + challenge-001/abigail/node/ch-1.js | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 challenge-001/abigail/node/ch-1.js diff --git a/challenge-001/abigail/README.md b/challenge-001/abigail/README.md index 6c4b4b565b..2644f43e28 100644 --- a/challenge-001/abigail/README.md +++ b/challenge-001/abigail/README.md @@ -9,6 +9,7 @@ Write a script to replace the character `e` with `E` in the string ### Solutions * [AWK](awk/ch-1.awk) * [C](c/ch-1.c) +* [Node.js](node/ch-1.js) * [Perl](perl/ch-1.pl) diff --git a/challenge-001/abigail/node/ch-1.js b/challenge-001/abigail/node/ch-1.js new file mode 100644 index 0000000000..9cc9980719 --- /dev/null +++ b/challenge-001/abigail/node/ch-1.js @@ -0,0 +1,21 @@ +// +// Read STDIN. Split on newlines, filter out empty lines, then call "main". +// + require ("fs") +. readFileSync (0) // Read all. +. toString () // Turn it into a string. +. split ("\n") // Split on newlines. +. filter (_ => _ . length) // Filter out empty lines. +. map (_ => { + // + // replace() returns the modified string, so we do a separate + // match to get the actual count of the number of 'e's + // + count = [... _ . matchAll (/e/g)] . length; + // + // Do the replacement, and print the results. Print also + // the number of times 'e' appears. + // + process . stdout . write (_ . replace (/e/g, "E") + "\n" + count + "\n") +}) +; -- cgit From b56e9198031fa3bde98e608837856cf2e00cb18c Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 20 Jan 2021 12:42:08 +0100 Subject: Python solution for week 1/part 1 --- challenge-001/abigail/README.md | 1 + challenge-001/abigail/python/ch-1.py | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 challenge-001/abigail/python/ch-1.py diff --git a/challenge-001/abigail/README.md b/challenge-001/abigail/README.md index 2644f43e28..2d3c5ac4fb 100644 --- a/challenge-001/abigail/README.md +++ b/challenge-001/abigail/README.md @@ -11,6 +11,7 @@ Write a script to replace the character `e` with `E` in the string * [C](c/ch-1.c) * [Node.js](node/ch-1.js) * [Perl](perl/ch-1.pl) +* [Python](python/ch-1.py) ## [Challenge #2](https://perlweeklychallenge.org/blog/perl-weekly-challenge-001 diff --git a/challenge-001/abigail/python/ch-1.py b/challenge-001/abigail/python/ch-1.py new file mode 100644 index 0000000000..193586bcf6 --- /dev/null +++ b/challenge-001/abigail/python/ch-1.py @@ -0,0 +1,11 @@ +# +# See ../READE,md +# + +# +# Run as python ch-1.py < input-file +# +import fileinput + +for line in fileinput . input (): + print line . replace ("e", "E"), line . count ("e") -- cgit From fd4d8a047ba6b03e116f831b5bfff8b143925325 Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 20 Jan 2021 17:44:28 +0100 Subject: Bash solution for week 1/part 1 --- challenge-001/abigail/README.md | 1 + challenge-001/abigail/bash/ch-1.sh | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 challenge-001/abigail/bash/ch-1.sh diff --git a/challenge-001/abigail/README.md b/challenge-001/abigail/README.md index 2d3c5ac4fb..3900a1aec5 100644 --- a/challenge-001/abigail/README.md +++ b/challenge-001/abigail/README.md @@ -8,6 +8,7 @@ Write a script to replace the character `e` with `E` in the string ### Solutions * [AWK](awk/ch-1.awk) +* [Bash](bash/ch-1.sh) * [C](c/ch-1.c) * [Node.js](node/ch-1.js) * [Perl](perl/ch-1.pl) diff --git a/challenge-001/abigail/bash/ch-1.sh b/challenge-001/abigail/bash/ch-1.sh new file mode 100644 index 0000000000..7133f8ceb7 --- /dev/null +++ b/challenge-001/abigail/bash/ch-1.sh @@ -0,0 +1,5 @@ +while read line +do echo "${line//e/E}" # Replace all 'e's with 'E'; print result. + ees="${line//[^e]}" # Remove anything which is not an 'e'. + echo "${#ees}" # Print the number of the ees. +done -- cgit From 72dd0cfebf0dec78395dfd061e1a16d5f0bad872 Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 20 Jan 2021 17:58:46 +0100 Subject: Befunge-93 solution for week 1, part 1 --- challenge-001/abigail/README.md | 1 + challenge-001/abigail/befunge-93/ch-1.bf93 | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 challenge-001/abigail/befunge-93/ch-1.bf93 diff --git a/challenge-001/abigail/README.md b/challenge-001/abigail/README.md index 3900a1aec5..48426bd7c9 100644 --- a/challenge-001/abigail/README.md +++ b/challenge-001/abigail/README.md @@ -9,6 +9,7 @@ Write a script to replace the character `e` with `E` in the string ### Solutions * [AWK](awk/ch-1.awk) * [Bash](bash/ch-1.sh) +* [Befunge-93](befunge/ch-1.bf93) * [C](c/ch-1.c) * [Node.js](node/ch-1.js) * [Perl](perl/ch-1.pl) diff --git a/challenge-001/abigail/befunge-93/ch-1.bf93 b/challenge-001/abigail/befunge-93/ch-1.bf93 new file mode 100644 index 0000000000..5a37405b87 --- /dev/null +++ b/challenge-001/abigail/befunge-93/ch-1.bf93 @@ -0,0 +1,3 @@ +~:1+!#v_:"e"-!#v_>, + "E"+1$ < ^ +@,*25.< -- cgit From 2a82815dcdf88da94ef8324cc121ace86339bff8 Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 20 Jan 2021 19:53:37 +0100 Subject: lua solution for week 1, part 1 --- challenge-001/abigail/README.md | 1 + challenge-001/abigail/lua/ch-1.lua | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 challenge-001/abigail/lua/ch-1.lua diff --git a/challenge-001/abigail/README.md b/challenge-001/abigail/README.md index 48426bd7c9..bc34397097 100644 --- a/challenge-001/abigail/README.md +++ b/challenge-001/abigail/README.md @@ -11,6 +11,7 @@ Write a script to replace the character `e` with `E` in the string * [Bash](bash/ch-1.sh) * [Befunge-93](befunge/ch-1.bf93) * [C](c/ch-1.c) +* [lua](lua/ch-1.lua) * [Node.js](node/ch-1.js) * [Perl](perl/ch-1.pl) * [Python](python/ch-1.py) diff --git a/challenge-001/abigail/lua/ch-1.lua b/challenge-001/abigail/lua/ch-1.lua new file mode 100644 index 0000000000..2876669f0d --- /dev/null +++ b/challenge-001/abigail/lua/ch-1.lua @@ -0,0 +1,12 @@ +-- +-- See ../README.md +-- + +-- +-- Run as: lua ch-1.lua < input-file +-- + +for line in io . lines () do + line, count = string . gsub (line, "e", "E"); + io . write (line, "\n", count, "\n") +end -- cgit From e7a12efc66d478b7b5b8bb23f1604271280aa28c Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 20 Jan 2021 19:55:56 +0100 Subject: Fix formatting --- challenge-001/abigail/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/challenge-001/abigail/README.md b/challenge-001/abigail/README.md index bc34397097..fc72aca445 100644 --- a/challenge-001/abigail/README.md +++ b/challenge-001/abigail/README.md @@ -17,8 +17,7 @@ Write a script to replace the character `e` with `E` in the string * [Python](python/ch-1.py) -## [Challenge #2](https://perlweeklychallenge.org/blog/perl-weekly-challenge-001 -/#challenge-2) +## [Challenge #2](https://perlweeklychallenge.org/blog/perl-weekly-challenge-001/#challenge-2) Write a one-liner to solve the *FizzBuzz* problem and print the numbers `1` through `20`. However, any number divisible by `3` should -- cgit From 42daa52c482db159701b4cc5c22f611fae9abef7 Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 20 Jan 2021 20:24:39 +0100 Subject: Ruby solution for week 1, part 1 --- challenge-001/abigail/README.md | 1 + challenge-001/abigail/ruby/ch-1.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 challenge-001/abigail/ruby/ch-1.rb diff --git a/challenge-001/abigail/README.md b/challenge-001/abigail/README.md index fc72aca445..ccfa7e3869 100644 --- a/challenge-001/abigail/README.md +++ b/challenge-001/abigail/README.md @@ -15,6 +15,7 @@ Write a script to replace the character `e` with `E` in the string * [Node.js](node/ch-1.js) * [Perl](perl/ch-1.pl) * [Python](python/ch-1.py) +* [Ruby](ruby/ch-1.rb) ## [Challenge #2](https://perlweeklychallenge.org/blog/perl-weekly-challenge-001/#challenge-2) diff --git a/challenge-001/abigail/ruby/ch-1.rb b/challenge-001/abigail/ruby/ch-1.rb new file mode 100644 index 0000000000..c3491daf34 --- /dev/null +++ b/challenge-001/abigail/ruby/ch-1.rb @@ -0,0 +1,12 @@ +# +# See ../README.md +# + +# +# Run as: ruby ch-1.rb < input-file +# + +ARGF . each_line do |_| + puts _ . gsub "e", "E" + puts _ . count "e" +end -- cgit From 897c760a747fab4013c718d24468fbda8b90e80a Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 20 Jan 2021 20:26:14 +0100 Subject: Add some notes to README.md --- challenge-001/abigail/README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/challenge-001/abigail/README.md b/challenge-001/abigail/README.md index ccfa7e3869..d298cf91e0 100644 --- a/challenge-001/abigail/README.md +++ b/challenge-001/abigail/README.md @@ -6,6 +6,11 @@ Write a script to replace the character `e` with `E` in the string `"Perl Weekly Challenge"`. Also print the number of times the character `e` is found in the string. +### Note +We will not be assuming a fixed string. Instead, we read from STDIN, +and for each line read, we change the 'e' characters to 'E', and +count the number of time we encountered an 'e'. + ### Solutions * [AWK](awk/ch-1.awk) * [Bash](bash/ch-1.sh) -- cgit From 660c508c1f95db209dec26cfe84b9f197e9c7fde Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 21 Jan 2021 01:55:46 +0100 Subject: Perl solution for week 1, part 1 --- challenge-001/abigail/README.md | 5 +++++ challenge-001/abigail/perl/ch-2.pl | 27 +++++++++++++++++++++++++++ challenge-001/abigail/t/ctest.ini | 1 + challenge-001/abigail/t/input-2-1 | 1 + challenge-001/abigail/t/output-2-1.exp | 20 ++++++++++++++++++++ 5 files changed, 54 insertions(+) create mode 100644 challenge-001/abigail/perl/ch-2.pl create mode 100644 challenge-001/abigail/t/input-2-1 create mode 100644 challenge-001/abigail/t/output-2-1.exp diff --git a/challenge-001/abigail/README.md b/challenge-001/abigail/README.md index d298cf91e0..78d02e6d99 100644 --- a/challenge-001/abigail/README.md +++ b/challenge-001/abigail/README.md @@ -31,4 +31,9 @@ be replaced by the word `fizz` and any divisible by `5` by the word `buzz` Those numbers that are both divisible by `3` and `5` become `fizzbuzz`. +### Note +We will not be assuming a fixed upper bound. Instead, we read the +upper boad from STDIN. + ### Solutions +* [Perl](perl/ch-2.pl) diff --git a/challenge-001/abigail/perl/ch-2.pl b/challenge-001/abigail/perl/ch-2.pl new file mode 100644 index 0000000000..27521c71cb --- /dev/null +++ b/challenge-001/abigail/perl/ch-2.pl @@ -0,0 +1,27 @@ +#!/opt/perl/bin/perl + +use 5.032; + +use strict; +use warnings; +no warnings 'syntax'; + +use experimental 'signatures'; +use experimental 'lexical_subs'; + +# +# See ../README.md +# + +# +# Run as: perl ch-2.pl < input-file +# + +while (<>) { + foreach my $number (1 .. $_) { + say $number % 15 == 0 ? "fizzbuzz" + : $number % 5 == 0 ? "buzz" + : $number % 3 == 0 ? "fizz" + : $number + } +} diff --git a/challenge-001/abigail/t/ctest.ini b/challenge-001/abigail/t/ctest.ini index 158e3552c7..99cf66a245 100644 --- a/challenge-001/abigail/t/ctest.ini +++ b/challenge-001/abigail/t/ctest.ini @@ -1,3 +1,4 @@ [names] 1-1 = The challenge 1-2 = No e +2-1 = The Challenge diff --git a/challenge-001/abigail/t/input-2-1 b/challenge-001/abigail/t/input-2-1 new file mode 100644 index 0000000000..209e3ef4b6 --- /dev/null +++ b/challenge-001/abigail/t/input-2-1 @@ -0,0 +1 @@ +20 diff --git a/challenge-001/abigail/t/output-2-1.exp b/challenge-001/abigail/t/output-2-1.exp new file mode 100644 index 0000000000..aa03b8dd28 --- /dev/null +++ b/challenge-001/abigail/t/output-2-1.exp @@ -0,0 +1,20 @@ +1 +2 +fizz +4 +buzz +fizz +7 +8 +fizz +buzz +11 +fizz +13 +14 +fizzbuzz +16 +17 +fizz +19 +buzz -- cgit From 1980959c4af89bd63dcfec1d727cb7f4479289cc Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 21 Jan 2021 02:12:24 +0100 Subject: AWK solution for week 1, part 2 --- challenge-001/abigail/README.md | 1 + challenge-001/abigail/awk/ch-2.awk | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 challenge-001/abigail/awk/ch-2.awk diff --git a/challenge-001/abigail/README.md b/challenge-001/abigail/README.md index 78d02e6d99..15a8939c56 100644 --- a/challenge-001/abigail/README.md +++ b/challenge-001/abigail/README.md @@ -36,4 +36,5 @@ We will not be assuming a fixed upper bound. Instead, we read the upper boad from STDIN. ### Solutions +* [AWK](awk/ch-2.awk) * [Perl](perl/ch-2.pl) diff --git a/challenge-001/abigail/awk/ch-2.awk b/challenge-001/abigail/awk/ch-2.awk new file mode 100644 index 0000000000..23f8dff855 --- /dev/null +++ b/challenge-001/abigail/awk/ch-2.awk @@ -0,0 +1,16 @@ +# +# See ../README.md +# + +# +# Run as: awk -f ch-2.awk < input-file +# + +{ + for (i = 1; i <= $0; i ++) { + print (i % 15 == 0) ? "fizzbuzz" \ + : (i % 5 == 0) ? "buzz" \ + : (i % 3 == 0) ? "fizz" \ + : i + } +} -- cgit From ee75a3aa066730d009accd0cb61a08de18e3877e Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 21 Jan 2021 02:13:01 +0100 Subject: Examples for week 1, part 2 --- challenge-001/abigail/t/ctest.ini | 1 + challenge-001/abigail/t/input-2-2 | 1 + challenge-001/abigail/t/output-2-2.exp | 100 +++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 challenge-001/abigail/t/input-2-2 create mode 100644 challenge-001/abigail/t/output-2-2.exp diff --git a/challenge-001/abigail/t/ctest.ini b/challenge-001/abigail/t/ctest.ini index 99cf66a245..8cee909e1e 100644 --- a/challenge-001/abigail/t/ctest.ini +++ b/challenge-001/abigail/t/ctest.ini @@ -2,3 +2,4 @@ 1-1 = The challenge 1-2 = No e 2-1 = The Challenge +2-2 = Regular upper bound diff --git a/challenge-001/abigail/t/input-2-2 b/challenge-001/abigail/t/input-2-2 new file mode 100644 index 0000000000..29d6383b52 --- /dev/null +++ b/challenge-001/abigail/t/input-2-2 @@ -0,0 +1 @@ +100 diff --git a/challenge-001/abigail/t/output-2-2.exp b/challenge-001/abigail/t/output-2-2.exp new file mode 100644 index 0000000000..27e9a38fd3 --- /dev/null +++ b/challenge-001/abigail/t/output-2-2.exp @@ -0,0 +1,100 @@ +1 +2 +fizz +4 +buzz +fizz +7 +8 +fizz +buzz +11 +fizz +13 +14 +fizzbuzz +16 +17 +fizz +19 +buzz +fizz +22 +23 +fizz +buzz +26 +fizz +28 +29 +fizzbuzz +31 +32 +fizz +34 +buzz +fizz +37 +38 +fizz +buzz +41 +fizz +43 +44 +fizzbuzz +46 +47 +fizz +49 +buzz +fizz +52 +53 +fizz +buzz +56 +fizz +58 +59 +fizzbuzz +61 +62 +fizz +64 +buzz +fizz +67 +68 +fizz +buzz +71 +fizz +73 +74 +fizzbuzz +76 +77 +fizz +79 +buzz +fizz +82 +83 +fizz +buzz +86 +fizz +88 +89 +fizzbuzz +91 +92 +fizz +94 +buzz +fizz +97 +98 +fizz +buzz -- cgit From 40778af70849939a2e2b22345e19e0fc53cb22b4 Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 21 Jan 2021 12:07:42 +0100 Subject: C solution for week 1, part 1 --- challenge-001/abigail/README.md | 1 + challenge-001/abigail/c/ch-2.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 challenge-001/abigail/c/ch-2.c diff --git a/challenge-001/abigail/README.md b/challenge-001/abigail/README.md index 15a8939c56..666f65dbf5 100644 --- a/challenge-001/abigail/README.md +++ b/challenge-001/abigail/README.md @@ -37,4 +37,5 @@ upper boad from STDIN. ### Solutions * [AWK](awk/ch-2.awk) +* [C](c/ch-2.c) * [Perl](perl/ch-2.pl) diff --git a/challenge-001/abigail/c/ch-2.c b/challenge-001/abigail/c/ch-2.c new file mode 100644 index 0000000000..4c72835827 --- /dev/null +++ b/challenge-001/abigail/c/ch-2.c @@ -0,0 +1,30 @@ +# include +# include +# include + +/* + * See ../README.md + */ + +/* + * Run as: cc -o ch-2.o cc-2.c; ./ch-2.o < input-file + */ + +int main (void) { + char * line = NULL; + size_t len = 0; + size_t strlen; + + while ((strlen = getline (&line, &len, stdin)) != -1) { + int max = atoi (line); + for (int i = 1; i <= max; i ++) { + if (i % 15 == 0) {printf ("%s\n", "fizzbuzz"); continue;} + if (i % 5 == 0) {printf ("%s\n", "buzz"); continue;} + if (i % 3 == 0) {printf ("%s\n", "fizz"); continue;} + printf ("%d\n", i); + } + } + free (line); + + return (0); +} -- cgit From 545b8c1620c1bca8f3cb718b27e8c47000cb199f Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 21 Jan 2021 12:17:29 +0100 Subject: lua solution for week 1, part 1 --- challenge-001/abigail/lua/ch-2.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 challenge-001/abigail/lua/ch-2.lua diff --git a/challenge-001/abigail/lua/ch-2.lua b/challenge-001/abigail/lua/ch-2.lua new file mode 100644 index 0000000000..749cdcd444 --- /dev/null +++ b/challenge-001/abigail/lua/ch-2.lua @@ -0,0 +1,25 @@ +-- +-- See ../README.md +-- + +-- +-- Run as: lua ch-2.lua < input-file +-- + +for line in io . lines () do + for i = 1, line do + if i % 15 == 0 + then + out = "fizzbuzz" + elseif i % 5 == 0 + then + out = "buzz" + elseif i % 3 == 0 + then + out = "fizz" + else + out = i + end + io . write (out, "\n") + end +end -- cgit From 2ac009d785d6de33796d8aa4b91977be85da0f13 Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 21 Jan 2021 12:41:59 +0100 Subject: Node.js solution for week 1, part 1 --- challenge-001/abigail/README.md | 2 ++ challenge-001/abigail/node/ch-2.js | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 challenge-001/abigail/node/ch-2.js diff --git a/challenge-001/abigail/README.md b/challenge-001/abigail/README.md index 666f65dbf5..114774d0b1 100644 --- a/challenge-001/abigail/README.md +++ b/challenge-001/abigail/README.md @@ -38,4 +38,6 @@ upper boad from STDIN. ### Solutions * [AWK](awk/ch-2.awk) * [C](c/ch-2.c) +* [lua](lua/ch-2.lua) +* [Node.js](node/ch-2.js) * [Perl](perl/ch-2.pl) diff --git a/challenge-001/abigail/node/ch-2.js b/challenge-001/abigail/node/ch-2.js new file mode 100644 index 0000000000..41155714f8 --- /dev/null +++ b/challenge-001/abigail/node/ch-2.js @@ -0,0 +1,21 @@ +// +// See ../README.md +// + +// +// Run as: node ch-1.js < input-file +// + + require ("fs") +. readFileSync (0) // Read all. +. toString () // Turn it into a string. +. split ("\n") // Split on newlines. +. filter (_ => _ . length) // Filter out empty lines. +. map (_ => { + for (let i = 1; i <= +_; i ++) { + console . log (i % 15 == 0 ? "fizzbuzz" + : i % 5 == 0 ? "buzz" + : i % 3 == 0 ? "fizz" + : i) + } +}); -- cgit From 85175e35ba99094aff82b4b21cdd7defde020f4e Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 21 Jan 2021 12:48:45 +0100 Subject: Bash solution for week 1, part 1 --- challenge-001/abigail/README.md | 1 + challenge-001/abigail/bash/ch-2.sh | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 challenge-001/abigail/bash/ch-2.sh diff --git a/challenge-001/abigail/README.md b/challenge-001/abigail/README.md index 114774d0b1..eb8bcb2229 100644 --- a/challenge-001/abigail/README.md +++ b/challenge-001/abigail/README.md @@ -37,6 +37,7 @@ upper boad from STDIN. ### Solutions * [AWK](awk/ch-2.awk) +* [Bash](bash/ch-2.sh) * [C](c/ch-2.c) * [lua](lua/ch-2.lua) * [Node.js](node/ch-2.js) diff --git a/challenge-001/abigail/bash/ch-2.sh b/challenge-001/abigail/bash/ch-2.sh new file mode 100644 index 0000000000..b81a0b0414 --- /dev/null +++ b/challenge-001/abigail/bash/ch-2.sh @@ -0,0 +1,24 @@ +# +# See ../README.md +# + +# +# Run as: bash ch-1.sh < input-file +# + +while read max +do for ((i = 1; i <= $max; i ++)) + do + out=$i + if (($i % 3 == 0)) + then out="fizz" + fi + if (($i % 5 == 0)) + then out="buzz" + fi + if (($i % 15 == 0)) + then out="fizzbuzz" + fi + echo $out + done +done -- cgit From 72557b3172bec25ae35f036a177332ccd913c143 Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 21 Jan 2021 12:57:33 +0100 Subject: Python solution for week 1, part 2 --- challenge-001/abigail/README.md | 1 + challenge-001/abigail/python/ch-2.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 challenge-001/abigail/python/ch-2.py diff --git a/challenge-001/abigail/README.md b/challenge-001/abigail/README.md index eb8bcb2229..213e656761 100644 --- a/challenge-001/abigail/README.md +++ b/challenge-001/abigail/README.md @@ -42,3 +42,4 @@ upper boad from STDIN. * [lua](lua/ch-2.lua) * [Node.js](node/ch-2.js) * [Perl](perl/ch-2.pl) +* [Python](python/ch-2.py) diff --git a/challenge-001/abigail/python/ch-2.py b/challenge-001/abigail/python/ch-2.py new file mode 100644 index 0000000000..9e93cb08e2 --- /dev/null +++ b/challenge-001/abigail/python/ch-2.py @@ -0,0 +1,16 @@ +# +# See ../READ.md +# + +# +# Run as python ch-2.py < input-file +# + +import fileinput + +for max in fileinput . input (): + for i in range (1, int (max) + 1): + print "fizzbuzz" if i % 15 == 0 else\ + "buzz" if i % 5 == 0 else\ + "fizz" if i % 3 == 0 else\ + i -- cgit From 1d8d6c61378d7c0599c8f08916124b0fadf96c5c Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 21 Jan 2021 13:05:22 +0100 Subject: Add comment --- challenge-001/abigail/t/ctest.ini | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/challenge-001/abigail/t/ctest.ini b/challenge-001/abigail/t/ctest.ini index 8cee909e1e..abca6977af 100644 --- a/challenge-001/abigail/t/ctest.ini +++ b/challenge-001/abigail/t/ctest.ini @@ -1,3 +1,7 @@ +# +# Configuration file for running tests, using ctest. +# See https://github.com/Abigail/Misc/blob/master/ctest +# [names] 1-1 = The challenge 1-2 = No e -- cgit From ac8e3891e332af9360eea6ead8b8b96a053a54ae Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 21 Jan 2021 14:34:54 +0100 Subject: Ruby solution for week 1, part 1 --- challenge-001/abigail/README.md | 1 + challenge-001/abigail/ruby/ch-2.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 challenge-001/abigail/ruby/ch-2.rb diff --git a/challenge-001/abigail/README.md b/challenge-001/abigail/README.md index 213e656761..e070d16c3f 100644 --- a/challenge-001/abigail/README.md +++ b/challenge-001/abigail/README.md @@ -43,3 +43,4 @@ upper boad from STDIN. * [Node.js](node/ch-2.js) * [Perl](perl/ch-2.pl) * [Python](python/ch-2.py) +* [Ruby](ruby/ch-2.rb) diff --git a/challenge-001/abigail/ruby/ch-2.rb b/challenge-001/abigail/ruby/ch-2.rb new file mode 100644 index 0000000000..4d68cd1cfa --- /dev/null +++ b/challenge-001/abigail/ruby/ch-2.rb @@ -0,0 +1,16 @@ +# +# See ../README.md +# + +# +# Run as: ruby ch-2.rb < input-file +# + +ARGF . each_line do |_| + for i in 1 .. _ . to_i do + puts i % 15 == 0 ? "fizzbuzz" + : i % 5 == 0 ? "buzz" + : i % 3 == 0 ? "fizz" + : i + end +end -- cgit From 6172b5279612e72e5480ecc2ca6f13fa55d2cf8f Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 21 Jan 2021 15:04:38 +0100 Subject: Befunge-93 solution for week 1, part 2 --- challenge-001/abigail/README.md | 1 + challenge-001/abigail/befunge-93/ch-2.bf93 | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 challenge-001/abigail/befunge-93/ch-2.bf93 diff --git a/challenge-001/abigail/README.md b/challenge-001/abigail/README.md index e070d16c3f..941614e09a 100644 --- a/challenge-001/abigail/README.md +++ b/challenge-001/abigail/README.md @@ -38,6 +38,7 @@ upper boad from STDIN. ### Solutions * [AWK](awk/ch-2.awk) * [Bash](bash/ch-2.sh) +* [Befunge-93](befunge-93/ch-2.bf93) * [C](c/ch-2.c) * [lua](lua/ch-2.lua) * [Node.js](node/ch-2.js) diff --git a/challenge-001/abigail/befunge-93/ch-2.bf93 b/challenge-001/abigail/befunge-93/ch-2.bf93 new file mode 100644 index 0000000000..66349eeb9c --- /dev/null +++ b/challenge-001/abigail/befunge-93/ch-2.bf93 @@ -0,0 +1,9 @@ +v >v +& >:5%| +1 > : 3 % | ++>:11g-| +1 @ +1^+1<,*52<.: < +>p0 ^ ^ ,,,,"buzz" < + |%5:,,,,"fizz"< + > ^ -- cgit From 0f5c21ad90c5f91fe51b3f053edac74e420ff536 Mon Sep 17 00:00:00 2001 From: Abigail Date: Sat, 23 Jan 2021 22:02:02 +0100 Subject: Use the 'readline' module to iterate over the input. --- challenge-096/abigail/node/ch-1.js | 30 +++++++++++++++++------------- challenge-096/abigail/node/ch-2.js | 20 ++++++++++++-------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/challenge-096/abigail/node/ch-1.js b/challenge-096/abigail/node/ch-1.js index b31524a686..cbc7e56d60 100644 --- a/challenge-096/abigail/node/ch-1.js +++ b/challenge-096/abigail/node/ch-1.js @@ -1,15 +1,19 @@ +#!/usr/local/bin/node + // -// Read STDIN. Split on newlines, filter out empty lines, then call "main". -// - require ("fs") -. readFileSync (0) // Read all. -. toString () // Turn it into a string. -. split ("\n") // Split on newlines. -. filter (_ => _ . length) // Filter out empty lines. -. map (_ => console . log (_ . trim () // Remove leading - // and trailing - // whitespace. - . split (/\s+/) // split ... - . reverse () // reverse ... - . join (" "))) // and recombine. +// See ../README.md +// + +// +// Run as: node ch-1.js < input-file +// + +require ('readline') +. createInterface ({input: process . stdin}) +. on ('line', _ => console . log (_ . trim () // Remove leading + // and trailing + // whitespace. + . split (/\s+/) // split ... + . reverse () // reverse ... + . join (" "))) // and recombine. ; diff --git a/challenge-096/abigail/node/ch-2.js b/challenge-096/abigail/node/ch-2.js index 8423ab96b8..59079c4cad 100644 --- a/challenge-096/abigail/node/ch-2.js +++ b/challenge-096/abigail/node/ch-2.js @@ -1,13 +1,17 @@ +#!/usr/local/bin/node + +// +// See ../README.md // -// Read STDIN. Split on newlines, filter out empty lines, then call "main". + // - require ("fs") -. readFileSync (0) // Read all. -. toString () // Turn it into a string. -. split ("\n") // Split on newlines. -. filter (_ => _ . length) // Filter out empty lines. -. map (_ => console . log (LevenshteinDistance (_ . trim () - . split (/\s+/)))) +// Run as: node ch-2.js < input-file +// + +require ('readline') +. createInterface ({input: process . stdin}) +. on ('line', _ => console . log (LevenshteinDistance (_ . trim () + . split (/\s+/)))) ; // -- cgit