From 36399aa2e618874a0b86780f49a49fe9cc13e389 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 5 Apr 2021 17:49:38 +0200 Subject: Initial README for week 107 --- challenge-107/abigail/README.md | 122 +++++++++++++--------------------------- 1 file changed, 39 insertions(+), 83 deletions(-) diff --git a/challenge-107/abigail/README.md b/challenge-107/abigail/README.md index 3b4bc6fcf4..3f6636e813 100644 --- a/challenge-107/abigail/README.md +++ b/challenge-107/abigail/README.md @@ -1,108 +1,64 @@ # Solution by Abigail -## [Maximum Gap](https://perlweeklychallenge.org/blog/perl-weekly-challenge-106/#TASK1) +## [Self-descriptive Numbers](https://perlweeklychallenge.org/blog/perl-weekly-challenge-107/#TASK1) -You are given an array of integers `@N`. +Write a script to display the first three self-descriptive numbers. +As per [wikipedia](https://en.wikipedia.org/wiki/Self-descriptive_number), +the definition of Self-descriptive Number is -Write a script to display the maximum difference between two -successive elements once the array is sorted. +> In mathematics, a self-descriptive number is an integer `m` that in a +> given base `b` is `b` digits long in which each digit `d` at position `n` +> (the most significant digit being at position 0 and the least +> significant at position `b - 1`) counts how many instances of +> digit `n` are in `m`. -If the array contains only `1` element then display `0`. - -### Examples +### Example ~~~~ -Input: @N = (2, 9, 3, 5) -Output: 4 + 1210 is a four-digit self-descriptive number: -Input: @N = (1, 3, 8, 2, 0) -Output: 5 + position 0 has value 1 i.e. there is only one 0 in the number + position 1 has value 2 i.e. there are two 1 in the number + position 2 has value 1 i.e. there is only one 2 in the number + position 3 has value 0 i.e. there is no 3 in the number +~~~~ -Input: @N = (5) -Output: 0 +### Output +~~~~ + 1210, 2020, 21200 ~~~~ ### Solutions -* [GNU AWK](awk/ch-1.gawk) -* [Bash](perl/ch-1.sh) -* [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) -* [Ruby](ruby/ch-1.rb) ### Blog -[Perl Weekly Challenge 106: Maximum Gap](https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-106-1.html) - -## [Decimal String](https://perlweeklychallenge.org/blog/perl-weekly-challenge-106/#TASK2) -You are given numerator and denominator i.e. `$N` and `$D`. - -Write a script to convert the fraction into decimal string. If the -fractional part is recurring then put it in parenthesis. - -### Examples -~~~~ -Input: $N = 1, $D = 3 -Output: "0.(3)" +## [List Methods](https://perlweeklychallenge.org/blog/perl-weekly-challenge-107/#TASK2) -Input: $N = 1, $D = 2 -Output: "0.5" +Write a script to list methods of a package/class. -Input: $N = 5, $D = 66 -Output: "0.0(75)" +### Example +Given the package: ~~~~ +package Calc; -### Notes +use strict; +use warnings; -We are assuming the numerator is non-negative, and the denominator -is positive. Dealing with signs is left as an exercise to the reader. - -We're creation the decimal expansion of the fraction `$N / $D` -by performing long division. - -First, we calculate the part before the decimal point, by -doing integer division of `$N / $D`. -We're then left to do division of `$N' / $D`, where `$N'` initially -is `$N % $D`. -We then repeatedly find new digits by calculating the integer -division of `(10 * $N' / $D)` (which gives us a new digit in the -decimal expansion), and then setting `$N' = 10 * $N' % $D`. -The fraction will have a finite decimal expansion if during the -process `$N'` becomes `0`. Otherwise, it repeats, and it repeats -as soon as have a `$N'` which we've already seen. By the pidgeon -hole principle, this cannot take more then $D steps. -To calculate the repeating part, we keep track of how far we -were in calculating the expansion for which `$N'`. +sub new { bless {}, shift; } +sub add { } +sub mul { } +sub div { } +1; ~~~~ - 22/7 \0.318 - 0 int (7 / 22) == 0, so 0 before decimal point - -- - 7 N = N % D - 66 3 * D - -- - 4 N = (10 * N) % D <--+ - 22 1 * D | - -- | Same, so '18' - 18 N = (10 * N) % D | is the repeating - 176 8 * D | part - --- | - 4 N = (10 * N) % D <--+ +Output: +~~~~ +BEGIN +mul +div +new +add ~~~~ - -This implementation is based on the [one given on -Wikipedia](https://en.wikipedia.org/wiki/Repeating_decimal). - ### Solutions -* [AWK](perl/ch-2.awk) -* [Bash](bash/ch-2.sh) -* [C](c/ch-2.c) -* [Lua](lua/ch-2.lua) -* [Node.js](node/ch-2.js) -* [Perl](perl/ch-2.pl) -* [Python](python/ch-2.py) -* [Ruby](ruby/ch-2.rb) ### Blog -[Perl Weekly Challenge 106: Decimal String](https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-106-2.html) + -- cgit From e0b831c882f7a9ae9b26272abe678319d5d13523 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 5 Apr 2021 18:46:08 +0200 Subject: Tests for week 107, part 1 --- challenge-107/abigail/t/ctest.ini | 8 ++++++++ challenge-107/abigail/t/input-1-1 | 0 challenge-107/abigail/t/output-1-1.exp | 1 + 3 files changed, 9 insertions(+) create mode 100644 challenge-107/abigail/t/ctest.ini create mode 100644 challenge-107/abigail/t/input-1-1 create mode 100644 challenge-107/abigail/t/output-1-1.exp diff --git a/challenge-107/abigail/t/ctest.ini b/challenge-107/abigail/t/ctest.ini new file mode 100644 index 0000000000..2b2795a72b --- /dev/null +++ b/challenge-107/abigail/t/ctest.ini @@ -0,0 +1,8 @@ +[names] +1-1 = Fixed output + +[1-1] +no_input = 1 + +[1-1/sed] +no_input = 0 diff --git a/challenge-107/abigail/t/input-1-1 b/challenge-107/abigail/t/input-1-1 new file mode 100644 index 0000000000..e69de29bb2 diff --git a/challenge-107/abigail/t/output-1-1.exp b/challenge-107/abigail/t/output-1-1.exp new file mode 100644 index 0000000000..0de25823a2 --- /dev/null +++ b/challenge-107/abigail/t/output-1-1.exp @@ -0,0 +1 @@ +1210, 2020, 21200 -- cgit From 95bb5450871518fe504ddf77399a99d1a33fb2f2 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 5 Apr 2021 18:46:59 +0200 Subject: Perl solution for week 107, part 1 --- challenge-107/abigail/README.md | 1 + challenge-107/abigail/perl/ch-1.pl | 76 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 challenge-107/abigail/perl/ch-1.pl diff --git a/challenge-107/abigail/README.md b/challenge-107/abigail/README.md index 3f6636e813..5fb591753d 100644 --- a/challenge-107/abigail/README.md +++ b/challenge-107/abigail/README.md @@ -27,6 +27,7 @@ the definition of Self-descriptive Number is ~~~~ ### Solutions +* [Perl](perl/ch-1.pl) ### Blog diff --git a/challenge-107/abigail/perl/ch-1.pl b/challenge-107/abigail/perl/ch-1.pl new file mode 100644 index 0000000000..e747f40ef8 --- /dev/null +++ b/challenge-107/abigail/perl/ch-1.pl @@ -0,0 +1,76 @@ +#!/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-1.pl +# + +# +# This is a trivial exercise -- as all exercises are which do not +# take any input, and which have a fixed output. +# +# This exercise is so trivial, we don't even have to head to the OEIS +# to download the wanted numbers. We can easily derive what the +# first numbers are. +# +# Note the following observations for self-descriptive numbers in +# a given base b: +# +# 1) The number has exactly b digits (we don't count leading 0s) +# 2) For all digits d, 0 <= d < b. +# 3) The last digit must be a 0 +# 4) The leading digit must be greater than 0. +# 5) No digit can be b - 1. +# 6) The sum of all the digits is b. +# +# From 2) it follows there is no self-descriptive number in base 1. +# From 3) and 4) it follows that if there is a self-descriptive +# number in base 2 it must be "10". But 5) prohibits this. +# From 1) - 5) it follows that any self-descriptive number in base 3 +# has be of the form "1.0". From 6), it follows that such a number +# must be "120", but since we don't have two 1's in the number, it +# is not self-descriptive. +# +# For base 4, the leading digit must be a 1 or a 2. If the first digit +# is a 1, the number is of the form "1ab0", where a != 0, b != 0, +# and a + b == 3. a cannot be 1, as that would imply the number +# contains just one 1, but "1120" contains two 1s. "1210", however, +# is a self-descriptive number, and this is the first self-descriptive +# number. If the first digit is a 2, out of the other three digits, +# two have to be 0 (of which one is the last one), and hence, the +# other has to be 2. The pen-ultimate digit cannot be 0 (as the number +# has at least one 2), leaving us with "2020". And this is self-descriptive. +# +# For base 5, possible leading digits are 1, 2, and 3. +# If the leading digit is a 1, there can only be one 0, and we know +# this must be the last digit. Which means the next three digits are +# all non-zero, and sum to 4. Which means the next three digits are +# 1, 1, and 2. But that means the number contains four 1s, but the +# number does not contain a 4. +# If the leading digit is a 3, there is only one non-zero in the next +# digits, and this must be a 2. But that leaves no way to describe +# the number of 3s. +# If the leading digits is a 2, of the next four numbers, two are 0 +# (including the last one), and two are non-zero. Those two non-zero +# numbers must add to 3, which means they are 1 and 2. This means the +# third digit (describing the number of 2s) must be 2, and the second +# digit (describing the number of 1s), must be 1. And "21200" is a +# self-describing number. +# +# Which means, we now have the first three self-describing numbers: +# "1210", "2020", "21200". +# + +say "1210, 2020, 21200"; -- cgit From cc171c4fb31c6f7ce4fdd02dfb25e3b1608aecf7 Mon Sep 17 00:00:00 2001 From: Abigail Date: Tue, 6 Apr 2021 12:17:35 +0200 Subject: AWK, Bash, C, Lua, Node.js, Python, and Ruby solution for week 107, part 1 --- challenge-107/abigail/README.md | 8 ++++++++ challenge-107/abigail/awk/ch-1.awk | 13 +++++++++++++ challenge-107/abigail/bash/ch-1.sh | 11 +++++++++++ challenge-107/abigail/befunge-93/ch-1.bf93 | 2 ++ challenge-107/abigail/c/ch-1.c | 15 +++++++++++++++ challenge-107/abigail/lua/ch-1.lua | 11 +++++++++++ challenge-107/abigail/node/ch-1.js | 11 +++++++++++ challenge-107/abigail/python/ch-1.py | 11 +++++++++++ challenge-107/abigail/ruby/ch-1.rb | 11 +++++++++++ 9 files changed, 93 insertions(+) create mode 100644 challenge-107/abigail/awk/ch-1.awk create mode 100644 challenge-107/abigail/bash/ch-1.sh create mode 100644 challenge-107/abigail/befunge-93/ch-1.bf93 create mode 100644 challenge-107/abigail/c/ch-1.c create mode 100644 challenge-107/abigail/lua/ch-1.lua create mode 100644 challenge-107/abigail/node/ch-1.js create mode 100644 challenge-107/abigail/python/ch-1.py create mode 100644 challenge-107/abigail/ruby/ch-1.rb diff --git a/challenge-107/abigail/README.md b/challenge-107/abigail/README.md index 5fb591753d..623f2c81c7 100644 --- a/challenge-107/abigail/README.md +++ b/challenge-107/abigail/README.md @@ -27,7 +27,15 @@ the definition of Self-descriptive Number is ~~~~ ### Solutions +* [AWK](awk/ch-1.awk) +* [Bash](bash/ch-1.awk) +* [Befunge-93](befunge-93/ch-1.bf93) +* [C](c/ch-1.c) +* [Lua](lua/ch-1.lua) +* [Node.js](lua/ch-1.js) * [Perl](perl/ch-1.pl) +* [Python](python/ch-1.py) +* [Ruby](ruby/ch-1.rb) ### Blog diff --git a/challenge-107/abigail/awk/ch-1.awk b/challenge-107/abigail/awk/ch-1.awk new file mode 100644 index 0000000000..cd8a87a7dc --- /dev/null +++ b/challenge-107/abigail/awk/ch-1.awk @@ -0,0 +1,13 @@ +#!/usr/bin/awk + +# +# See ../README.md +# + +# +# Run as: awk -f ch-1.awk +# + +BEGIN { + print "1210, 2020, 21200" +} diff --git a/challenge-107/abigail/bash/ch-1.sh b/challenge-107/abigail/bash/ch-1.sh new file mode 100644 index 0000000000..133a606068 --- /dev/null +++ b/challenge-107/abigail/bash/ch-1.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +# +# See ../README.md +# + +# +# Run as: bash ch-1.sh < input-file +# + +echo "1210, 2020, 21200" diff --git a/challenge-107/abigail/befunge-93/ch-1.bf93 b/challenge-107/abigail/befunge-93/ch-1.bf93 new file mode 100644 index 0000000000..67043917cf --- /dev/null +++ b/challenge-107/abigail/befunge-93/ch-1.bf93 @@ -0,0 +1,2 @@ +, ^ diff --git a/challenge-107/abigail/c/ch-1.c b/challenge-107/abigail/c/ch-1.c new file mode 100644 index 0000000000..edda83dced --- /dev/null +++ b/challenge-107/abigail/c/ch-1.c @@ -0,0 +1,15 @@ +# include +# include +# include + +/* + * See ../README.md + */ + +/* + * Run as: cc -o ch-1.o ch-1.c; ./ch-1.o + */ + +int main (void) { + printf ("%s\n", "1210, 2020, 21200"); +} diff --git a/challenge-107/abigail/lua/ch-1.lua b/challenge-107/abigail/lua/ch-1.lua new file mode 100644 index 0000000000..42017becfb --- /dev/null +++ b/challenge-107/abigail/lua/ch-1.lua @@ -0,0 +1,11 @@ +#!/opt/local/bin/lua + +-- +-- See ../README.md +-- + +-- +-- Run as: lua ch-1.lua +-- + +print ("1210, 2020, 21200") diff --git a/challenge-107/abigail/node/ch-1.js b/challenge-107/abigail/node/ch-1.js new file mode 100644 index 0000000000..6216ffe749 --- /dev/null +++ b/challenge-107/abigail/node/ch-1.js @@ -0,0 +1,11 @@ +#!/usr/local/bin/node + +// +// See ../README.md +// + +// +// Run as: node ch-1.js +// + +console . log ("1210, 2020, 21200") diff --git a/challenge-107/abigail/python/ch-1.py b/challenge-107/abigail/python/ch-1.py new file mode 100644 index 0000000000..c413e9f903 --- /dev/null +++ b/challenge-107/abigail/python/ch-1.py @@ -0,0 +1,11 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-1.py +# + +print ("1210, 2020, 21200") diff --git a/challenge-107/abigail/ruby/ch-1.rb b/challenge-107/abigail/ruby/ch-1.rb new file mode 100644 index 0000000000..3057dbc35d --- /dev/null +++ b/challenge-107/abigail/ruby/ch-1.rb @@ -0,0 +1,11 @@ +#!/usr/bin/ruby + +# +# See ../README.md +# + +# +# Run as: ruby ch-1.rb +# + +puts ("1210, 2020, 21200") -- cgit From 486ba0ac2e35ca779eb249eae39ef9ed19e1b9b5 Mon Sep 17 00:00:00 2001 From: Abigail Date: Tue, 6 Apr 2021 12:50:37 +0200 Subject: BASIC, bc, Cobol, csh, Erlang, Forth, Fortran, and Pascal solutions for week 107, part 1 --- challenge-107/abigail/README.md | 8 ++++++++ challenge-107/abigail/basic/ch-1.bas | 9 +++++++++ challenge-107/abigail/bc/ch-1.bc | 10 ++++++++++ challenge-107/abigail/cobol/ch-1.cb | 14 ++++++++++++++ challenge-107/abigail/csh/ch-1.csh | 11 +++++++++++ challenge-107/abigail/erlang/ch-1.erl | 15 +++++++++++++++ challenge-107/abigail/forth/ch-1.fs | 5 +++++ challenge-107/abigail/fortran/ch-1.f90 | 12 ++++++++++++ challenge-107/abigail/pascal/ch-1.p | 13 +++++++++++++ 9 files changed, 97 insertions(+) create mode 100644 challenge-107/abigail/basic/ch-1.bas create mode 100644 challenge-107/abigail/bc/ch-1.bc create mode 100644 challenge-107/abigail/cobol/ch-1.cb create mode 100644 challenge-107/abigail/csh/ch-1.csh create mode 100644 challenge-107/abigail/erlang/ch-1.erl create mode 100644 challenge-107/abigail/forth/ch-1.fs create mode 100644 challenge-107/abigail/fortran/ch-1.f90 create mode 100644 challenge-107/abigail/pascal/ch-1.p diff --git a/challenge-107/abigail/README.md b/challenge-107/abigail/README.md index 623f2c81c7..035449ae0f 100644 --- a/challenge-107/abigail/README.md +++ b/challenge-107/abigail/README.md @@ -29,10 +29,18 @@ the definition of Self-descriptive Number is ### Solutions * [AWK](awk/ch-1.awk) * [Bash](bash/ch-1.awk) +* [BASIC](basic/ch-1.bas) +* [bc](bc/ch-1.bc) * [Befunge-93](befunge-93/ch-1.bf93) * [C](c/ch-1.c) +* [Cobol](cobol/ch-1.cb) +* [Csh](csh/ch-1.csh) +* [Erlang](erlang/ch-1.erl) +* [Forth](forth/ch-1.fs) +* [Fortran](fortran/ch-1.fs) * [Lua](lua/ch-1.lua) * [Node.js](lua/ch-1.js) +* [Pascal](pascal/ch-1.pl) * [Perl](perl/ch-1.pl) * [Python](python/ch-1.py) * [Ruby](ruby/ch-1.rb) diff --git a/challenge-107/abigail/basic/ch-1.bas b/challenge-107/abigail/basic/ch-1.bas new file mode 100644 index 0000000000..6f0a11aabb --- /dev/null +++ b/challenge-107/abigail/basic/ch-1.bas @@ -0,0 +1,9 @@ +010 REM +020 REM See ../README.md +030 REM + +040 REM +050 REM Run as: basic ch-1.bas +060 REM + +100 PRINT "1210, 2020, 21200" diff --git a/challenge-107/abigail/bc/ch-1.bc b/challenge-107/abigail/bc/ch-1.bc new file mode 100644 index 0000000000..258f8a522d --- /dev/null +++ b/challenge-107/abigail/bc/ch-1.bc @@ -0,0 +1,10 @@ +# +# See ../README.md +# + +# +# Run as: bc ch-1.bc +# +"1210, 2020, 21200 +" +quit diff --git a/challenge-107/abigail/cobol/ch-1.cb b/challenge-107/abigail/cobol/ch-1.cb new file mode 100644 index 0000000000..c3be4e79a8 --- /dev/null +++ b/challenge-107/abigail/cobol/ch-1.cb @@ -0,0 +1,14 @@ +IDENTIFICATION DIVISION. +PROGRAM-ID. XXXX. + +*> +*> See ../README.md +*> + +*> +*> Run as: cobc -xF -o ch-1.o ch-1.cb; ./ch-1.o +*> + +PROCEDURE DIVISION. + DISPLAY "1210, 2020, 21200". + STOP RUN. diff --git a/challenge-107/abigail/csh/ch-1.csh b/challenge-107/abigail/csh/ch-1.csh new file mode 100644 index 0000000000..510f8e2ae4 --- /dev/null +++ b/challenge-107/abigail/csh/ch-1.csh @@ -0,0 +1,11 @@ +#!/bin/csh + +# +# See ../README.md +# + +# +# Run as: csh ch-1.csh +# + +echo "1210, 2020, 21200" diff --git a/challenge-107/abigail/erlang/ch-1.erl b/challenge-107/abigail/erlang/ch-1.erl new file mode 100644 index 0000000000..17abba2e3c --- /dev/null +++ b/challenge-107/abigail/erlang/ch-1.erl @@ -0,0 +1,15 @@ +% +% See ../README.md +% + +% +% Run as: ln ch-1.erl ch1.erl +% erl -compile ch1 +% erl -noshell -s ch1 main -s init stop +% + +-module (ch1). +-export ([main/0]). + +main () -> + io:fwrite ("1210, 2020, 21200\n"). diff --git a/challenge-107/abigail/forth/ch-1.fs b/challenge-107/abigail/forth/ch-1.fs new file mode 100644 index 0000000000..022fe0f6cc --- /dev/null +++ b/challenge-107/abigail/forth/ch-1.fs @@ -0,0 +1,5 @@ +\ +\ See ../README.md +\ + +.( 1210, 2020, 21200) diff --git a/challenge-107/abigail/fortran/ch-1.f90 b/challenge-107/abigail/fortran/ch-1.f90 new file mode 100644 index 0000000000..70a7ad8707 --- /dev/null +++ b/challenge-107/abigail/fortran/ch-1.f90 @@ -0,0 +1,12 @@ +! +! See ../README.md +! + +! +! Run as: gfortran -o ch-1.o ch-1.f90; ./ch-1.o +! + +program ch1 + implicit none + write(*, *) "1210, 2020, 21200" +end diff --git a/challenge-107/abigail/pascal/ch-1.p b/challenge-107/abigail/pascal/ch-1.p new file mode 100644 index 0000000000..b24ebeab57 --- /dev/null +++ b/challenge-107/abigail/pascal/ch-1.p @@ -0,0 +1,13 @@ +Program SelfDescribing; + +(* *) +(* See ../README.md *) +(* *) + +(* *) +(* Run as: fpc -och-1.out ch-1.p; ./ch-1.out *) +(* *) + +begin + writeln ('1210, 2020, 21200'); +end. -- cgit From 39caa8e6b7bcad824bcb8c00fbedd707fd2da998 Mon Sep 17 00:00:00 2001 From: Abigail Date: Tue, 6 Apr 2021 13:14:30 +0200 Subject: Go, Java, m4 and OCaml solutions for week 107, part 1 --- challenge-107/abigail/README.md | 4 ++++ challenge-107/abigail/go/ch-1.go | 15 +++++++++++++++ challenge-107/abigail/java/ch-1.java | 13 +++++++++++++ challenge-107/abigail/m4/ch-1.m4 | 1 + challenge-107/abigail/ocaml/ch-1.ml | 9 +++++++++ 5 files changed, 42 insertions(+) create mode 100644 challenge-107/abigail/go/ch-1.go create mode 100644 challenge-107/abigail/java/ch-1.java create mode 100644 challenge-107/abigail/m4/ch-1.m4 create mode 100644 challenge-107/abigail/ocaml/ch-1.ml diff --git a/challenge-107/abigail/README.md b/challenge-107/abigail/README.md index 035449ae0f..33b50becb3 100644 --- a/challenge-107/abigail/README.md +++ b/challenge-107/abigail/README.md @@ -38,8 +38,12 @@ the definition of Self-descriptive Number is * [Erlang](erlang/ch-1.erl) * [Forth](forth/ch-1.fs) * [Fortran](fortran/ch-1.fs) +* [Go](go/ch-1.go) +* [Java](java/ch-1.java) * [Lua](lua/ch-1.lua) +* [m4](m4/ch-1.m4) * [Node.js](lua/ch-1.js) +* [OCaml](ocaml/ch-1.ml) * [Pascal](pascal/ch-1.pl) * [Perl](perl/ch-1.pl) * [Python](python/ch-1.py) diff --git a/challenge-107/abigail/go/ch-1.go b/challenge-107/abigail/go/ch-1.go new file mode 100644 index 0000000000..9a75bbff46 --- /dev/null +++ b/challenge-107/abigail/go/ch-1.go @@ -0,0 +1,15 @@ +package main + +// +// See ../README.md +// + +// +// Run as: go run ch-1.go +// + +import "fmt" + +func main () { + fmt . Print ("1210, 2020, 21200\n") +} diff --git a/challenge-107/abigail/java/ch-1.java b/challenge-107/abigail/java/ch-1.java new file mode 100644 index 0000000000..40fe82dccb --- /dev/null +++ b/challenge-107/abigail/java/ch-1.java @@ -0,0 +1,13 @@ +// +// See ../README.md +// + +// +// Run as: ln ch-1.java ch1.java; javac ch1; java ch1 +// + +public class ch1 { + public static void main (String [] args) { + System . out . print ("1210, 2020, 21200\n"); + } +} diff --git a/challenge-107/abigail/m4/ch-1.m4 b/challenge-107/abigail/m4/ch-1.m4 new file mode 100644 index 0000000000..0de25823a2 --- /dev/null +++ b/challenge-107/abigail/m4/ch-1.m4 @@ -0,0 +1 @@ +1210, 2020, 21200 diff --git a/challenge-107/abigail/ocaml/ch-1.ml b/challenge-107/abigail/ocaml/ch-1.ml new file mode 100644 index 0000000000..53a9124d9a --- /dev/null +++ b/challenge-107/abigail/ocaml/ch-1.ml @@ -0,0 +1,9 @@ +(* *) +(* See ../README.md *) +(* *) + +(* *) +(* Run as: ocaml ch-1.ml *) +(* *) + +print_endline "1210, 2020, 21200"; -- cgit From 5cdc7168641203529fdef0708f6042c7608fe792 Mon Sep 17 00:00:00 2001 From: Abigail Date: Tue, 6 Apr 2021 13:32:47 +0200 Subject: PHP, R, Rexx, Scheme, sed, SQL, and Tcl solutions for week 107, part 1 --- challenge-107/abigail/README.md | 7 +++++++ challenge-107/abigail/php/ch-1.php | 11 +++++++++++ challenge-107/abigail/r/ch-1.r | 9 +++++++++ challenge-107/abigail/rexx/ch-1.rexx | 9 +++++++++ challenge-107/abigail/scheme/ch-1.scm | 9 +++++++++ challenge-107/abigail/sed/ch-1.sed | 12 ++++++++++++ challenge-107/abigail/sql/ch-1.sql | 9 +++++++++ challenge-107/abigail/t/input-1-1 | 1 + challenge-107/abigail/tcl/ch-1.tcl | 9 +++++++++ 9 files changed, 76 insertions(+) create mode 100644 challenge-107/abigail/php/ch-1.php create mode 100644 challenge-107/abigail/r/ch-1.r create mode 100644 challenge-107/abigail/rexx/ch-1.rexx create mode 100644 challenge-107/abigail/scheme/ch-1.scm create mode 100644 challenge-107/abigail/sed/ch-1.sed create mode 100644 challenge-107/abigail/sql/ch-1.sql create mode 100644 challenge-107/abigail/tcl/ch-1.tcl diff --git a/challenge-107/abigail/README.md b/challenge-107/abigail/README.md index 33b50becb3..5dcab2794d 100644 --- a/challenge-107/abigail/README.md +++ b/challenge-107/abigail/README.md @@ -46,8 +46,15 @@ the definition of Self-descriptive Number is * [OCaml](ocaml/ch-1.ml) * [Pascal](pascal/ch-1.pl) * [Perl](perl/ch-1.pl) +* [PHP](php/ch-1.pl) * [Python](python/ch-1.py) +* [R](r/ch-1.r) +* [Rexx](rexx/ch-1.rexx) * [Ruby](ruby/ch-1.rb) +* [Scheme](scheme/ch-1.scm) +* [sed](sed/ch-1.sed) +* [SQL](sql/ch-1.sql) +* [Tcl](tcl/ch-1.tcl) ### Blog diff --git a/challenge-107/abigail/php/ch-1.php b/challenge-107/abigail/php/ch-1.php new file mode 100644 index 0000000000..52646348a5 --- /dev/null +++ b/challenge-107/abigail/php/ch-1.php @@ -0,0 +1,11 @@ + diff --git a/challenge-107/abigail/r/ch-1.r b/challenge-107/abigail/r/ch-1.r new file mode 100644 index 0000000000..b14a917727 --- /dev/null +++ b/challenge-107/abigail/r/ch-1.r @@ -0,0 +1,9 @@ +# +# See ../README.md +# + +# +# Run as: Rscript ch-1.r +# + +cat ("1210, 2020, 21200\n") diff --git a/challenge-107/abigail/rexx/ch-1.rexx b/challenge-107/abigail/rexx/ch-1.rexx new file mode 100644 index 0000000000..de95f9d159 --- /dev/null +++ b/challenge-107/abigail/rexx/ch-1.rexx @@ -0,0 +1,9 @@ +/* + * See ../README.md + */ + +/* + * Run as: rexx ch-1.rexx + */ + +say "1210, 2020, 21200" diff --git a/challenge-107/abigail/scheme/ch-1.scm b/challenge-107/abigail/scheme/ch-1.scm new file mode 100644 index 0000000000..e06fdfe6ec --- /dev/null +++ b/challenge-107/abigail/scheme/ch-1.scm @@ -0,0 +1,9 @@ +;;; +;;; See ../README.md +;;; + +;;; +;;; Run as: guile --no-auto-compile ch-1.scm +;;; + +(display "1210, 2020, 21200\n") diff --git a/challenge-107/abigail/sed/ch-1.sed b/challenge-107/abigail/sed/ch-1.sed new file mode 100644 index 0000000000..899e5c5cfd --- /dev/null +++ b/challenge-107/abigail/sed/ch-1.sed @@ -0,0 +1,12 @@ +# +# See ../README.md +# + +# +# Run as: sed -f ch-1.sed < input-file +# +# For each line in the input file, we write the first three +# self-describing numbers. +# + +s/.*/1210, 2020, 21200/ diff --git a/challenge-107/abigail/sql/ch-1.sql b/challenge-107/abigail/sql/ch-1.sql new file mode 100644 index 0000000000..ebb1f4b1ce --- /dev/null +++ b/challenge-107/abigail/sql/ch-1.sql @@ -0,0 +1,9 @@ +-- +-- See ../README.md +-- + +-- +-- Run as: sqlite3 < ch-1.sql +-- + +SELECT "1210, 2020, 21200"; diff --git a/challenge-107/abigail/t/input-1-1 b/challenge-107/abigail/t/input-1-1 index e69de29bb2..8b13789179 100644 --- a/challenge-107/abigail/t/input-1-1 +++ b/challenge-107/abigail/t/input-1-1 @@ -0,0 +1 @@ + diff --git a/challenge-107/abigail/tcl/ch-1.tcl b/challenge-107/abigail/tcl/ch-1.tcl new file mode 100644 index 0000000000..59daf96335 --- /dev/null +++ b/challenge-107/abigail/tcl/ch-1.tcl @@ -0,0 +1,9 @@ +# +# See ../README.md +# + +# +# Run as: tclsh ch-1.tcl +# + +puts "1210, 2020, 21200" -- cgit From 9941d85738c02e09f56b1479b94e008b0af8e1c0 Mon Sep 17 00:00:00 2001 From: Abigail Date: Tue, 6 Apr 2021 13:44:08 +0200 Subject: PostScript solution for week 107, part 1 --- challenge-107/abigail/README.md | 1 + challenge-107/abigail/postscript/ch-1.ps | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 challenge-107/abigail/postscript/ch-1.ps diff --git a/challenge-107/abigail/README.md b/challenge-107/abigail/README.md index 5dcab2794d..e7eb5e02bd 100644 --- a/challenge-107/abigail/README.md +++ b/challenge-107/abigail/README.md @@ -47,6 +47,7 @@ the definition of Self-descriptive Number is * [Pascal](pascal/ch-1.pl) * [Perl](perl/ch-1.pl) * [PHP](php/ch-1.pl) +* [PostScript](postscript/ch-1.ps) * [Python](python/ch-1.py) * [R](r/ch-1.r) * [Rexx](rexx/ch-1.rexx) diff --git a/challenge-107/abigail/postscript/ch-1.ps b/challenge-107/abigail/postscript/ch-1.ps new file mode 100644 index 0000000000..3ad53dd1f7 --- /dev/null +++ b/challenge-107/abigail/postscript/ch-1.ps @@ -0,0 +1,10 @@ +%!PS +% +% See ../README.md +% + +% +% Run as: ps2ascii ch-1.ps +% + +(1210, 2020, 21200) = -- cgit From d9e6a738049b9f95eee9daec882f04e60e82a609 Mon Sep 17 00:00:00 2001 From: Abigail Date: Tue, 6 Apr 2021 17:35:11 +0200 Subject: Perl solution for week 107, part 2 --- challenge-107/abigail/README.md | 1 + challenge-107/abigail/perl/ch-2.pl | 59 ++++++++++++++++++++++++++++++++++ challenge-107/abigail/t/Calc.pm | 11 +++++++ challenge-107/abigail/t/ctest.ini | 6 ++++ challenge-107/abigail/t/input-2-1 | 0 challenge-107/abigail/t/output-2-1.exp | 5 +++ 6 files changed, 82 insertions(+) create mode 100644 challenge-107/abigail/perl/ch-2.pl create mode 100644 challenge-107/abigail/t/Calc.pm create mode 100644 challenge-107/abigail/t/input-2-1 create mode 100644 challenge-107/abigail/t/output-2-1.exp diff --git a/challenge-107/abigail/README.md b/challenge-107/abigail/README.md index e7eb5e02bd..ffb6203bbc 100644 --- a/challenge-107/abigail/README.md +++ b/challenge-107/abigail/README.md @@ -88,6 +88,7 @@ add ~~~~ ### Solutions +* [Perl](perl/ch-2.pl) ### Blog diff --git a/challenge-107/abigail/perl/ch-2.pl b/challenge-107/abigail/perl/ch-2.pl new file mode 100644 index 0000000000..a3194ba7de --- /dev/null +++ b/challenge-107/abigail/perl/ch-2.pl @@ -0,0 +1,59 @@ +#!/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 module +# +# where 'module' is the name of the module to be inspected, and +# this module is to be found in a file named 'module.pm' (with :: +# replaced by '/'), somewhere in @INC. +# + +# +# Get the module name from the command line. +# +my $module = shift; + +# +# Load the module. +# +eval "use $module; 1" or die "Failed to load $module.pm: $@"; + +# +# Create a reference to the symbol table of the module. +# +my $symbol_table = do {no strict 'refs'; \%{$module . "::"}}; + +# +# Iterate over the symbols in the name space, and print out +# which symbols have a code ref entry in the type glob. +# (The symbol table maps symbols to type globs). +# +foreach my $symbol (keys %$symbol_table) { + say $symbol if *{$$symbol_table {$symbol}} {CODE}; +} + +# +# Print BEGIN. This is not a method. While there is a entry +# named "BEGIN" in the symbol table, the type glob does not +# have CODE entry. $module -> can ("BEGIN") fails as well. +# +# We only print "BEGIN" so we pass the one test given for +# this exercise. +# +# We will *NOT* do the same for END, INIT, CHECK, nor UNITCHECK. +# One piece of madness is enough. +# +say "BEGIN" if $$symbol_table {BEGIN}; diff --git a/challenge-107/abigail/t/Calc.pm b/challenge-107/abigail/t/Calc.pm new file mode 100644 index 0000000000..4123090fde --- /dev/null +++ b/challenge-107/abigail/t/Calc.pm @@ -0,0 +1,11 @@ +package Calc; + +use strict; +use warnings; + +sub new { bless {}, shift; } +sub add { } +sub mul { } +sub div { } + +1; diff --git a/challenge-107/abigail/t/ctest.ini b/challenge-107/abigail/t/ctest.ini index 2b2795a72b..3a493dec84 100644 --- a/challenge-107/abigail/t/ctest.ini +++ b/challenge-107/abigail/t/ctest.ini @@ -1,8 +1,14 @@ [names] 1-1 = Fixed output +2-1 = Given example [1-1] no_input = 1 [1-1/sed] no_input = 0 + +[2-1/perl] +exe_args = -It +args = %RUN_FILE Calc +sort = 1 diff --git a/challenge-107/abigail/t/input-2-1 b/challenge-107/abigail/t/input-2-1 new file mode 100644 index 0000000000..e69de29bb2 diff --git a/challenge-107/abigail/t/output-2-1.exp b/challenge-107/abigail/t/output-2-1.exp new file mode 100644 index 0000000000..fdb52d0469 --- /dev/null +++ b/challenge-107/abigail/t/output-2-1.exp @@ -0,0 +1,5 @@ +BEGIN +add +div +mul +new -- cgit From e69195920db440fcc88761e9c902de7f185c078e Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 7 Apr 2021 19:57:42 +0200 Subject: Notes for week 107, part 1. --- challenge-107/abigail/README.md | 61 +++++++++++++++++++++ challenge-107/abigail/perl/ch-1.pl | 105 +++++++++++++++++++------------------ 2 files changed, 116 insertions(+), 50 deletions(-) diff --git a/challenge-107/abigail/README.md b/challenge-107/abigail/README.md index ffb6203bbc..c753fe6fbd 100644 --- a/challenge-107/abigail/README.md +++ b/challenge-107/abigail/README.md @@ -26,6 +26,67 @@ the definition of Self-descriptive Number is 1210, 2020, 21200 ~~~~ +### Notes + +This is a trivial exercise -- as all exercises are which do not +take any input, and which have a fixed output. Fixed output +challenges are boring -- unless there's another condition (golf, +for instance). + +This exercise is so trivial, we don't even have to head to the OEIS +to download the wanted numbers, as the expected output is stated +in the exercise. + +So, all we need to do is print three numbers, separated by commas. + +The easiest way would be to just do what the challenge demands +from us, and print the output as given. + +A slightly less easy way would be to head over the given +[Wikipedia page](https://en.wikipedia.org/wiki/Self-descriptive_number) +(or the [OEIS](https://oeis.org) for that matter), copy the first +three numbers, and print those out. + +But those solutions no doubt will cause scorn in two weeks, +when the review comes out. It's all "advice about the code is the thing". + +But that raises the question, what is the code which is wanted? +You could generate all the numbers of length `b` in base `b`, while +increasing `b`, test them for being self-descriptive, and print +the first three numbers found. + +My advice about brute force code when there is a more efficient way: +Don't ever do that. + +If we just imagine the Wikipedia page didn't list any self-descriptive +numbers, and Neil Sloane has forgotten to pay the fee for the OEIS +domain, so it was taken off-line, then it's still easy to determine +the first three self-descriptive numbers -- no code required. + +Given the following observations for a self-descriptive number `N` in base `b`: +* `N` has `b` digits, and does not start with a `0`. +* The sum of the digits of `N` is `b`. +* No digit of `N` equals `b - 1`. +* The last digit of `N` is `0`. +* If `b > 4`, then `N` does not start with a `1`. +* If `b > 4`, then `N` does not start with `b - 2`. + +From that, it's easy to determine that: +* There are no self-descriptive numbers in any base below `4`. +* A self-descriptive number in base `4` must start with a `1` or `2`. And + end with a `0`. If it starts with a `1`, the middle digits are `1` and `2`. + If it starts with a `2`, the middle digits are `0` and `2`. Both `1210`, + and `2020"`are self-descriptive numbers. +* A self-descriptive number in base `5` must start with a `2`, and end + with a `0`. The three middle digits must be `0`, `1`, and `2`. `21200` + is a self-descriptive number. + +(For a more detailed derivation, with all the details filled in, see [the blog +post](https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-107-1.html)) + +But this still makes this challenge a glorified `Hello, World!` +program, as there is no useful code to write to generate the numbers. + ### Solutions * [AWK](awk/ch-1.awk) * [Bash](bash/ch-1.awk) diff --git a/challenge-107/abigail/perl/ch-1.pl b/challenge-107/abigail/perl/ch-1.pl index e747f40ef8..763a0c54fa 100644 --- a/challenge-107/abigail/perl/ch-1.pl +++ b/challenge-107/abigail/perl/ch-1.pl @@ -19,58 +19,63 @@ use experimental 'lexical_subs'; # # This is a trivial exercise -- as all exercises are which do not -# take any input, and which have a fixed output. +# take any input, and which have a fixed output. Fixed output +# challenges are boring -- unless there's another condition (golf, +# for instance). # # This exercise is so trivial, we don't even have to head to the OEIS -# to download the wanted numbers. We can easily derive what the -# first numbers are. -# -# Note the following observations for self-descriptive numbers in -# a given base b: -# -# 1) The number has exactly b digits (we don't count leading 0s) -# 2) For all digits d, 0 <= d < b. -# 3) The last digit must be a 0 -# 4) The leading digit must be greater than 0. -# 5) No digit can be b - 1. -# 6) The sum of all the digits is b. -# -# From 2) it follows there is no self-descriptive number in base 1. -# From 3) and 4) it follows that if there is a self-descriptive -# number in base 2 it must be "10". But 5) prohibits this. -# From 1) - 5) it follows that any self-descriptive number in base 3 -# has be of the form "1.0". From 6), it follows that such a number -# must be "120", but since we don't have two 1's in the number, it -# is not self-descriptive. -# -# For base 4, the leading digit must be a 1 or a 2. If the first digit -# is a 1, the number is of the form "1ab0", where a != 0, b != 0, -# and a + b == 3. a cannot be 1, as that would imply the number -# contains just one 1, but "1120" contains two 1s. "1210", however, -# is a self-descriptive number, and this is the first self-descriptive -# number. If the first digit is a 2, out of the other three digits, -# two have to be 0 (of which one is the last one), and hence, the -# other has to be 2. The pen-ultimate digit cannot be 0 (as the number -# has at least one 2), leaving us with "2020". And this is self-descriptive. -# -# For base 5, possible leading digits are 1, 2, and 3. -# If the leading digit is a 1, there can only be one 0, and we know -# this must be the last digit. Which means the next three digits are -# all non-zero, and sum to 4. Which means the next three digits are -# 1, 1, and 2. But that means the number contains four 1s, but the -# number does not contain a 4. -# If the leading digit is a 3, there is only one non-zero in the next -# digits, and this must be a 2. But that leaves no way to describe -# the number of 3s. -# If the leading digits is a 2, of the next four numbers, two are 0 -# (including the last one), and two are non-zero. Those two non-zero -# numbers must add to 3, which means they are 1 and 2. This means the -# third digit (describing the number of 2s) must be 2, and the second -# digit (describing the number of 1s), must be 1. And "21200" is a -# self-describing number. -# -# Which means, we now have the first three self-describing numbers: -# "1210", "2020", "21200". +# to download the wanted numbers, as the expected output is stated +# in the exercise. +# +# So, all we need to do is print three numbers, separated by commas. +# +# The easiest way would be to just do what the challenge demands +# from us, and print the output as given. +# +# A slightly less easy way would be to head over the given Wikipedia +# page (or the OEIS for that matter), copy the first three numbers, +# and print those out. +# +# But those solutions no doubt will cause scorn in two weeks, +# when the review comes out. It's all "advice about the code is the thing". +# +# But that raises the question, what is the code which is wanted? +# You could generate all the numbers of length b in base b, while +# increasing b, test them for being self-descriptive, and print +# the first three numbers found. +# +# My advice about brute force code when there is a more efficient way: +# Don't ever do that. +# +# If we just imagine the Wikipedia page didn't list any self-descriptive +# numbers, and Neil Sloane has forgotten to pay the fee for the OEIS +# domain, so it was taken off-line, then it's still easy to determine +# the first three self-descriptive numbers -- no code required. +# +# Given the following observations for a self-descriptive number N in base b: +# - N has b digits, and does not start with a 0. +# - The sum of the digits of N is b. +# - No digit of N equals b - 1. +# - The last digit of N is 0. +# - If b > 4, then N does not start with a 1. +# - If b > 4, then N does not start with b - 2. +# +# From that, it's easy to determine that: +# - There are no self-descriptive numbers in any base below 4. +# - A self-descriptive number in base 4 must start with a 1 or 2. And +# end with a 0. If it starts with a 1, the middle digits are 1 and 2. +# If it starts with a 2, the middle digits are 0 and 2. Both "1210", +# and "2020" are self-descriptive numbers. +# - A self-descriptive number in base 5 must start with a 2, and end +# with a 0. The three middle digits must be 0, 1, and 2. "21200" +# is a self-descriptive number. +# +# (For a more detailed derivation, with all the details filled in, +# see the blog post at +# https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-107-1.html) +# +# But this still makes this challenge a glorified "Hello, World!" +# program, as there is no useful code to write to generate the numbers. # say "1210, 2020, 21200"; -- cgit From 189236de703a94cf94663b83dea35c69fd4c0b84 Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 8 Apr 2021 20:40:14 +0200 Subject: Link to blog post for week 107, part 1 --- challenge-107/abigail/README.md | 1 + challenge-107/abigail/blog.txt | 1 + 2 files changed, 2 insertions(+) create mode 100644 challenge-107/abigail/blog.txt diff --git a/challenge-107/abigail/README.md b/challenge-107/abigail/README.md index c753fe6fbd..5bd25310d7 100644 --- a/challenge-107/abigail/README.md +++ b/challenge-107/abigail/README.md @@ -119,6 +119,7 @@ program, as there is no useful code to write to generate the numbers. * [Tcl](tcl/ch-1.tcl) ### Blog +[Perl Weekly Challenge 107: Self-descriptive Numbers](https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-107-1.html) ## [List Methods](https://perlweeklychallenge.org/blog/perl-weekly-challenge-107/#TASK2) diff --git a/challenge-107/abigail/blog.txt b/challenge-107/abigail/blog.txt new file mode 100644 index 0000000000..d0209f073a --- /dev/null +++ b/challenge-107/abigail/blog.txt @@ -0,0 +1 @@ +https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-107-1.html -- cgit From 6a593c51919ce50284673882f2b301bfde57d020 Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 8 Apr 2021 20:40:37 +0200 Subject: Remark about AUTOLOAD --- challenge-107/abigail/perl/ch-2.pl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/challenge-107/abigail/perl/ch-2.pl b/challenge-107/abigail/perl/ch-2.pl index a3194ba7de..bc74d27e4c 100644 --- a/challenge-107/abigail/perl/ch-2.pl +++ b/challenge-107/abigail/perl/ch-2.pl @@ -57,3 +57,10 @@ foreach my $symbol (keys %$symbol_table) { # One piece of madness is enough. # say "BEGIN" if $$symbol_table {BEGIN}; + +# +# Note that if the module contains an AUTOLOAD method, one could argue +# the module contains any possible method. We decide to not do that. +# + +__END__ -- cgit From fafed8e98f280132fc442d11508e810700ab4a08 Mon Sep 17 00:00:00 2001 From: Abigail Date: Fri, 9 Apr 2021 16:38:16 +0200 Subject: More tests for week 107, part 2 --- challenge-107/abigail/t/Multi.pm | 13 +++++++++++++ challenge-107/abigail/t/Test.pm | 13 +++++++++++++ challenge-107/abigail/t/ctest.ini | 12 ++++++++++++ challenge-107/abigail/t/input-2-2 | 0 challenge-107/abigail/t/input-2-3 | 0 challenge-107/abigail/t/output-2-2.exp | 2 ++ challenge-107/abigail/t/output-2-3.exp | 2 ++ 7 files changed, 42 insertions(+) create mode 100644 challenge-107/abigail/t/Multi.pm create mode 100644 challenge-107/abigail/t/Test.pm create mode 100644 challenge-107/abigail/t/input-2-2 create mode 100644 challenge-107/abigail/t/input-2-3 create mode 100644 challenge-107/abigail/t/output-2-2.exp create mode 100644 challenge-107/abigail/t/output-2-3.exp diff --git a/challenge-107/abigail/t/Multi.pm b/challenge-107/abigail/t/Multi.pm new file mode 100644 index 0000000000..68c54ca995 --- /dev/null +++ b/challenge-107/abigail/t/Multi.pm @@ -0,0 +1,13 @@ +package Multi; + +use strict; +use warnings; +use 5.010; + +our $Multi = 2; +our @Multi = (3, 4, 5); +our %Multi = (6 => 7, 8 => 9); +open Multi, "<", "does not exist"; +sub Multi { } + +1; diff --git a/challenge-107/abigail/t/Test.pm b/challenge-107/abigail/t/Test.pm new file mode 100644 index 0000000000..39615fcd82 --- /dev/null +++ b/challenge-107/abigail/t/Test.pm @@ -0,0 +1,13 @@ +package Test; + +use strict; +use warnings; +use 5.010; + +our $scalar = 1; +our @array = (1, 2, 3); +our %hash = (1 => 2); +open FH, "<", "does not exist"; +sub sub_routine { } + +1; diff --git a/challenge-107/abigail/t/ctest.ini b/challenge-107/abigail/t/ctest.ini index 3a493dec84..3e5daaf228 100644 --- a/challenge-107/abigail/t/ctest.ini +++ b/challenge-107/abigail/t/ctest.ini @@ -1,6 +1,8 @@ [names] 1-1 = Fixed output 2-1 = Given example +2-2 = Ignore non sub-routines in the slots +2-3 = Deal with slots with multiple entries [1-1] no_input = 1 @@ -12,3 +14,13 @@ no_input = 0 exe_args = -It args = %RUN_FILE Calc sort = 1 + +[2-2/perl] +exe_args = -It +args = %RUN_FILE Test +sort = 1 + +[2-3/perl] +exe_args = -It +args = %RUN_FILE Multi +sort = 1 diff --git a/challenge-107/abigail/t/input-2-2 b/challenge-107/abigail/t/input-2-2 new file mode 100644 index 0000000000..e69de29bb2 diff --git a/challenge-107/abigail/t/input-2-3 b/challenge-107/abigail/t/input-2-3 new file mode 100644 index 0000000000..e69de29bb2 diff --git a/challenge-107/abigail/t/output-2-2.exp b/challenge-107/abigail/t/output-2-2.exp new file mode 100644 index 0000000000..1a1dff1275 --- /dev/null +++ b/challenge-107/abigail/t/output-2-2.exp @@ -0,0 +1,2 @@ +BEGIN +sub_routine diff --git a/challenge-107/abigail/t/output-2-3.exp b/challenge-107/abigail/t/output-2-3.exp new file mode 100644 index 0000000000..7158e56e04 --- /dev/null +++ b/challenge-107/abigail/t/output-2-3.exp @@ -0,0 +1,2 @@ +BEGIN +Multi -- cgit From 7c398511d67d05283111bf310ee7156e1df8aa1e Mon Sep 17 00:00:00 2001 From: Abigail Date: Fri, 9 Apr 2021 19:26:59 +0200 Subject: Don't print BEGIN twice --- challenge-107/abigail/perl/ch-2.pl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/challenge-107/abigail/perl/ch-2.pl b/challenge-107/abigail/perl/ch-2.pl index bc74d27e4c..e87f8aef71 100644 --- a/challenge-107/abigail/perl/ch-2.pl +++ b/challenge-107/abigail/perl/ch-2.pl @@ -41,6 +41,10 @@ my $symbol_table = do {no strict 'refs'; \%{$module . "::"}}; # which symbols have a code ref entry in the type glob. # (The symbol table maps symbols to type globs). # +# Note that this only gives use the global methods, no lexical +# subroutines are found that way. Which is ok, as lexical +# subroutines are bound to their lexical scope - not the package. +# foreach my $symbol (keys %$symbol_table) { say $symbol if *{$$symbol_table {$symbol}} {CODE}; } @@ -56,7 +60,7 @@ foreach my $symbol (keys %$symbol_table) { # We will *NOT* do the same for END, INIT, CHECK, nor UNITCHECK. # One piece of madness is enough. # -say "BEGIN" if $$symbol_table {BEGIN}; +say "BEGIN" if $$symbol_table {BEGIN} && !*{$$symbol_table {BEGIN}} {CODE}; # # Note that if the module contains an AUTOLOAD method, one could argue -- cgit From a4b32a332cab68fc5f7c79b60ea8e956a34b755c Mon Sep 17 00:00:00 2001 From: Abigail Date: Fri, 9 Apr 2021 19:28:32 +0200 Subject: Link to blog for week 107, part 2 --- challenge-107/abigail/README.md | 1 + challenge-107/abigail/blog1.txt | 1 + 2 files changed, 2 insertions(+) create mode 100644 challenge-107/abigail/blog1.txt diff --git a/challenge-107/abigail/README.md b/challenge-107/abigail/README.md index 5bd25310d7..67392c9e54 100644 --- a/challenge-107/abigail/README.md +++ b/challenge-107/abigail/README.md @@ -153,4 +153,5 @@ add * [Perl](perl/ch-2.pl) ### Blog +[Perl Weekly Challenge 107: List Methods](https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-107-2.html) diff --git a/challenge-107/abigail/blog1.txt b/challenge-107/abigail/blog1.txt new file mode 100644 index 0000000000..ce4fb4cb33 --- /dev/null +++ b/challenge-107/abigail/blog1.txt @@ -0,0 +1 @@ +https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-107-2.html -- cgit