From 6b444c9324695fe56539797fad50792e6a3dc345 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 12 Apr 2021 13:52:35 +0200 Subject: README for week 108 --- challenge-108/abigail/README.md | 160 +++++----------------------------------- 1 file changed, 17 insertions(+), 143 deletions(-) diff --git a/challenge-108/abigail/README.md b/challenge-108/abigail/README.md index 67392c9e54..fca58964a2 100644 --- a/challenge-108/abigail/README.md +++ b/challenge-108/abigail/README.md @@ -1,157 +1,31 @@ -# Solution by Abigail -## [Self-descriptive Numbers](https://perlweeklychallenge.org/blog/perl-weekly-challenge-107/#TASK1) +# Solutions by Abigail +## [Locate Memory](https://perlweeklychallenge.org/blog/perl-weekly-challenge-108/#TASK1) -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 - -> 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`. - -### Example -~~~~ - 1210 is a four-digit self-descriptive number: - - 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 -~~~~ - -### Output -~~~~ - 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. +Write a script to declare a variable or constant and print it's +location in the memory. ### 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) -* [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) -* [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) -* [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 -[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) -Write a script to list methods of a package/class. -### Example -Given the package: -~~~~ -package Calc; +## [Bell Numbers](https://perlweeklychallenge.org/blog/perl-weekly-challenge-108/#TASK2) -use strict; -use warnings; +Write a script to display top 10 Bell Numbers. Please refer to +[wikipedia page](https://en.wikipedia.org/wiki/Bell_number) for +more informations. -sub new { bless {}, shift; } -sub add { } -sub mul { } -sub div { } - -1; -~~~~ -Output: -~~~~ -BEGIN -mul -div -new -add -~~~~ +### Example +* `B_0 = 1`, as you can only have one partition of zero element set +* `B_1 = 1`, as you can only have one partition of one element set {a}. +* `B_2 = 2`, `{a}{b}`, `{a,b}`. +* `B_3 = 5`, `{a}{b}{c}`, `{a,b}{c}`, `{a}{b,c}`, `{a,c}{b}`, `{a,b,c}`. +* `B_4 = 15`, `{a}{b}{c}{d}`, `{a,b,c,d}`, `{a,b}{c,d}`, `{a,c}{b,d}`, + `{a,d}{b,c}`, `{a,b}{c}{d}`, `{a,c}{b}{d}`, `{a,d}{b}{c}`, + `{b,c}{a}{d}`, `{b,d}{a}{c}`, `{c,d}{a}{b}`, `{a}{b,c,d}`, + `{b}{a,c,d}`, `{c}{a,b,d}`, `{d}{a,b,c}` ### Solutions -* [Perl](perl/ch-2.pl) ### Blog -[Perl Weekly Challenge 107: List Methods](https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-107-2.html) -- cgit From 59795d1335f1839d4a5ff8620f27100495448229 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 12 Apr 2021 13:52:57 +0200 Subject: Test files for week 108. --- challenge-108/abigail/t/ctest.ini | 11 +++++++++++ challenge-108/abigail/t/input-1-1 | 0 challenge-108/abigail/t/input-2-1 | 0 challenge-108/abigail/t/output-1-1.exp | 1 + challenge-108/abigail/t/output-2-1.exp | 1 + 5 files changed, 13 insertions(+) create mode 100644 challenge-108/abigail/t/ctest.ini create mode 100644 challenge-108/abigail/t/input-1-1 create mode 100644 challenge-108/abigail/t/input-2-1 create mode 100644 challenge-108/abigail/t/output-1-1.exp create mode 100644 challenge-108/abigail/t/output-2-1.exp diff --git a/challenge-108/abigail/t/ctest.ini b/challenge-108/abigail/t/ctest.ini new file mode 100644 index 0000000000..c6b6322f48 --- /dev/null +++ b/challenge-108/abigail/t/ctest.ini @@ -0,0 +1,11 @@ +# +# Configuration file for running tests, using ctest. +# See https://github.com/Abigail/Misc/blob/master/ctest +# + +[names] +1-1 = Memory address +2-1 = Fixed output + +[1-1] +no_input = 1 diff --git a/challenge-108/abigail/t/input-1-1 b/challenge-108/abigail/t/input-1-1 new file mode 100644 index 0000000000..e69de29bb2 diff --git a/challenge-108/abigail/t/input-2-1 b/challenge-108/abigail/t/input-2-1 new file mode 100644 index 0000000000..e69de29bb2 diff --git a/challenge-108/abigail/t/output-1-1.exp b/challenge-108/abigail/t/output-1-1.exp new file mode 100644 index 0000000000..0a4df1dcd2 --- /dev/null +++ b/challenge-108/abigail/t/output-1-1.exp @@ -0,0 +1 @@ +qr {[1-9][0-9]*} diff --git a/challenge-108/abigail/t/output-2-1.exp b/challenge-108/abigail/t/output-2-1.exp new file mode 100644 index 0000000000..52ad7f9d63 --- /dev/null +++ b/challenge-108/abigail/t/output-2-1.exp @@ -0,0 +1 @@ +1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147 -- cgit From 1d687ed1911a31f57ca6714cc85b4eacf78dfbfe Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 12 Apr 2021 13:54:12 +0200 Subject: Perl solution for week 108, part 1 --- challenge-108/abigail/README.md | 1 + challenge-108/abigail/perl/ch-1.pl | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 challenge-108/abigail/perl/ch-1.pl diff --git a/challenge-108/abigail/README.md b/challenge-108/abigail/README.md index fca58964a2..ef7fb8b526 100644 --- a/challenge-108/abigail/README.md +++ b/challenge-108/abigail/README.md @@ -5,6 +5,7 @@ Write a script to declare a variable or constant and print it's location in the memory. ### Solutions +* [Perl](perl/ch-1.pl) ### Blog diff --git a/challenge-108/abigail/perl/ch-1.pl b/challenge-108/abigail/perl/ch-1.pl new file mode 100644 index 0000000000..a7964cf3b4 --- /dev/null +++ b/challenge-108/abigail/perl/ch-1.pl @@ -0,0 +1,25 @@ +#!/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 +# + +# +# - A reference in numeric context gives the memory location +# - 0 is a constant +# + +say+0+\+0 -- cgit From f02c5746861535f4471879d33ff63759bbcd6e9a Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 12 Apr 2021 14:06:46 +0200 Subject: C solution for week 108, part 1 --- challenge-108/abigail/README.md | 1 + challenge-108/abigail/c/ch-1.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 challenge-108/abigail/c/ch-1.c diff --git a/challenge-108/abigail/README.md b/challenge-108/abigail/README.md index ef7fb8b526..98a4523d47 100644 --- a/challenge-108/abigail/README.md +++ b/challenge-108/abigail/README.md @@ -5,6 +5,7 @@ Write a script to declare a variable or constant and print it's location in the memory. ### Solutions +* [C](c/ch-1.c) * [Perl](perl/ch-1.pl) ### Blog diff --git a/challenge-108/abigail/c/ch-1.c b/challenge-108/abigail/c/ch-1.c new file mode 100644 index 0000000000..0d1ad208bf --- /dev/null +++ b/challenge-108/abigail/c/ch-1.c @@ -0,0 +1,21 @@ +# include +# include +# include + +/* + * See ../README.md + */ + +/* + * Run as: cc -o ch-1.o ch-1.c; ./ch-1.o + */ + +int main (void) { + int i; + printf ("%lld\n", (long long) &i); /* %p is specific for printing */ + /* memory addresses, but does this */ + /* using hex numbers. So we cast */ + /* the address to long long and */ + /* print that. */ + return (0); +} -- cgit From fa485e6665431156c33d7c7ad3fa17be1b54c596 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 12 Apr 2021 20:03:28 +0200 Subject: Perl solution for week 108, part 2 --- challenge-108/abigail/README.md | 1 + challenge-108/abigail/perl/ch-2.pl | 68 ++++++++++++++++++++++++++++++++++ challenge-108/abigail/t/ctest.ini | 21 +++++++++++ challenge-108/abigail/t/input-2-2 | 0 challenge-108/abigail/t/input-2-3 | 0 challenge-108/abigail/t/input-2-4 | 0 challenge-108/abigail/t/output-2-2.exp | 1 + challenge-108/abigail/t/output-2-3.exp | 1 + challenge-108/abigail/t/output-2-4.exp | 1 + 9 files changed, 93 insertions(+) create mode 100644 challenge-108/abigail/perl/ch-2.pl create mode 100644 challenge-108/abigail/t/input-2-2 create mode 100644 challenge-108/abigail/t/input-2-3 create mode 100644 challenge-108/abigail/t/input-2-4 create mode 100644 challenge-108/abigail/t/output-2-2.exp create mode 100644 challenge-108/abigail/t/output-2-3.exp create mode 100644 challenge-108/abigail/t/output-2-4.exp diff --git a/challenge-108/abigail/README.md b/challenge-108/abigail/README.md index 98a4523d47..bff5cad944 100644 --- a/challenge-108/abigail/README.md +++ b/challenge-108/abigail/README.md @@ -28,6 +28,7 @@ more informations. `{b}{a,c,d}`, `{c}{a,b,d}`, `{d}{a,b,c}` ### Solutions +* [Perl](perl/ch-2.pl) ### Blog diff --git a/challenge-108/abigail/perl/ch-2.pl b/challenge-108/abigail/perl/ch-2.pl new file mode 100644 index 0000000000..d89e32391e --- /dev/null +++ b/challenge-108/abigail/perl/ch-2.pl @@ -0,0 +1,68 @@ +#!/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 [plain|fetch|compute] +# +# +# Three solutions, depending on the command line argument: +# 1) We just print the first 10 Bell numbers. The simplest solution. +# 2) We fetch the first 10 Bell numbers from the OEIS. +# 3) We calculate the Bell numbers from the Bell triangle. +# + +my $COUNT = 10; + +my $TYPE_PLAIN = 0; +my $TYPE_FETCH = 1; +my $TYPE_COMPUTE = 2; + +my $type = $TYPE_PLAIN; # Default + $type = $TYPE_FETCH if @ARGV && $ARGV [0] eq "fetch"; + $type = $TYPE_COMPUTE if @ARGV && $ARGV [0] eq "compute"; + + +if ($type == $TYPE_PLAIN) { + say "1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147"; +} +elsif ($type == $TYPE_FETCH) { + use OEIS; + $, = ", "; + say oeis (110 => 10) +} +elsif ($type == $TYPE_COMPUTE) { + my $COUNT = 10; + + # + # Create Bell triangle (See https://en.wikipedia.org/wiki/Bell_triangle) + # The Bell numbers (starting from the second one), are on the + # right diagonal. + # + # The Bell triangle is defined as follows: + # Bell (0, 0) = 1 + # Bell (n, 0) = Bell (n - 1, n - 1), k > 0 + # Bell (n, m) = Bell (n, m - 1) + Bell (n - 1, m - 1), n > 0, m > 0 + # + my @bell = [1]; + for (my $x = 1; $x < $COUNT - 1; $x ++) { + $bell [$x] [0] = $bell [$x - 1] [-1]; + for (my $y = 1; $y <= $x; $y ++) { + $bell [$x] [$y] = $bell [$x] [$y - 1] + $bell [$x - 1] [$y - 1] + } + } + + $, = ", "; + say 1, map {$$_ [-1]} @bell; +} diff --git a/challenge-108/abigail/t/ctest.ini b/challenge-108/abigail/t/ctest.ini index c6b6322f48..1a6f8ee862 100644 --- a/challenge-108/abigail/t/ctest.ini +++ b/challenge-108/abigail/t/ctest.ini @@ -6,6 +6,27 @@ [names] 1-1 = Memory address 2-1 = Fixed output +2-2 = Fixed output/plain +2-3 = Fixed output/fetch +2-4 = Fixed output/compute [1-1] no_input = 1 + +[2-1/perl] +skip = "Not for Perl" + +[2-2,2-3,2-4] +skip = "Only for Perl" + +[2-2/perl] +skip = 0 +args = plain + +[2-3/perl] +skip = 0 +args = fetch + +[2-4/perl] +skip = 0 +args = compute diff --git a/challenge-108/abigail/t/input-2-2 b/challenge-108/abigail/t/input-2-2 new file mode 100644 index 0000000000..e69de29bb2 diff --git a/challenge-108/abigail/t/input-2-3 b/challenge-108/abigail/t/input-2-3 new file mode 100644 index 0000000000..e69de29bb2 diff --git a/challenge-108/abigail/t/input-2-4 b/challenge-108/abigail/t/input-2-4 new file mode 100644 index 0000000000..e69de29bb2 diff --git a/challenge-108/abigail/t/output-2-2.exp b/challenge-108/abigail/t/output-2-2.exp new file mode 100644 index 0000000000..52ad7f9d63 --- /dev/null +++ b/challenge-108/abigail/t/output-2-2.exp @@ -0,0 +1 @@ +1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147 diff --git a/challenge-108/abigail/t/output-2-3.exp b/challenge-108/abigail/t/output-2-3.exp new file mode 100644 index 0000000000..52ad7f9d63 --- /dev/null +++ b/challenge-108/abigail/t/output-2-3.exp @@ -0,0 +1 @@ +1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147 diff --git a/challenge-108/abigail/t/output-2-4.exp b/challenge-108/abigail/t/output-2-4.exp new file mode 100644 index 0000000000..52ad7f9d63 --- /dev/null +++ b/challenge-108/abigail/t/output-2-4.exp @@ -0,0 +1 @@ +1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147 -- cgit From 516d2bc425b97f36c8e79d7ec85b0b254274c1ca Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 14 Apr 2021 15:46:46 +0200 Subject: Fortran, Go, and Python solutions for week 108, part 1 --- challenge-108/abigail/README.md | 3 +++ challenge-108/abigail/fortran/ch-1.f90 | 13 +++++++++++++ challenge-108/abigail/go/ch-1.go | 16 ++++++++++++++++ challenge-108/abigail/python/ch-1.py | 11 +++++++++++ 4 files changed, 43 insertions(+) create mode 100644 challenge-108/abigail/fortran/ch-1.f90 create mode 100644 challenge-108/abigail/go/ch-1.go create mode 100644 challenge-108/abigail/python/ch-1.py diff --git a/challenge-108/abigail/README.md b/challenge-108/abigail/README.md index bff5cad944..fc4039982c 100644 --- a/challenge-108/abigail/README.md +++ b/challenge-108/abigail/README.md @@ -6,7 +6,10 @@ location in the memory. ### Solutions * [C](c/ch-1.c) +* [Fortran](fortran/ch-1.f90) +* [Go](go/ch-1.go) * [Perl](perl/ch-1.pl) +* [Python](python/ch-1.py) ### Blog diff --git a/challenge-108/abigail/fortran/ch-1.f90 b/challenge-108/abigail/fortran/ch-1.f90 new file mode 100644 index 0000000000..c55b81745e --- /dev/null +++ b/challenge-108/abigail/fortran/ch-1.f90 @@ -0,0 +1,13 @@ +! +! See ../README.md +! + +! +! Run as: gfortran -o ch-1.o ch-1.f90; ./ch-1.o +! + +program ch1 + implicit none + integer :: i + print *, loc(i) +end diff --git a/challenge-108/abigail/go/ch-1.go b/challenge-108/abigail/go/ch-1.go new file mode 100644 index 0000000000..fb3673f5f3 --- /dev/null +++ b/challenge-108/abigail/go/ch-1.go @@ -0,0 +1,16 @@ +package main + +// +// See ../README.md +// + +// +// Run as: go run ch-1.go +// + +import "fmt" + +func main () { + x := 0 + fmt . Printf ("%d\n", &x) +} diff --git a/challenge-108/abigail/python/ch-1.py b/challenge-108/abigail/python/ch-1.py new file mode 100644 index 0000000000..da3d6d2ced --- /dev/null +++ b/challenge-108/abigail/python/ch-1.py @@ -0,0 +1,11 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-1.py +# + +print (id (0)) -- cgit From c2df7ee9412915b09491cefb1ab9a16e3ccee76f Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 14 Apr 2021 19:30:21 +0200 Subject: AWK solution for week 108, part 2 --- challenge-108/abigail/README.md | 1 + challenge-108/abigail/awk/ch-2.awk | 32 ++++++++++++++++++++++++++++++++ challenge-108/abigail/t/ctest.ini | 8 ++++---- 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 challenge-108/abigail/awk/ch-2.awk diff --git a/challenge-108/abigail/README.md b/challenge-108/abigail/README.md index fc4039982c..b4b729933a 100644 --- a/challenge-108/abigail/README.md +++ b/challenge-108/abigail/README.md @@ -31,6 +31,7 @@ more informations. `{b}{a,c,d}`, `{c}{a,b,d}`, `{d}{a,b,c}` ### Solutions +* [AWK](awk/ch-2.awk) * [Perl](perl/ch-2.pl) ### Blog diff --git a/challenge-108/abigail/awk/ch-2.awk b/challenge-108/abigail/awk/ch-2.awk new file mode 100644 index 0000000000..96344e739e --- /dev/null +++ b/challenge-108/abigail/awk/ch-2.awk @@ -0,0 +1,32 @@ +#!/usr/bin/awk + +# +# See ../README.md +# + +# +# Run as: awk -f ch-2.awk [plain | compute] +# + +BEGIN { + COUNT = 10 + if (!ARGV [1] || ARGV [1] != "compute") { + printf "%s\n", "1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147" + } + else { + bell [1, 1] = 1 + for (x = 2; x < COUNT; x ++) { + bell [x, 1] = bell [x - 1, x - 1] + for (y = 2; y <= x; y ++) { + bell [x, y] = bell [x, y - 1] + bell [x - 1, y - 1] + } + } + printf "1" + for (x = 1; x < COUNT; x ++) { + printf ", %d", bell [x, x] + } + printf "\n" + } + delete ARGV +} + diff --git a/challenge-108/abigail/t/ctest.ini b/challenge-108/abigail/t/ctest.ini index 1a6f8ee862..0c513be6da 100644 --- a/challenge-108/abigail/t/ctest.ini +++ b/challenge-108/abigail/t/ctest.ini @@ -13,13 +13,13 @@ [1-1] no_input = 1 -[2-1/perl] -skip = "Not for Perl" +[2-1/perl,awk] +skip = "Not for this language" [2-2,2-3,2-4] skip = "Only for Perl" -[2-2/perl] +[2-2/perl,awk] skip = 0 args = plain @@ -27,6 +27,6 @@ args = plain skip = 0 args = fetch -[2-4/perl] +[2-4/perl,awk] skip = 0 args = compute -- cgit From 30bc53d420c654a6d8ddc159e0f604b7d84e28ba Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 14 Apr 2021 20:26:14 +0200 Subject: Bash solution for week 108, part 2 --- challenge-108/abigail/bash/ch-2.sh | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 challenge-108/abigail/bash/ch-2.sh diff --git a/challenge-108/abigail/bash/ch-2.sh b/challenge-108/abigail/bash/ch-2.sh new file mode 100644 index 0000000000..c74aff4bbe --- /dev/null +++ b/challenge-108/abigail/bash/ch-2.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +# +# See ../README.md +# + +# +# Run as: bash ch-2.sh +# + +set -f + +COUNT=10 + +function index () { + local x=$1 + local y=$2 + idx=$((COUNT * x + y)) +} + + +if [ "X$1" != "Xcompute" ] +then echo "1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147" +else bell[0]=1 + for ((x = 1; x < COUNT - 1; x ++)) + do index $x 0; i1=$idx + index $((x - 1)) $((x - 1)); i2=$idx + bell[$i1]=${bell[$i2]} + for ((y = 1; y <= x; y ++)) + do index $x $y; i1=$idx + index $x $((y - 1)); i2=$idx + index $((x - 1)) $((y - 1)); i3=$idx + bell[$i1]=$((bell[i2] + bell[i3])) + done + done + + printf "1" + for ((x = 0; x < COUNT - 1; x ++)) + do index $x $x; + printf ", %d" ${bell[$idx]} + done + echo +fi -- cgit From a47ab8a6afc5eb9843d2c97675ba2e18885d419b Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 14 Apr 2021 20:31:51 +0200 Subject: Befunge 93 solution for week 108, part 2 --- challenge-108/abigail/README.md | 4 +++- challenge-108/abigail/befunge-93/ch-2.bf93 | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 challenge-108/abigail/befunge-93/ch-2.bf93 diff --git a/challenge-108/abigail/README.md b/challenge-108/abigail/README.md index b4b729933a..38d2472a2a 100644 --- a/challenge-108/abigail/README.md +++ b/challenge-108/abigail/README.md @@ -1,4 +1,4 @@ -# Solutions by Abigail +# Solutions by Asbigail ## [Locate Memory](https://perlweeklychallenge.org/blog/perl-weekly-challenge-108/#TASK1) Write a script to declare a variable or constant and print it's @@ -32,6 +32,8 @@ more informations. ### Solutions * [AWK](awk/ch-2.awk) +* [Bash](bash/ch-2.sh) +* [Befunge-93][befunge-93/ch-2.bf93] * [Perl](perl/ch-2.pl) ### Blog diff --git a/challenge-108/abigail/befunge-93/ch-2.bf93 b/challenge-108/abigail/befunge-93/ch-2.bf93 new file mode 100644 index 0000000000..b212d72728 --- /dev/null +++ b/challenge-108/abigail/befunge-93/ch-2.bf93 @@ -0,0 +1,2 @@ +< v,_@#:< "1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147" +55 + > ^ -- cgit From af17168ecb87f45a8a7a7e51de2f2eb493973ec0 Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 14 Apr 2021 20:33:48 +0200 Subject: bc solution for week 108, part 2 --- challenge-108/abigail/README.md | 1 + challenge-108/abigail/bc/ch-2.bc | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 challenge-108/abigail/bc/ch-2.bc diff --git a/challenge-108/abigail/README.md b/challenge-108/abigail/README.md index 38d2472a2a..1680a47b9b 100644 --- a/challenge-108/abigail/README.md +++ b/challenge-108/abigail/README.md @@ -33,6 +33,7 @@ more informations. ### Solutions * [AWK](awk/ch-2.awk) * [Bash](bash/ch-2.sh) +* [bc](bc/ch-2.bc) * [Befunge-93][befunge-93/ch-2.bf93] * [Perl](perl/ch-2.pl) diff --git a/challenge-108/abigail/bc/ch-2.bc b/challenge-108/abigail/bc/ch-2.bc new file mode 100644 index 0000000000..b226f65322 --- /dev/null +++ b/challenge-108/abigail/bc/ch-2.bc @@ -0,0 +1,9 @@ +# +# See ../README.md +# + +# +# Run as: bc ch-1.bc +# +"1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147 +" -- cgit From f290a398359449b4b6c59c5239c83682851e53e7 Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 15 Apr 2021 14:27:25 +0200 Subject: C solution for week 108, part 2 --- challenge-108/abigail/README.md | 1 + challenge-108/abigail/c/ch-2.c | 70 +++++++++++++++++++++++++++++++++++++++ challenge-108/abigail/t/ctest.ini | 6 ++-- 3 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 challenge-108/abigail/c/ch-2.c diff --git a/challenge-108/abigail/README.md b/challenge-108/abigail/README.md index 1680a47b9b..b688b30c42 100644 --- a/challenge-108/abigail/README.md +++ b/challenge-108/abigail/README.md @@ -35,6 +35,7 @@ more informations. * [Bash](bash/ch-2.sh) * [bc](bc/ch-2.bc) * [Befunge-93][befunge-93/ch-2.bf93] +* [C](c/ch-2.c) * [Perl](perl/ch-2.pl) ### Blog diff --git a/challenge-108/abigail/c/ch-2.c b/challenge-108/abigail/c/ch-2.c new file mode 100644 index 0000000000..7d8352507b --- /dev/null +++ b/challenge-108/abigail/c/ch-2.c @@ -0,0 +1,70 @@ +# include +# include +# include + +/* + * See ../README.md + */ + +/* + * Run as: cc -o ch-2.o ch-2.c; ./ch-2.o + */ + +# define COUNT 10 + +# define PLAIN 0 +# define COMPUTE 2 + +typedef int number; /* Change if we want large numbers */ +char * fmt = "%d"; /* Should match typedef */ + +int main (int argc, char * argv []) { + int type = PLAIN; + if (argc > 1) { + if (strncmp (argv [1], "compute", 8) == 0) { + type = COMPUTE; + } + } + + if (type == PLAIN) { + printf ("1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147\n"); + } + if (type == COMPUTE) { + /* + * Calculate the Bell triangle + */ + number ** bell; + if ((bell = (number **) malloc ((COUNT - 1) * sizeof (number *))) + == NULL) { + perror ("Mallocing bell failed"); + exit (1); + } + if ((bell [0] = (number *) malloc (sizeof (number))) == NULL) { + perror ("Mallocing row failed"); + exit (1); + } + bell [0] [0] = 1; + for (int x = 1; x < COUNT - 1; x ++) { + if ((bell [x] = (number *) malloc ((x + 1) * sizeof (number))) + == NULL) { + perror ("Mallocing row failed"); + exit (1); + } + bell [x] [0] = bell [x - 1] [x - 1]; + for (int y = 1; y <= x; y ++) { + bell [x] [y] = bell [x] [y - 1] + bell [x - 1] [y - 1]; + } + } + + /* + * Print the right diagonal + */ + printf (fmt, 1); + for (int x = 0; x < COUNT - 1; x ++) { + printf (", "); + printf (fmt, bell [x] [x]); + } + printf ("\n"); + } + exit (0); +} diff --git a/challenge-108/abigail/t/ctest.ini b/challenge-108/abigail/t/ctest.ini index 0c513be6da..0d84cf60d7 100644 --- a/challenge-108/abigail/t/ctest.ini +++ b/challenge-108/abigail/t/ctest.ini @@ -13,13 +13,13 @@ [1-1] no_input = 1 -[2-1/perl,awk] +[2-1/awk,bash,c,perl] skip = "Not for this language" [2-2,2-3,2-4] skip = "Only for Perl" -[2-2/perl,awk] +[2-2/awk,bash,c,perl] skip = 0 args = plain @@ -27,6 +27,6 @@ args = plain skip = 0 args = fetch -[2-4/perl,awk] +[2-4/awk,bash,c,perl] skip = 0 args = compute -- cgit From cb227b49e4bfc9affaa09053eec6ad44509a3b08 Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 15 Apr 2021 14:30:14 +0200 Subject: BASIC solution for week 108, part 2 --- challenge-108/abigail/README.md | 1 + challenge-108/abigail/basic/ch-2.bas | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 challenge-108/abigail/basic/ch-2.bas diff --git a/challenge-108/abigail/README.md b/challenge-108/abigail/README.md index b688b30c42..bae4a956af 100644 --- a/challenge-108/abigail/README.md +++ b/challenge-108/abigail/README.md @@ -33,6 +33,7 @@ more informations. ### Solutions * [AWK](awk/ch-2.awk) * [Bash](bash/ch-2.sh) +* [BASIC](basic/ch-2.bas) * [bc](bc/ch-2.bc) * [Befunge-93][befunge-93/ch-2.bf93] * [C](c/ch-2.c) diff --git a/challenge-108/abigail/basic/ch-2.bas b/challenge-108/abigail/basic/ch-2.bas new file mode 100644 index 0000000000..2882082e94 --- /dev/null +++ b/challenge-108/abigail/basic/ch-2.bas @@ -0,0 +1,9 @@ +010 REM +020 REM See ../README.md +030 REM + +040 REM +050 REM Run as: basic ch-2.bas +060 REM + +100 PRINT "1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147" -- cgit From 2d6e93233290a9ee148739aec6dfe3b437ec3598 Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 15 Apr 2021 16:49:53 +0200 Subject: Cobol, Csh, Erlang, Forth and Fortran solutions for week 108, part 2 --- challenge-108/abigail/cobol/ch-2.cb | 14 ++++++++++++++ challenge-108/abigail/csh/ch-2.csh | 11 +++++++++++ challenge-108/abigail/erlang/ch-2.erl | 15 +++++++++++++++ challenge-108/abigail/forth/ch-2.fs | 5 +++++ challenge-108/abigail/fortran/ch-2.f90 | 12 ++++++++++++ 5 files changed, 57 insertions(+) create mode 100644 challenge-108/abigail/cobol/ch-2.cb create mode 100644 challenge-108/abigail/csh/ch-2.csh create mode 100644 challenge-108/abigail/erlang/ch-2.erl create mode 100644 challenge-108/abigail/forth/ch-2.fs create mode 100644 challenge-108/abigail/fortran/ch-2.f90 diff --git a/challenge-108/abigail/cobol/ch-2.cb b/challenge-108/abigail/cobol/ch-2.cb new file mode 100644 index 0000000000..c5aff7fdf8 --- /dev/null +++ b/challenge-108/abigail/cobol/ch-2.cb @@ -0,0 +1,14 @@ +IDENTIFICATION DIVISION. +PROGRAM-ID. BELL. + +*> +*> See ../README.md +*> + +*> +*> Run as: cobc -xF -o ch-2.o ch-2.cb; ./ch-2.o +*> + +PROCEDURE DIVISION. + DISPLAY "1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147". + STOP RUN. diff --git a/challenge-108/abigail/csh/ch-2.csh b/challenge-108/abigail/csh/ch-2.csh new file mode 100644 index 0000000000..ea424ce6b9 --- /dev/null +++ b/challenge-108/abigail/csh/ch-2.csh @@ -0,0 +1,11 @@ +#!/bin/csh + +# +# See ../README.md +# + +# +# Run as: csh ch-2.csh +# + +echo "1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147" diff --git a/challenge-108/abigail/erlang/ch-2.erl b/challenge-108/abigail/erlang/ch-2.erl new file mode 100644 index 0000000000..f407e66fde --- /dev/null +++ b/challenge-108/abigail/erlang/ch-2.erl @@ -0,0 +1,15 @@ +% +% See ../README.md +% + +% +% Run as: ln ch-2.erl ch2.erl +% erl -compile ch2 +% erl -noshell -s ch1 main -s init stop +% + +-module (ch2). +-export ([main/0]). + +main () -> + io:fwrite ("1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147\n"). diff --git a/challenge-108/abigail/forth/ch-2.fs b/challenge-108/abigail/forth/ch-2.fs new file mode 100644 index 0000000000..8b234c922e --- /dev/null +++ b/challenge-108/abigail/forth/ch-2.fs @@ -0,0 +1,5 @@ +\ +\ See ../README.md +\ + +.( 1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147) diff --git a/challenge-108/abigail/fortran/ch-2.f90 b/challenge-108/abigail/fortran/ch-2.f90 new file mode 100644 index 0000000000..112f6f2cd0 --- /dev/null +++ b/challenge-108/abigail/fortran/ch-2.f90 @@ -0,0 +1,12 @@ +! +! See ../README.md +! + +! +! Run as: gfortran -o ch-2.o ch-2.f90; ./ch-2.o +! + +program ch2 + implicit none + write (*, *) "1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147" +end -- cgit From ee3b74fc7b1071a7475c34faa5218442a99cc9b4 Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 15 Apr 2021 18:02:42 +0200 Subject: Solutions for many languages for week 108, part 2. Java, m4, OCaml, Pascal, PHP, PostScript, R, Rexx, Scheme, sed, SQL, and Tcl. --- challenge-108/abigail/README.md | 17 +++++++++++++++++ challenge-108/abigail/java/ch-2.java | 13 +++++++++++++ challenge-108/abigail/m4/ch-2.m4 | 1 + challenge-108/abigail/ocaml/ch-2.ml | 9 +++++++++ challenge-108/abigail/pascal/ch-2.p | 13 +++++++++++++ challenge-108/abigail/php/ch-2.php | 11 +++++++++++ challenge-108/abigail/postscript/ch-2.ps | 10 ++++++++++ challenge-108/abigail/r/ch-2.r | 9 +++++++++ challenge-108/abigail/rexx/ch-2.rexx | 9 +++++++++ challenge-108/abigail/scheme/ch-2.scm | 9 +++++++++ challenge-108/abigail/sed/ch-2.sed | 12 ++++++++++++ challenge-108/abigail/sql/ch-2.sql | 9 +++++++++ challenge-108/abigail/t/ctest.ini | 6 ++++++ challenge-108/abigail/t/input-2-1 | 1 + challenge-108/abigail/tcl/ch-2.tcl | 9 +++++++++ 15 files changed, 138 insertions(+) create mode 100644 challenge-108/abigail/java/ch-2.java create mode 100644 challenge-108/abigail/m4/ch-2.m4 create mode 100644 challenge-108/abigail/ocaml/ch-2.ml create mode 100644 challenge-108/abigail/pascal/ch-2.p create mode 100644 challenge-108/abigail/php/ch-2.php create mode 100644 challenge-108/abigail/postscript/ch-2.ps create mode 100644 challenge-108/abigail/r/ch-2.r create mode 100644 challenge-108/abigail/rexx/ch-2.rexx create mode 100644 challenge-108/abigail/scheme/ch-2.scm create mode 100644 challenge-108/abigail/sed/ch-2.sed create mode 100644 challenge-108/abigail/sql/ch-2.sql create mode 100644 challenge-108/abigail/tcl/ch-2.tcl diff --git a/challenge-108/abigail/README.md b/challenge-108/abigail/README.md index bae4a956af..77a8749f72 100644 --- a/challenge-108/abigail/README.md +++ b/challenge-108/abigail/README.md @@ -37,7 +37,24 @@ more informations. * [bc](bc/ch-2.bc) * [Befunge-93][befunge-93/ch-2.bf93] * [C](c/ch-2.c) +* [Cobol](cobol/ch-2.cb) +* [Csh](csh/ch-2.csh) +* [Erlang](erlang/ch-2.erl) +* [Forth](forth/ch-2.fs) +* [Fortran](fortran/ch-2.f90) +* [Java](java/ch-2.java) +* [m4](m4/ch-2.m4) +* [Ocaml](ocaml/ch-2.ml) +* [Pascal](pascal/ch-2.p) * [Perl](perl/ch-2.pl) +* [PHP](php/ch-2.php) +* [PostScript](postscript/ch-2.ps) +* [R](r/ch-2.r) +* [Rexx](rexx/ch-2.rexx) +* [Scheme](scheme/ch-2.scm) +* [sed](sed/ch-2.sed) +* [SQL](sql/ch-2.sql) +* [Tcl](tcl/ch-2.tcl) ### Blog diff --git a/challenge-108/abigail/java/ch-2.java b/challenge-108/abigail/java/ch-2.java new file mode 100644 index 0000000000..71c3980ce9 --- /dev/null +++ b/challenge-108/abigail/java/ch-2.java @@ -0,0 +1,13 @@ +// +// See ../README.md +// + +// +// Run as: ln ch-2.java ch2.java; javac ch2; java ch2 +// + +public class ch2 { + public static void main (String [] args) { + System . out . print ("1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147\n"); + } +} diff --git a/challenge-108/abigail/m4/ch-2.m4 b/challenge-108/abigail/m4/ch-2.m4 new file mode 100644 index 0000000000..52ad7f9d63 --- /dev/null +++ b/challenge-108/abigail/m4/ch-2.m4 @@ -0,0 +1 @@ +1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147 diff --git a/challenge-108/abigail/ocaml/ch-2.ml b/challenge-108/abigail/ocaml/ch-2.ml new file mode 100644 index 0000000000..368bf3ec07 --- /dev/null +++ b/challenge-108/abigail/ocaml/ch-2.ml @@ -0,0 +1,9 @@ +(* *) +(* See ../README.md *) +(* *) + +(* *) +(* Run as: ocaml ch-2.ml *) +(* *) + +print_endline "1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147"; diff --git a/challenge-108/abigail/pascal/ch-2.p b/challenge-108/abigail/pascal/ch-2.p new file mode 100644 index 0000000000..c4cd4b1d92 --- /dev/null +++ b/challenge-108/abigail/pascal/ch-2.p @@ -0,0 +1,13 @@ +Program Bell; + +(* *) +(* See ../README.md *) +(* *) + +(* *) +(* Run as: fpc -och-2.out ch-2.p; ./ch-2.out *) +(* *) + +begin + writeln ('1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147') +end. diff --git a/challenge-108/abigail/php/ch-2.php b/challenge-108/abigail/php/ch-2.php new file mode 100644 index 0000000000..23f3b55192 --- /dev/null +++ b/challenge-108/abigail/php/ch-2.php @@ -0,0 +1,11 @@ + diff --git a/challenge-108/abigail/postscript/ch-2.ps b/challenge-108/abigail/postscript/ch-2.ps new file mode 100644 index 0000000000..4102ddb4d9 --- /dev/null +++ b/challenge-108/abigail/postscript/ch-2.ps @@ -0,0 +1,10 @@ +%!PS +% +% See ../README.md +% + +% +% Run as: ps2ascii ch-2.ps +% + +(1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147) = diff --git a/challenge-108/abigail/r/ch-2.r b/challenge-108/abigail/r/ch-2.r new file mode 100644 index 0000000000..e9aa387b25 --- /dev/null +++ b/challenge-108/abigail/r/ch-2.r @@ -0,0 +1,9 @@ +# +# See ../README.md +# + +# +# Run as: Rscript ch-2.r +# + +cat ("1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147\n") diff --git a/challenge-108/abigail/rexx/ch-2.rexx b/challenge-108/abigail/rexx/ch-2.rexx new file mode 100644 index 0000000000..908dc8ac58 --- /dev/null +++ b/challenge-108/abigail/rexx/ch-2.rexx @@ -0,0 +1,9 @@ +/* + * See ../README.md + */ + +/* + * Run as: rexx ch-2.rexx + */ + +say "1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147" diff --git a/challenge-108/abigail/scheme/ch-2.scm b/challenge-108/abigail/scheme/ch-2.scm new file mode 100644 index 0000000000..6c0814f5b2 --- /dev/null +++ b/challenge-108/abigail/scheme/ch-2.scm @@ -0,0 +1,9 @@ +;;; +;;; See ../README.md +;;; + +;;; +;;; Run as: guile --no-auto-compile ch-2.scm +;;; + +(display "1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147\n") diff --git a/challenge-108/abigail/sed/ch-2.sed b/challenge-108/abigail/sed/ch-2.sed new file mode 100644 index 0000000000..c3f82af40a --- /dev/null +++ b/challenge-108/abigail/sed/ch-2.sed @@ -0,0 +1,12 @@ +# +# See ../README.md +# + +# +# Run as: sed -f ch-2.sed +# +# For each line in the input file, we write the first three +# self-describing numbers. +# + +s/.*/1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147/ diff --git a/challenge-108/abigail/sql/ch-2.sql b/challenge-108/abigail/sql/ch-2.sql new file mode 100644 index 0000000000..1fb5e94ef6 --- /dev/null +++ b/challenge-108/abigail/sql/ch-2.sql @@ -0,0 +1,9 @@ +-- +-- See ../README.md +-- + +-- +-- Run as: sqlite3 < ch-2.sql +-- + +SELECT "1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147"; diff --git a/challenge-108/abigail/t/ctest.ini b/challenge-108/abigail/t/ctest.ini index 0d84cf60d7..4b109e4310 100644 --- a/challenge-108/abigail/t/ctest.ini +++ b/challenge-108/abigail/t/ctest.ini @@ -13,6 +13,12 @@ [1-1] no_input = 1 +[2-1] +no_input = 1 + +[2-1/sed] +no_input = 0 + [2-1/awk,bash,c,perl] skip = "Not for this language" diff --git a/challenge-108/abigail/t/input-2-1 b/challenge-108/abigail/t/input-2-1 index e69de29bb2..8b13789179 100644 --- a/challenge-108/abigail/t/input-2-1 +++ b/challenge-108/abigail/t/input-2-1 @@ -0,0 +1 @@ + diff --git a/challenge-108/abigail/tcl/ch-2.tcl b/challenge-108/abigail/tcl/ch-2.tcl new file mode 100644 index 0000000000..38bcb1e0ca --- /dev/null +++ b/challenge-108/abigail/tcl/ch-2.tcl @@ -0,0 +1,9 @@ +# +# See ../README.md +# + +# +# Run as: tclsh ch-2.tcl +# + +puts "1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147" -- cgit From a5983ebcde7e49f77690d28461dcdfeb575dc834 Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 15 Apr 2021 18:08:25 +0200 Subject: Go solution for week 108, part 2 --- challenge-108/abigail/README.md | 1 + challenge-108/abigail/go/ch-2.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 challenge-108/abigail/go/ch-2.go diff --git a/challenge-108/abigail/README.md b/challenge-108/abigail/README.md index 77a8749f72..73974ba642 100644 --- a/challenge-108/abigail/README.md +++ b/challenge-108/abigail/README.md @@ -42,6 +42,7 @@ more informations. * [Erlang](erlang/ch-2.erl) * [Forth](forth/ch-2.fs) * [Fortran](fortran/ch-2.f90) +* [Go](go/ch-2.go) * [Java](java/ch-2.java) * [m4](m4/ch-2.m4) * [Ocaml](ocaml/ch-2.ml) diff --git a/challenge-108/abigail/go/ch-2.go b/challenge-108/abigail/go/ch-2.go new file mode 100644 index 0000000000..ef6ebae1a6 --- /dev/null +++ b/challenge-108/abigail/go/ch-2.go @@ -0,0 +1,15 @@ +package main + +// +// See ../README.md +// + +// +// Run as: go run ch-1.go +// + +import "fmt" + +func main () { + fmt . Print ("1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147\n") +} -- cgit From b1620c481366a458f47ca2eaac91715da0914f9d Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 15 Apr 2021 18:35:14 +0200 Subject: Lua solution for week 108, part 2 --- challenge-108/abigail/README.md | 1 + challenge-108/abigail/lua/ch-2.lua | 41 ++++++++++++++++++++++++++++++++++++++ challenge-108/abigail/t/ctest.ini | 6 +++--- 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 challenge-108/abigail/lua/ch-2.lua diff --git a/challenge-108/abigail/README.md b/challenge-108/abigail/README.md index 73974ba642..d97ab66dec 100644 --- a/challenge-108/abigail/README.md +++ b/challenge-108/abigail/README.md @@ -44,6 +44,7 @@ more informations. * [Fortran](fortran/ch-2.f90) * [Go](go/ch-2.go) * [Java](java/ch-2.java) +* [Lua](lua/ch-2.lua) * [m4](m4/ch-2.m4) * [Ocaml](ocaml/ch-2.ml) * [Pascal](pascal/ch-2.p) diff --git a/challenge-108/abigail/lua/ch-2.lua b/challenge-108/abigail/lua/ch-2.lua new file mode 100644 index 0000000000..37f067c465 --- /dev/null +++ b/challenge-108/abigail/lua/ch-2.lua @@ -0,0 +1,41 @@ +#!/opt/local/bin/lua + +-- +-- See ../README.md +-- + +-- +-- Run as: lua ch-2.lua +-- + +local COUNT = 10 +local PLAIN = 0 +local COMPUTE = 1 + +local type = PLAIN +if #arg >= 1 and arg [1] == "compute" +then type = COMPUTE +end + +if type == PLAIN +then print ("1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147") +end + +if type == COMPUTE +then local bell = {} + bell [0] = {} + bell [0] [0] = 1 + for x = 1, COUNT - 2 + do bell [x] = {} + bell [x] [0] = bell [x - 1] [x - 1] + for y = 1, x + do bell [x] [y] = bell [x] [y - 1] + bell [x - 1] [y - 1] + end + end + + io . write (1) + for x = 0, COUNT - 2 + do io . write (", " .. bell [x] [x]) + end + io . write ("\n") +end diff --git a/challenge-108/abigail/t/ctest.ini b/challenge-108/abigail/t/ctest.ini index 4b109e4310..ab10b98257 100644 --- a/challenge-108/abigail/t/ctest.ini +++ b/challenge-108/abigail/t/ctest.ini @@ -19,13 +19,13 @@ no_input = 1 [2-1/sed] no_input = 0 -[2-1/awk,bash,c,perl] +[2-1/awk,bash,c,lua,perl] skip = "Not for this language" [2-2,2-3,2-4] skip = "Only for Perl" -[2-2/awk,bash,c,perl] +[2-2/awk,bash,c,lua,perl] skip = 0 args = plain @@ -33,6 +33,6 @@ args = plain skip = 0 args = fetch -[2-4/awk,bash,c,perl] +[2-4/awk,bash,c,lua,perl] skip = 0 args = compute -- cgit From f4f74541386e7d473017e82ee919677fa61d667f Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 15 Apr 2021 18:56:01 +0200 Subject: Node.js solution for week 108, part 2 --- challenge-108/abigail/README.md | 1 + challenge-108/abigail/node/ch-2.js | 42 ++++++++++++++++++++++++++++++++++++++ challenge-108/abigail/t/ctest.ini | 6 +++--- 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 challenge-108/abigail/node/ch-2.js diff --git a/challenge-108/abigail/README.md b/challenge-108/abigail/README.md index d97ab66dec..1f2b01eaf8 100644 --- a/challenge-108/abigail/README.md +++ b/challenge-108/abigail/README.md @@ -46,6 +46,7 @@ more informations. * [Java](java/ch-2.java) * [Lua](lua/ch-2.lua) * [m4](m4/ch-2.m4) +* [Node.js](node/ch-2.js) * [Ocaml](ocaml/ch-2.ml) * [Pascal](pascal/ch-2.p) * [Perl](perl/ch-2.pl) diff --git a/challenge-108/abigail/node/ch-2.js b/challenge-108/abigail/node/ch-2.js new file mode 100644 index 0000000000..7911a70038 --- /dev/null +++ b/challenge-108/abigail/node/ch-2.js @@ -0,0 +1,42 @@ +#!/usr/local/bin/node + +// +// See ../README.md +// + +// +// Run as: node ch-2.js +// + +let COUNT = 10 +let PLAIN = 0 +let COMPUTE = 1 + +let type = PLAIN + +if (process . argv . length > 2 && + process . argv [2] == "compute") { + type = COMPUTE +} + +if (type == PLAIN) { + console . log ("1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147") +} + +if (type == COMPUTE) { + let bell = [[ 1 ]] + let x + for (x = 1; x < COUNT - 1; x ++) { + bell [x] = [bell [x - 1] [x - 1]] + let y + for (y = 1; y <= x; y ++) { + bell [x] [y] = bell [x] [y - 1] + bell [x - 1] [y - 1] + } + } + + process . stdout . write ("1") + for (x = 0; x < COUNT - 1; x ++) { + process . stdout . write (", " + bell [x] [x] . toString ()) + } + process . stdout . write ("\n") +} diff --git a/challenge-108/abigail/t/ctest.ini b/challenge-108/abigail/t/ctest.ini index ab10b98257..b0643c4194 100644 --- a/challenge-108/abigail/t/ctest.ini +++ b/challenge-108/abigail/t/ctest.ini @@ -19,13 +19,13 @@ no_input = 1 [2-1/sed] no_input = 0 -[2-1/awk,bash,c,lua,perl] +[2-1/awk,bash,c,lua,node,perl] skip = "Not for this language" [2-2,2-3,2-4] skip = "Only for Perl" -[2-2/awk,bash,c,lua,perl] +[2-2/awk,bash,c,lua,node,perl] skip = 0 args = plain @@ -33,6 +33,6 @@ args = plain skip = 0 args = fetch -[2-4/awk,bash,c,lua,perl] +[2-4/awk,bash,c,lua,node,perl] skip = 0 args = compute -- cgit From ca1daf0f9da43b6450136eb84d3eda37d1f9f0d0 Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 15 Apr 2021 18:59:55 +0200 Subject: bc programs not taking input should quit. --- challenge-108/abigail/bc/ch-2.bc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/challenge-108/abigail/bc/ch-2.bc b/challenge-108/abigail/bc/ch-2.bc index b226f65322..ba95c81011 100644 --- a/challenge-108/abigail/bc/ch-2.bc +++ b/challenge-108/abigail/bc/ch-2.bc @@ -3,7 +3,8 @@ # # -# Run as: bc ch-1.bc +# Run as: bc ch-2.bc # "1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147 " +quit -- cgit From 4c178bd74d87439bd82eae6d35a1a4ad8f446c3d Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 15 Apr 2021 19:11:45 +0200 Subject: Python solution for week 108, part 2 --- challenge-108/abigail/README.md | 1 + challenge-108/abigail/python/ch-2.py | 38 ++++++++++++++++++++++++++++++++++++ challenge-108/abigail/t/ctest.ini | 6 +++--- 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 challenge-108/abigail/python/ch-2.py diff --git a/challenge-108/abigail/README.md b/challenge-108/abigail/README.md index 1f2b01eaf8..1a326569ae 100644 --- a/challenge-108/abigail/README.md +++ b/challenge-108/abigail/README.md @@ -52,6 +52,7 @@ more informations. * [Perl](perl/ch-2.pl) * [PHP](php/ch-2.php) * [PostScript](postscript/ch-2.ps) +* [Python](python/ch-2.py) * [R](r/ch-2.r) * [Rexx](rexx/ch-2.rexx) * [Scheme](scheme/ch-2.scm) diff --git a/challenge-108/abigail/python/ch-2.py b/challenge-108/abigail/python/ch-2.py new file mode 100644 index 0000000000..161dcd862b --- /dev/null +++ b/challenge-108/abigail/python/ch-2.py @@ -0,0 +1,38 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-2.py +# + +import sys + +COUNT = 10 +PLAIN = 0 +COMPUTE = 1 + +type = PLAIN + +if len (sys . argv) > 1 and sys . argv [1] == "compute": + type = COMPUTE + + +if type == PLAIN: + print ("1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147") + + +if type == COMPUTE: + bell = [[1]] + for x in range (1, COUNT - 1): + bell . append ([bell [x - 1] [x - 1]]) + for y in range (1, x + 1): + bell [x] . append (bell [x] [y - 1] + bell [x - 1] [y - 1]) + + print (1, end = '') + for x in range (0, COUNT - 1): + print (",", bell [x] [x], end = '') + + print ("") diff --git a/challenge-108/abigail/t/ctest.ini b/challenge-108/abigail/t/ctest.ini index b0643c4194..f34ee1531b 100644 --- a/challenge-108/abigail/t/ctest.ini +++ b/challenge-108/abigail/t/ctest.ini @@ -19,13 +19,13 @@ no_input = 1 [2-1/sed] no_input = 0 -[2-1/awk,bash,c,lua,node,perl] +[2-1/awk,bash,c,lua,node,perl,python] skip = "Not for this language" [2-2,2-3,2-4] skip = "Only for Perl" -[2-2/awk,bash,c,lua,node,perl] +[2-2/awk,bash,c,lua,node,perl,python] skip = 0 args = plain @@ -33,6 +33,6 @@ args = plain skip = 0 args = fetch -[2-4/awk,bash,c,lua,node,perl] +[2-4/awk,bash,c,lua,node,perl,python] skip = 0 args = compute -- cgit From 3f31447acbe9b9a929319d1b691610dcbb2bc07b Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 15 Apr 2021 20:14:04 +0200 Subject: Ruby solution for week 108, part 2 --- challenge-108/abigail/ruby/ch-2.rb | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 challenge-108/abigail/ruby/ch-2.rb diff --git a/challenge-108/abigail/ruby/ch-2.rb b/challenge-108/abigail/ruby/ch-2.rb new file mode 100644 index 0000000000..184a0dcc66 --- /dev/null +++ b/challenge-108/abigail/ruby/ch-2.rb @@ -0,0 +1,39 @@ +#!/usr/bin/ruby + +# +# See ../README.md +# + +# +# Run as: ruby ch-2.rb +# + +COUNT = 10 +PLAIN = 0 +COMPUTE = 1 + +type = PLAIN + +if ARGV . length > 0 && ARGV[0] == "compute" +then type = COMPUTE +end + +if type == PLAIN +then puts ("1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147"); +end + +if type == COMPUTE +then bell = [[1]] + for x in 1 .. COUNT - 2 + bell [x] = [bell [x - 1] [x - 1]] + for y in 1 .. x + bell [x] [y] = bell [x] [y - 1] + bell [x - 1] [y - 1] + end + end + print (1) + for x in 0 .. COUNT - 2 + print (", ") + print (bell [x] [x]) + end + puts ("") +end -- cgit From 6d77ad28625fb12bad358b00aa4746c9df714392 Mon Sep 17 00:00:00 2001 From: Abigail Date: Fri, 16 Apr 2021 01:12:58 +0200 Subject: Pascal solution for week 108, part 1 --- challenge-108/abigail/README.md | 2 ++ challenge-108/abigail/pascal/ch-1.p | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 challenge-108/abigail/pascal/ch-1.p diff --git a/challenge-108/abigail/README.md b/challenge-108/abigail/README.md index 1a326569ae..b91c6ce23b 100644 --- a/challenge-108/abigail/README.md +++ b/challenge-108/abigail/README.md @@ -8,6 +8,7 @@ location in the memory. * [C](c/ch-1.c) * [Fortran](fortran/ch-1.f90) * [Go](go/ch-1.go) +* [Pascal](pascal/ch-1.p) * [Perl](perl/ch-1.pl) * [Python](python/ch-1.py) @@ -55,6 +56,7 @@ more informations. * [Python](python/ch-2.py) * [R](r/ch-2.r) * [Rexx](rexx/ch-2.rexx) +* [Ruby](ruby/ch-2.rb) * [Scheme](scheme/ch-2.scm) * [sed](sed/ch-2.sed) * [SQL](sql/ch-2.sql) diff --git a/challenge-108/abigail/pascal/ch-1.p b/challenge-108/abigail/pascal/ch-1.p new file mode 100644 index 0000000000..918503a432 --- /dev/null +++ b/challenge-108/abigail/pascal/ch-1.p @@ -0,0 +1,19 @@ +Program XXX; + +(* *) +(* See ../README.md *) +(* *) + +(* *) +(* Run as: fpc -och-1.out ch-1.p; ./ch-1.out *) +(* *) + +var i: Integer; + p: ^Integer; + w: ^Word; + +begin + p := @i; + w := addr (p); + writeln (w^); +end. -- cgit From 3254688724274330eac26ea83d5c76028fe421aa Mon Sep 17 00:00:00 2001 From: Abigail Date: Fri, 16 Apr 2021 02:16:18 +0200 Subject: R solution for week 108, part 1 --- challenge-108/abigail/README.md | 1 + challenge-108/abigail/r/ch-1.r | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 challenge-108/abigail/r/ch-1.r diff --git a/challenge-108/abigail/README.md b/challenge-108/abigail/README.md index b91c6ce23b..66ded7e046 100644 --- a/challenge-108/abigail/README.md +++ b/challenge-108/abigail/README.md @@ -11,6 +11,7 @@ location in the memory. * [Pascal](pascal/ch-1.p) * [Perl](perl/ch-1.pl) * [Python](python/ch-1.py) +* [R](r/ch-1.r) ### Blog diff --git a/challenge-108/abigail/r/ch-1.r b/challenge-108/abigail/r/ch-1.r new file mode 100644 index 0000000000..e293055ccd --- /dev/null +++ b/challenge-108/abigail/r/ch-1.r @@ -0,0 +1,15 @@ +# +# See ../README.md +# + +# +# Run as: Rscript ch-1.r +# + +x <- 0 +cat (sprintf ("%.0f\n", + as.numeric ( + paste0 ("0x", + substring ( + sub (" .*$", "", + capture.output (.Internal (inspect (x)))), 2))))) -- cgit From 513dbf94b4f9c79ab0cd274f7489a4eb076af04e Mon Sep 17 00:00:00 2001 From: Abigail Date: Fri, 16 Apr 2021 02:30:32 +0200 Subject: Ruby solution for week 108, part 1 --- challenge-108/abigail/README.md | 1 + challenge-108/abigail/ruby/ch-1.rb | 12 ++++++++++++ challenge-108/abigail/t/ctest.ini | 6 +++--- 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 challenge-108/abigail/ruby/ch-1.rb diff --git a/challenge-108/abigail/README.md b/challenge-108/abigail/README.md index 66ded7e046..28df162888 100644 --- a/challenge-108/abigail/README.md +++ b/challenge-108/abigail/README.md @@ -12,6 +12,7 @@ location in the memory. * [Perl](perl/ch-1.pl) * [Python](python/ch-1.py) * [R](r/ch-1.r) +* [Ruby](ruby/ch-1.rb) ### Blog diff --git a/challenge-108/abigail/ruby/ch-1.rb b/challenge-108/abigail/ruby/ch-1.rb new file mode 100644 index 0000000000..fe85212b95 --- /dev/null +++ b/challenge-108/abigail/ruby/ch-1.rb @@ -0,0 +1,12 @@ + +#!/usr/bin/ruby + +# +# See ../README.md +# + +# +# Run as: ruby ch-1.rb +# + +puts (Object . new . object_id << 1) diff --git a/challenge-108/abigail/t/ctest.ini b/challenge-108/abigail/t/ctest.ini index f34ee1531b..3bba3fcf1f 100644 --- a/challenge-108/abigail/t/ctest.ini +++ b/challenge-108/abigail/t/ctest.ini @@ -19,13 +19,13 @@ no_input = 1 [2-1/sed] no_input = 0 -[2-1/awk,bash,c,lua,node,perl,python] +[2-1/awk,bash,c,lua,node,perl,python,ruby] skip = "Not for this language" [2-2,2-3,2-4] skip = "Only for Perl" -[2-2/awk,bash,c,lua,node,perl,python] +[2-2/awk,bash,c,lua,node,perl,python,ruby] skip = 0 args = plain @@ -33,6 +33,6 @@ args = plain skip = 0 args = fetch -[2-4/awk,bash,c,lua,node,perl,python] +[2-4/awk,bash,c,lua,node,perl,python,ruby] skip = 0 args = compute -- cgit From f228bdabf3df9ab8f0738838e68acd4df91f6061 Mon Sep 17 00:00:00 2001 From: Abigail Date: Fri, 16 Apr 2021 03:05:28 +0200 Subject: Blog for week 108, part 1 --- challenge-108/abigail/README.md | 1 + challenge-108/abigail/blog.txt | 1 + 2 files changed, 2 insertions(+) create mode 100644 challenge-108/abigail/blog.txt diff --git a/challenge-108/abigail/README.md b/challenge-108/abigail/README.md index 28df162888..d5b2ea8943 100644 --- a/challenge-108/abigail/README.md +++ b/challenge-108/abigail/README.md @@ -15,6 +15,7 @@ location in the memory. * [Ruby](ruby/ch-1.rb) ### Blog +[Locate Memory](https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-108-1.html) ## [Bell Numbers](https://perlweeklychallenge.org/blog/perl-weekly-challenge-108/#TASK2) diff --git a/challenge-108/abigail/blog.txt b/challenge-108/abigail/blog.txt new file mode 100644 index 0000000000..ce18567b5c --- /dev/null +++ b/challenge-108/abigail/blog.txt @@ -0,0 +1 @@ +https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-108-1.html -- cgit From 1b300cfd72ea76888a56b1a2bc9e96f8bce748a3 Mon Sep 17 00:00:00 2001 From: Abigail Date: Sun, 18 Apr 2021 19:43:00 +0200 Subject: Small improvements --- challenge-108/abigail/perl/ch-2.pl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/challenge-108/abigail/perl/ch-2.pl b/challenge-108/abigail/perl/ch-2.pl index d89e32391e..c1f4457967 100644 --- a/challenge-108/abigail/perl/ch-2.pl +++ b/challenge-108/abigail/perl/ch-2.pl @@ -40,11 +40,9 @@ if ($type == $TYPE_PLAIN) { elsif ($type == $TYPE_FETCH) { use OEIS; $, = ", "; - say oeis (110 => 10) + say oeis (110 => $COUNT) } elsif ($type == $TYPE_COMPUTE) { - my $COUNT = 10; - # # Create Bell triangle (See https://en.wikipedia.org/wiki/Bell_triangle) # The Bell numbers (starting from the second one), are on the -- cgit From cb14e653f808efab54343ccde87436a78e9e5f3b Mon Sep 17 00:00:00 2001 From: Abigail Date: Sun, 18 Apr 2021 20:12:15 +0200 Subject: Blog for week 108, part 2 --- challenge-108/abigail/README.md | 1 + challenge-108/abigail/blog1.txt | 1 + 2 files changed, 2 insertions(+) create mode 100644 challenge-108/abigail/blog1.txt diff --git a/challenge-108/abigail/README.md b/challenge-108/abigail/README.md index d5b2ea8943..32dc7d1d9d 100644 --- a/challenge-108/abigail/README.md +++ b/challenge-108/abigail/README.md @@ -66,4 +66,5 @@ more informations. * [Tcl](tcl/ch-2.tcl) ### Blog +[Bell Numbers](https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-108-2.html) diff --git a/challenge-108/abigail/blog1.txt b/challenge-108/abigail/blog1.txt new file mode 100644 index 0000000000..575bff46c6 --- /dev/null +++ b/challenge-108/abigail/blog1.txt @@ -0,0 +1 @@ +https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-108-2.html -- cgit