aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-125/abigail/README.md112
-rw-r--r--challenge-125/abigail/awk/ch-1.awk44
-rw-r--r--challenge-125/abigail/blog.txt1
-rw-r--r--challenge-125/abigail/blog1.txt1
-rw-r--r--challenge-125/abigail/c/ch-1.c52
-rw-r--r--challenge-125/abigail/go/ch-1.go61
-rw-r--r--challenge-125/abigail/java/ch-1.java52
-rw-r--r--challenge-125/abigail/lua/ch-1.lua48
-rw-r--r--challenge-125/abigail/node/ch-1.js47
-rw-r--r--challenge-125/abigail/pascal/ch-1.p59
-rw-r--r--challenge-125/abigail/perl/ch-1.pl69
-rw-r--r--challenge-125/abigail/perl/ch-2.pl79
-rw-r--r--challenge-125/abigail/python/ch-1.py41
-rw-r--r--challenge-125/abigail/r/ch-1.r54
-rw-r--r--challenge-125/abigail/ruby/ch-1.rb45
-rw-r--r--challenge-125/abigail/t/ctest.ini10
-rw-r--r--challenge-125/abigail/t/input-1-13
-rw-r--r--challenge-125/abigail/t/input-1-22
-rw-r--r--challenge-125/abigail/t/input-1-398
-rw-r--r--challenge-125/abigail/t/input-1-4143
-rw-r--r--challenge-125/abigail/t/output-1-1.exp5
-rw-r--r--challenge-125/abigail/t/output-1-2.exp2
-rw-r--r--challenge-125/abigail/t/output-1-3.exp391
-rw-r--r--challenge-125/abigail/t/output-1-4.exp212
-rw-r--r--challenge-125/abigail/tcl/ch-1.tcl45
25 files changed, 1619 insertions, 57 deletions
diff --git a/challenge-125/abigail/README.md b/challenge-125/abigail/README.md
index c116d92523..677f80fccf 100644
--- a/challenge-125/abigail/README.md
+++ b/challenge-125/abigail/README.md
@@ -1,95 +1,93 @@
# Solutions by Abigail
-## [Happy Women Day][task1]
+## [Pythagorean Triples][task1]
-> Write a script to print the Venus Symbol, international gender symbol
-> for women. Please feel free to use any character.
+> You are given a positive integer `$N`.
+>
+> Write a script to print all Pythagorean Triples containing $N as
+> a member. Print `-1` if it can't be a member of any.
+>
+> Triples with the same set of elements are considered the same,
+> i.e. if your script has already printed `(3, 4, 5)`, `(4, 3, 5)` should
+> not be printed.
+>
+> > The famous Pythagorean theorem states that in a right angle
+> > triangle, the length of the two shorter sides and the length of the
+> > longest side are related by `a^2+b^2 = c^2`.
+### Example
~~~~
- ^^^^^
- ^ ^
- ^ ^
- ^ ^
- ^ ^
- ^ ^
- ^ ^
- ^ ^
- ^ ^
- ^ ^
- ^^^^^
- ^
- ^
- ^
- ^^^^^
- ^
- ^
+Input: $N = 5
+Output: (3, 4, 5)
+ (5, 12, 13)
+
+Input: $N = 13
+Output: (5, 12, 13)
+ (13, 84, 85)
+
+Input: $N = 1
+Output: -1
~~~~
### Solutions
* [AWK](awk/ch-1.awk)
-* [Bash](bash/ch-1.sh)
-* [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.f90)
* [Go](go/ch-1.go)
* [Java](java/ch-1.java)
* [Lua](lua/ch-1.lua)
-* [m4](m4/ch-1.m4)
-* [MMIX](mmix/ch-1.mms)
* [Node.js](node/ch-1.js)
-* [Ocaml](ocaml/ch-1.ml)
* [Pascal](pascal/ch-1.p)
* [Perl](perl/ch-1.pl)
-* [Php](php/ch-1.php)
-* [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)
-* [SQL](sql/ch-1.sql)
* [Tcl](tcl/ch-1.tcl)
### Blog
-[Perl Weekly Challenge 124: Happy Women Day][blog1]
+[Perl Weekly Challenge 125: Pythagorean Triples][blog1]
+
+## [Binary Tree Diameter][task2]
-## [Tug of War][task2]
+> You are given binary tree as below:
-> You are given a set of $n integers `(n1, n2, n3, ...)`.
+~~~~
+ 1
+ / \
+ 2 5
+ / \ / \
+3 4 6 7
+ / \
+ 8 10
+ /
+ 9
+~~~~
+
+> Write a script to find the diameter of the given binary tree.
>
-> Write a script to divide the set in two subsets of `n/2` sizes each
-> so that the difference of the sum of two subsets is the least. If
-> `$n` is even then each subset must be of size `$n/2` each. In case $n
-> is odd then one subset must be `($n-1)/2` and other must be `($n+1)/2`.
+> > The diameter of a binary tree is the length of the longest path
+> > between any two nodes in a tree. It doesn't have to pass
+> > through the root.
+
+For the above given binary tree, possible diameters (7) are:
-### Examples
~~~~
-Input: Set = (10, 20, 30, 40, 50, 60, 70, 80, 90, 100)
-Output: Subset 1 = (30, 40, 60, 70, 80)
- Subset 2 = (10, 20, 50, 90, 100)
+3, 2, 1, 5, 7, 8, 9
~~~~
+or
+
~~~~
-Input: Set = (10, -15, 20, 30, -25, 0, 5, 40, -5)
- Subset 1 = (30, 0, 5, -5)
- Subset 2 = (10, -15, 20, -25, 40)
+4, 2, 1, 5, 7, 8, 9
~~~~
### Solutions
* [Perl](perl/ch-2.pl)
-* [Python](python/ch-2.py)
### Blog
-[Perl Weekly Challenge 124: Tug of War][blog2]
+[Perl Weekly Challenge 125: Binary Tree Diameter][blog2]
-[task1]: https://perlweeklychallenge.org/blog/perl-weekly-challenge-124/#TASK1
-[task2]: https://perlweeklychallenge.org/blog/perl-weekly-challenge-124/#TASK2
-[blog1]: https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-124-1.html
-[blog2]: https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-124-2.html
+[task1]: https://perlweeklychallenge.org/blog/perl-weekly-challenge-125/#TASK1
+[task2]: https://perlweeklychallenge.org/blog/perl-weekly-challenge-125/#TASK2
+[blog1]: https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-125-1.html
+[blog2]: https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-125-2.html
diff --git a/challenge-125/abigail/awk/ch-1.awk b/challenge-125/abigail/awk/ch-1.awk
new file mode 100644
index 0000000000..1758b7d64d
--- /dev/null
+++ b/challenge-125/abigail/awk/ch-1.awk
@@ -0,0 +1,44 @@
+#!/usr/bin/awk
+
+#
+# See ../README.md
+#
+
+#
+# Run as: awk -f ch-1.awk < input-file
+#
+
+function introot (square) {
+ return (int (.4 + sqrt (square)))
+}
+
+
+$1 <= 2 {
+ print (-1)
+ next
+}
+
+
+{
+ n = $1
+ n_sq = n * n
+ c = n + 1
+ c_sq = n_sq + 2 * n + 1
+ while (2 * c - 1 <= n_sq) {
+ b_sq = c_sq - n_sq
+ b = introot(b_sq)
+ if (b_sq == b * b) {
+ print n, b, c
+ }
+ c_sq += 2 * c ++ + 1
+ }
+
+ max_a = int (n / sqrt (2))
+ for (a = 3; a <= max_a; a ++) {
+ b_sq = n_sq - a * a
+ b = introot(b_sq)
+ if (b_sq == b * b) {
+ print a, b, n
+ }
+ }
+}
diff --git a/challenge-125/abigail/blog.txt b/challenge-125/abigail/blog.txt
new file mode 100644
index 0000000000..79e86ddc80
--- /dev/null
+++ b/challenge-125/abigail/blog.txt
@@ -0,0 +1 @@
+https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-125-1.html
diff --git a/challenge-125/abigail/blog1.txt b/challenge-125/abigail/blog1.txt
new file mode 100644
index 0000000000..ce0adcab58
--- /dev/null
+++ b/challenge-125/abigail/blog1.txt
@@ -0,0 +1 @@
+https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-125-2.html
diff --git a/challenge-125/abigail/c/ch-1.c b/challenge-125/abigail/c/ch-1.c
new file mode 100644
index 0000000000..63b3a67db1
--- /dev/null
+++ b/challenge-125/abigail/c/ch-1.c
@@ -0,0 +1,52 @@
+# include <stdlib.h>
+# include <stdio.h>
+# include <string.h>
+# include <math.h>
+
+/*
+ * See ../README.md
+ */
+
+/*
+ * Run as: cc -o ch-1.o ch-1.c; ./ch-1.o < input-file
+ */
+
+typedef long long number;
+
+number introot (number square) {
+ return ((number) floorl (.4 + sqrt (square)));
+}
+
+int main (void) {
+ number n;
+
+ while (scanf ("%lld", &n) == 1) {
+ if (n <= 2) {
+ printf ("-1\n");
+ continue;
+ }
+
+ number n_sq = n * n;
+ number c = n + 1;
+ number c_sq = n_sq + 2 * n + 1;
+ while (2 * c - 1 <= n_sq) {
+ number b_sq = c_sq - n_sq;
+ number b = introot (b_sq);
+ if (b_sq == b * b) {
+ printf ("%lld %lld %lld\n", n, b, c);
+ }
+ c_sq += 2 * c ++ + 1;
+ }
+
+ number max_a = (number) floorl (n / sqrt (2));
+ for (number a = 3; a <= max_a; a ++) {
+ number b_sq = n_sq - a * a;
+ number b = introot (b_sq);
+ if (b_sq == b * b) {
+ printf ("%lld %lld %lld\n", a, b, n);
+ }
+ }
+ }
+
+ return (0);
+}
diff --git a/challenge-125/abigail/go/ch-1.go b/challenge-125/abigail/go/ch-1.go
new file mode 100644
index 0000000000..f69846b7ed
--- /dev/null
+++ b/challenge-125/abigail/go/ch-1.go
@@ -0,0 +1,61 @@
+package main
+
+//
+// See ../README.md
+//
+
+//
+// Run as: go run ch-1.go
+//
+
+import (
+ "fmt"
+ "math"
+)
+
+func introot (square int) int {
+ return (int (math . Round (math . Sqrt (float64 (square)))));
+}
+
+func main () {
+ for {
+ var n, n_sq, a, max_a, b, b_sq, c, c_sq int;
+ var count, err = fmt . Scanf ("%d", &n);
+ if (err != nil || count != 1) {
+ break;
+ }
+
+ if (n <= 2) {
+ fmt . Println ("-1");
+ continue;
+ }
+
+ n_sq = n * n;
+ c = n + 1;
+ c_sq = n_sq + 2 * n + 1;
+
+ for 2 * c - 1 <= n_sq {
+ b_sq = c_sq - n_sq;
+ b = introot (b_sq);
+
+ if (b_sq == b * b) {
+ fmt . Printf ("%d %d %d\n", n, b, c);
+ }
+
+ c_sq += 2 * c + 1;
+ c += 1;
+ }
+
+ max_a = int (float64 (n) / math . Sqrt (float64 (2)));
+
+ a = 3;
+ for a <= max_a {
+ b_sq = n_sq - a * a
+ b = introot (b_sq)
+ if (b_sq == b * b) {
+ fmt . Printf ("%d %d %d\n", a, b, n);
+ }
+ a += 1;
+ }
+ }
+}
diff --git a/challenge-125/abigail/java/ch-1.java b/challenge-125/abigail/java/ch-1.java
new file mode 100644
index 0000000000..722b6d0f81
--- /dev/null
+++ b/challenge-125/abigail/java/ch-1.java
@@ -0,0 +1,52 @@
+//
+// See ../README.md
+//
+
+//
+// Run as: ln ch-1.java ch1.java; javac ch1.java; java ch1 < input-file
+//
+
+import java.util.*;
+
+public class ch1 {
+ public static long introot (long square) {
+ return ((long) Math . floor (Math . sqrt (square)));
+ }
+
+ public static void main (String [] args) {
+ Scanner scanner = new Scanner (System . in);
+ while (scanner . hasNextInt ()) {
+ long n = scanner . nextInt ();
+ if (n <= 2) {
+ System . out . println ("-1");
+ continue;
+ }
+
+ long n_sq = n * n;
+ long c = n + 1;
+ long c_sq = n_sq + 2 * n + 1;
+
+ while (2 * c - 1 <= n_sq) {
+ long b_sq = c_sq - n_sq;
+ long b = introot (b_sq);
+
+ if (b_sq == b * b) {
+ System . out . printf ("%d %d %d\n", n, b, c);
+ }
+
+ c_sq += 2 * c + 1;
+ c += 1;
+ }
+
+ long max_a = (long) Math . floor (n / Math . sqrt (2));
+ long a = 3;
+ for (a = 3; a <= max_a; a ++) {
+ long b_sq = n_sq - a * a;
+ long b = introot (b_sq);
+ if (b_sq == b * b) {
+ System . out . printf ("%d %d %d\n", a, b, n);
+ }
+ }
+ }
+ }
+}
diff --git a/challenge-125/abigail/lua/ch-1.lua b/challenge-125/abigail/lua/ch-1.lua
new file mode 100644
index 0000000000..1a0efb40c8
--- /dev/null
+++ b/challenge-125/abigail/lua/ch-1.lua
@@ -0,0 +1,48 @@
+#!/opt/local/bin/lua
+
+--
+-- See ../README.md
+--
+
+--
+-- Run as: lua ch-1.lua < input-file
+--
+
+function introot (square)
+ return (math . floor (.4 + math . sqrt (square)))
+end
+
+
+for line in io . lines () do
+ local n = tonumber (line)
+ if n <= 2 then
+ print (-1)
+ goto end_loop
+ end
+
+ local n_sq = n * n
+ local c = n + 1
+ local c_sq = n_sq + 2 * n + 1
+ while 2 * c - 1 <= n_sq do
+ local b_sq = c_sq - n_sq
+ local b = introot (b_sq)
+
+ if b_sq == b * b then
+ print (n .. " " .. b .. " " .. c)
+ end
+
+ c_sq = c_sq + 2 * c + 1
+ c = c + 1
+ end
+
+ local max_a = math . floor (n / math . sqrt (2))
+ for a = 3, max_a do
+ local b_sq = n_sq - a * a
+ local b = introot (b_sq)
+ if b_sq == b * b then
+ print (a .. " " .. b .. " " .. n)
+ end
+ end
+
+ ::end_loop::
+end
diff --git a/challenge-125/abigail/node/ch-1.js b/challenge-125/abigail/node/ch-1.js
new file mode 100644
index 0000000000..a8c8c9c2c4
--- /dev/null
+++ b/challenge-125/abigail/node/ch-1.js
@@ -0,0 +1,47 @@
+#!/usr/local/bin/node
+
+//
+// See ../README.md
+//
+
+//
+// Run as: node ch-1.js < input-file
+//
+
+ require ('readline')
+. createInterface ({input: process . stdin})
+. on ('line', line => main (+ line))
+
+function introot (square) {
+ return (Math . floor (.4 + Math . sqrt (square)))
+}
+
+function main (n) {
+ if (n <= 2) {
+ console . log (-1)
+ return
+ }
+
+ let n_sq = n * n
+ let c = n + 1
+ let c_sq = n_sq + 2 * n + 1
+ while (2 * c - 1 <= n_sq) {
+ let b_sq = c_sq - n_sq
+ let b = introot (b_sq)
+
+ if (b_sq == b * b) {
+ console . log (n + " " + b + " " + c)
+ }
+
+ c_sq += 2 * c ++ + 1
+ }
+
+ let max_a = Math . floor (n / Math . sqrt (2))
+ for (let a = 3; a <= max_a; a ++) {
+ let b_sq = n_sq - a * a
+ let b = introot (b_sq)
+ if (b_sq == b * b) {
+ console . log (a + " " + b + " " + n)
+ }
+ }
+}
diff --git a/challenge-125/abigail/pascal/ch-1.p b/challenge-125/abigail/pascal/ch-1.p
new file mode 100644
index 0000000000..f6e2d93fb5
--- /dev/null
+++ b/challenge-125/abigail/pascal/ch-1.p
@@ -0,0 +1,59 @@
+Program XXX;
+
+(* *)
+(* See ../README.md *)
+(* *)
+
+(* *)
+(* Run as: fpc -och-1.out ch-1.p; ./ch-1.out < input-file *)
+(* *)
+
+uses
+ math;
+
+var
+ n, n_sq, a, max_a, b, b_sq, c, c_sq: int64;
+
+function introot (square: int64): int64;
+begin
+ introot := round (sqrt (square));
+end;
+
+
+begin
+ while (not eof) do begin
+ readln (n);
+ if n <= 2 then begin
+ writeln (-1);
+ continue;
+ end;
+
+ n_sq := n * n;
+ c := n + 1;
+ c_sq := n_sq + 2 * n + 1;
+
+ while (2 * c - 1 <= n_sq) do begin
+ b_sq := c_sq - n_sq;
+ b := introot (b_sq);
+ if b_sq = b * b then begin
+ writeln (n, ' ', b, ' ', c);
+ end;
+ c_sq := c_sq + 2 * c + 1;
+ c := c + 1;
+ end;
+
+ max_a := floor (n / sqrt (2));
+ for a := 3 to max_a do begin
+ b_sq := n_sq - a * a;
+ if b_sq < 0 then begin
+ writeln ('n = ', n, '; a = ', a, '; b_sq = ', b_sq);
+ continue;
+ end;
+
+ b := introot (b_sq);
+ if b_sq = b * b then begin
+ writeln (a, ' ', b, ' ', n);
+ end;
+ end;
+ end;
+end.
diff --git a/challenge-125/abigail/perl/ch-1.pl b/challenge-125/abigail/perl/ch-1.pl
new file mode 100644
index 0000000000..c62b9b92d3
--- /dev/null
+++ b/challenge-125/abigail/perl/ch-1.pl
@@ -0,0 +1,69 @@
+#!/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 < input-file
+#
+
+sub introot ($square) {
+ #
+ # Return the largest integer less than, or equal to the
+ # square root of $square.
+ #
+ int (.4 + sqrt ($square));
+}
+
+
+
+while (my $n = <>) {
+ chomp ($n);
+ say (-1), next if $n <= 2;
+ #
+ # First case, $n is not the hypothenuse; wlog, assume n = a.
+ #
+ # Then, we start searching from c = n + 1 until
+ # c^2 - (c - 1)^2 > n^2. Note that c^2 - (c - 1)^2 = 2c - 1
+ # In each iteration, we calculate b^2 = c^2 - n^2. If b^2 is
+ # a proper square, we have a Pythagorian triple.
+ #
+ my $n_sq = $n * $n;
+
+ my $c = $n + 1;
+ my $c_sq = $n_sq + 2 * $n + 1;
+ while (2 * $c - 1 <= $n_sq) {
+ #
+ # We now have a^2 (n_sq) and c^2. We can calculate b^2 (b_sq)
+ # and check whether this is a proper square.
+ #
+ my $b_sq = $c_sq - $n_sq;
+ my $b = introot ($b_sq);
+
+ say "$n $b $c" if $b_sq == $b * $b;
+ $c_sq += 2 * $c ++ + 1; # (c + 1)^2 == c^2 + 2 * c + 1
+ }
+
+ #
+ # Handle the case $n is the hypothenuse, so $n == c.
+ #
+ # We now need to search for a, b such that a^2 + b^2 = c^2 ($n_sq).
+ # Wlog, assume a < b (a == b cannot happen). Then a < c / sqrt (2).
+ #
+ my $max_a = int ($n / sqrt (2));
+ for (my $a = 3; $a <= $max_a; $a ++) {
+ my $b_sq = $n_sq - $a * $a;
+ my $b = introot ($b_sq);
+ say "$a $b $n" if $b_sq == $b * $b;
+ }
+}
diff --git a/challenge-125/abigail/perl/ch-2.pl b/challenge-125/abigail/perl/ch-2.pl
new file mode 100644
index 0000000000..06006dbe58
--- /dev/null
+++ b/challenge-125/abigail/perl/ch-2.pl
@@ -0,0 +1,79 @@
+#!/opt/perl/bin/perl
+
+use 5.032;
+
+use strict;
+use warnings;
+no warnings 'syntax';
+
+use experimental 'signatures';
+use experimental 'lexical_subs';
+
+#
+# See ../README.md
+#
+
+#
+# Run as: perl ch-2.pl < input-file
+#
+
+package Tree {
+ use Hash::Util::FieldHash qw [fieldhash];
+ use List::Util qw [max];
+
+ fieldhash my %left;
+ fieldhash my %right;
+
+ sub new ($class) {bless do {\my $var} => $class}
+
+ sub init ($self, $input) {
+ #
+ # Initialize a tree given the input following the
+ # specification of how we're given a tree.
+ #
+
+ ...; # <-- This is the yada, yada, yada operator, typically
+ # a placeholder for code which still needs to be written.
+ # Perfect! Once we have a specification of how the
+ # the input is structured (other than a single example
+ # of which anyone can instantly see it doesn't scale
+ # beyond trivial sizes), we can replace this piece of code.
+ #
+ # This does mean though, that rest of the code is largely
+ # untested. "It compiles" is the best we can do.
+ #
+
+ $self;
+ }
+
+ #
+ # Get the left and right child of a tree. Leaves obviously
+ # don't have children.
+ #
+ sub left ($self) {!$self -> isleaf && $left {$self}}
+ sub right ($self) {!$self -> isleaf && $right {$self}}
+ sub isleaf ($self) {!$left {$self} || !$right {$self}}
+
+ sub diameter ($self) {
+ ($self -> _diameter ($self)) [1]
+ }
+
+ sub _diameter ($self) {
+ #
+ # Given a tree, return a tuple ($depth, $diameter), where
+ # first element is the depth of a tree (longest path to a leaf),
+ # and second the diameter (longest path in the tree).
+ #
+ # Depth of a tree is 1 + max (depth left child, depth right child)
+ # Diameter of a tree is max (diameter left child,
+ # diameter right child, depth left child + depth right child).
+ #
+ return (0, 0) if $self -> isleaf; # Leaves have no depth nor diameter.
+ my ($ldp, $ldm) = $self -> left -> _diameter;
+ my ($rdp, $rdm) = $self -> right -> _diameter;
+ (max ($ldp, $rdp), max ($ldm, $rdm, $ldp + $rdp))
+ }
+}
+
+
+say Tree:: -> new -> init (do {local $/; <>}) -> diameter;
diff --git a/challenge-125/abigail/python/ch-1.py b/challenge-125/abigail/python/ch-1.py
new file mode 100644
index 0000000000..f8c07799b3
--- /dev/null
+++ b/challenge-125/abigail/python/ch-1.py
@@ -0,0 +1,41 @@
+#!/opt/local/bin/python
+
+#
+# See ../README.md
+#
+
+#
+# Run as: python ch-1.py < input-file
+#
+
+import fileinput
+import math
+
+def introot (square):
+ return math . floor (.4 + math . sqrt (square))
+
+for line in fileinput . input ():
+ n = int (line)
+ if n <= 2:
+ print (-1)
+ continue
+
+ n_sq = n * n
+ c = n + 1
+ c_sq = n_sq + 2 * n + 1
+ while 2 * c - 1 <= n_sq:
+ b_sq = c_sq - n_sq
+ b = introot (b_sq)
+
+ if b_sq == b * b:
+ print (str (n) + " " + str (b) + " " + str (c))
+
+ c_sq = c_sq + 2 * c + 1
+ c = c + 1
+
+ max_a = math . floor (n / math . sqrt (2))
+ for a in range (3, max_a + 1):
+ b_sq = n_sq - a * a
+ b = introot (b_sq)
+ if b_sq == b * b:
+ print (str (a) + " " + str (b) + " " + str (n))
diff --git a/challenge-125/abigail/r/ch-1.r b/challenge-125/abigail/r/ch-1.r
new file mode 100644
index 0000000000..bd64758e3f
--- /dev/null
+++ b/challenge-125/abigail/r/ch-1.r
@@ -0,0 +1,54 @@
+#
+# See ../README.md
+#
+
+#
+# Run as: Rscript ch-1.r < input-file
+#
+
+introot <- function (square) {
+ return (floor (sqrt (square)))
+}
+
+stdin <- file ('stdin', 'r')
+repeat {
+ n <- readLines (stdin, n = 1)
+ if (length (n) == 0) {
+ break
+ }
+ n <- as.integer (n)
+ if (n <= 2) {
+ cat ("-1\n")
+ next
+ }
+
+ n_sq <- n * n
+ c <- n + 1
+ c_sq <- n_sq + 2 * n + 1
+
+ while (2 * c - 1 <= n_sq) {
+ b_sq <- c_sq - n_sq
+ b <- introot (b_sq)
+
+ if (b_sq == b * b) {
+ cat (n, b, c, "\n")
+ }
+
+ c_sq <- c_sq + 2 * c + 1
+ c <- c + 1
+ }
+
+ max_a = floor (n / sqrt (2))
+ if (max_a < 3) {
+ next
+ }
+ for (a in 3 : max_a) {
+ # cat ("a = ", a, "\n")
+ b_sq <- n_sq - a * a
+ b <- introot (b_sq)
+
+ if (b_sq == b * b) {
+ cat (a, b, n, "\n")
+ }
+ }
+}
diff --git a/challenge-125/abigail/ruby/ch-1.rb b/challenge-125/abigail/ruby/ch-1.rb
new file mode 100644
index 0000000000..91518fc95e
--- /dev/null
+++ b/challenge-125/abigail/ruby/ch-1.rb
@@ -0,0 +1,45 @@
+#!/usr/bin/ruby
+
+#
+# See ../README.md
+#
+
+#
+# Run as: ruby ch-1.rb < input-file
+#
+
+def introot (square)
+ return Math . sqrt(square) . floor()
+end
+
+ARGF . each_line do
+ |n|
+ n = n . to_i
+ if (n <= 2) then
+ puts (-1)
+ end
+
+ n_sq = n * n
+ c = n + 1
+ c_sq = n_sq + 2 * n + 1
+ while (2 * c - 1 <= n_sq) do
+ b_sq = c_sq - n_sq
+ b = introot (b_sq)
+
+ if (b_sq == b * b) then
+ puts (n . to_s + " " + b . to_s + " " + c . to_s)
+ end
+
+ c_sq += 2 * c + 1
+ c += 1
+ end
+
+ max_a = (n / Math . sqrt(2)) . floor()
+ for a in 3 .. max_a do
+ b_sq = n_sq - a * a
+ b = introot (b_sq)
+ if (b_sq == b * b) then
+ puts (a . to_s + " " + b . to_s + " " + n . to_s)
+ end
+ end
+end
diff --git a/challenge-125/abigail/t/ctest.ini b/challenge-125/abigail/t/ctest.ini
new file mode 100644
index 0000000000..44057cf8e4
--- /dev/null
+++ b/challenge-125/abigail/t/ctest.ini
@@ -0,0 +1,10 @@
+#
+# Configuration file for running tests, using ctest.
+# See https://github.com/Abigail/Misc/blob/master/ctest
+#
+
+[names]
+1-1 = Given examples
+1-2 = No solutions
+1-3 = Up to 100
+1-4 = Primes up to 1000
diff --git a/challenge-125/abigail/t/input-1-1 b/challenge-125/abigail/t/input-1-1
new file mode 100644
index 0000000000..48685feaae
--- /dev/null
+++ b/challenge-125/abigail/t/input-1-1
@@ -0,0 +1,3 @@
+5
+13
+1
diff --git a/challenge-125/abigail/t/input-1-2 b/challenge-125/abigail/t/input-1-2
new file mode 100644
index 0000000000..1191247b6d
--- /dev/null
+++ b/challenge-125/abigail/t/input-1-2
@@ -0,0 +1,2 @@
+1
+2
diff --git a/challenge-125/abigail/t/input-1-3 b/challenge-125/abigail/t/input-1-3
new file mode 100644
index 0000000000..3758ba5b23
--- /dev/null
+++ b/challenge-125/abigail/t/input-1-3
@@ -0,0 +1,98 @@
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+68
+69
+70
+71
+72
+73
+74
+75
+76
+77
+78
+79
+80
+81
+82
+83
+84
+85
+86
+87
+88
+89
+90
+91
+92
+93
+94
+95
+96
+97
+98
+99
+100
diff --git a/challenge-125/abigail/t/input-1-4 b/challenge-125/abigail/t/input-1-4
new file mode 100644
index 0000000000..0aa2bff2b8
--- /dev/null
+++ b/challenge-125/abigail/t/input-1-4
@@ -0,0 +1,143 @@
+101
+103
+107
+109
+113
+127
+131
+137
+139
+149
+151
+157
+163
+167
+173
+179
+181
+191
+193
+197
+199
+211
+223
+227
+229
+233
+239
+241
+251
+257
+263
+269
+271
+277
+281
+283
+293
+307
+311
+313
+317
+331
+337
+347
+349
+353
+359
+367
+373
+379
+383
+389
+397
+401
+409
+419
+421
+431
+433
+439
+443