From 4699f600935129b16a48074d8534411ce935db17 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 3 Jan 2022 12:25:51 +0100 Subject: Week 146 Part 1 is a fixed output challenge, so, just a glorified Hello World program. It's stolen from project Euler, task 7. --- challenge-146/abigail/README.md | 20 ++++++++++++-- challenge-146/abigail/awk/ch-1.awk | 13 +++++++++ challenge-146/abigail/awk/ch-2.awk | 30 +++++++++++++++++++++ challenge-146/abigail/bash/ch-1.sh | 11 ++++++++ challenge-146/abigail/bash/ch-2.sh | 27 +++++++++++++++++++ challenge-146/abigail/basic/ch-1.bas | 9 +++++++ challenge-146/abigail/bc/ch-1.bc | 10 +++++++ challenge-146/abigail/bc/ch-2.bc | 26 ++++++++++++++++++ challenge-146/abigail/befunge-93/ch-1.bf93 | 2 ++ challenge-146/abigail/c/ch-1.c | 16 ++++++++++++ challenge-146/abigail/c/ch-2.c | 33 +++++++++++++++++++++++ challenge-146/abigail/cobol/ch-1.cb | 14 ++++++++++ challenge-146/abigail/csh/ch-1.csh | 11 ++++++++ challenge-146/abigail/erlang/ch-1.erl | 15 +++++++++++ challenge-146/abigail/forth/ch-1.fs | 5 ++++ challenge-146/abigail/fortran/ch-1.f90 | 12 +++++++++ challenge-146/abigail/go/ch-1.go | 15 +++++++++++ challenge-146/abigail/go/ch-2.go | 42 ++++++++++++++++++++++++++++++ challenge-146/abigail/java/ch-1.java | 13 +++++++++ challenge-146/abigail/java/ch-2.java | 33 +++++++++++++++++++++++ challenge-146/abigail/lua/ch-1.lua | 11 ++++++++ challenge-146/abigail/lua/ch-2.lua | 28 ++++++++++++++++++++ challenge-146/abigail/m4/ch-1.m4 | 1 + challenge-146/abigail/mmix/ch-1.mms | 16 ++++++++++++ challenge-146/abigail/node/ch-1.js | 11 ++++++++ challenge-146/abigail/node/ch-2.js | 31 ++++++++++++++++++++++ challenge-146/abigail/ocaml/ch-1.ml | 9 +++++++ challenge-146/abigail/pascal/ch-1.p | 13 +++++++++ challenge-146/abigail/pascal/ch-2.p | 42 ++++++++++++++++++++++++++++++ challenge-146/abigail/perl/ch-1.pl | 31 ++++++++++++++++++++++ challenge-146/abigail/perl/ch-2.pl | 40 ++++++++++++++++++++++++++++ challenge-146/abigail/php/ch-1.php | 11 ++++++++ challenge-146/abigail/postscript/ch-1.ps | 10 +++++++ challenge-146/abigail/python/ch-1.py | 11 ++++++++ challenge-146/abigail/python/ch-2.py | 24 +++++++++++++++++ challenge-146/abigail/r/ch-1.r | 9 +++++++ challenge-146/abigail/r/ch-2.r | 31 ++++++++++++++++++++++ challenge-146/abigail/rexx/ch-1.rexx | 9 +++++++ challenge-146/abigail/ruby/ch-1.rb | 11 ++++++++ challenge-146/abigail/ruby/ch-2.rb | 26 ++++++++++++++++++ challenge-146/abigail/scheme/ch-1.scm | 9 +++++++ challenge-146/abigail/scheme/ch-2.scm | 41 +++++++++++++++++++++++++++++ challenge-146/abigail/sed/ch-1.sed | 12 +++++++++ challenge-146/abigail/sql/ch-1.sql | 9 +++++++ challenge-146/abigail/t/ctest.ini | 12 +++++++++ challenge-146/abigail/t/input-1-1 | 1 + challenge-146/abigail/t/input-2-1 | 2 ++ challenge-146/abigail/t/input-2-2 | 3 +++ challenge-146/abigail/t/output-1-1.exp | 1 + challenge-146/abigail/t/output-2-1.exp | 2 ++ challenge-146/abigail/t/output-2-2.exp | 3 +++ challenge-146/abigail/tcl/ch-1.tcl | 9 +++++++ challenge-146/abigail/tcl/ch-2.tcl | 23 ++++++++++++++++ 53 files changed, 857 insertions(+), 2 deletions(-) create mode 100644 challenge-146/abigail/awk/ch-1.awk create mode 100644 challenge-146/abigail/awk/ch-2.awk create mode 100644 challenge-146/abigail/bash/ch-1.sh create mode 100644 challenge-146/abigail/bash/ch-2.sh create mode 100644 challenge-146/abigail/basic/ch-1.bas create mode 100644 challenge-146/abigail/bc/ch-1.bc create mode 100644 challenge-146/abigail/bc/ch-2.bc create mode 100644 challenge-146/abigail/befunge-93/ch-1.bf93 create mode 100644 challenge-146/abigail/c/ch-1.c create mode 100644 challenge-146/abigail/c/ch-2.c create mode 100644 challenge-146/abigail/cobol/ch-1.cb create mode 100644 challenge-146/abigail/csh/ch-1.csh create mode 100644 challenge-146/abigail/erlang/ch-1.erl create mode 100644 challenge-146/abigail/forth/ch-1.fs create mode 100644 challenge-146/abigail/fortran/ch-1.f90 create mode 100644 challenge-146/abigail/go/ch-1.go create mode 100644 challenge-146/abigail/go/ch-2.go create mode 100644 challenge-146/abigail/java/ch-1.java create mode 100644 challenge-146/abigail/java/ch-2.java create mode 100644 challenge-146/abigail/lua/ch-1.lua create mode 100644 challenge-146/abigail/lua/ch-2.lua create mode 100644 challenge-146/abigail/m4/ch-1.m4 create mode 100644 challenge-146/abigail/mmix/ch-1.mms create mode 100644 challenge-146/abigail/node/ch-1.js create mode 100644 challenge-146/abigail/node/ch-2.js create mode 100644 challenge-146/abigail/ocaml/ch-1.ml create mode 100644 challenge-146/abigail/pascal/ch-1.p create mode 100644 challenge-146/abigail/pascal/ch-2.p create mode 100644 challenge-146/abigail/perl/ch-1.pl create mode 100644 challenge-146/abigail/perl/ch-2.pl create mode 100644 challenge-146/abigail/php/ch-1.php create mode 100644 challenge-146/abigail/postscript/ch-1.ps create mode 100644 challenge-146/abigail/python/ch-1.py create mode 100644 challenge-146/abigail/python/ch-2.py create mode 100644 challenge-146/abigail/r/ch-1.r create mode 100644 challenge-146/abigail/r/ch-2.r create mode 100644 challenge-146/abigail/rexx/ch-1.rexx create mode 100644 challenge-146/abigail/ruby/ch-1.rb create mode 100644 challenge-146/abigail/ruby/ch-2.rb create mode 100644 challenge-146/abigail/scheme/ch-1.scm create mode 100644 challenge-146/abigail/scheme/ch-2.scm create mode 100644 challenge-146/abigail/sed/ch-1.sed create mode 100644 challenge-146/abigail/sql/ch-1.sql create mode 100644 challenge-146/abigail/t/ctest.ini create mode 100644 challenge-146/abigail/t/input-1-1 create mode 100644 challenge-146/abigail/t/input-2-1 create mode 100644 challenge-146/abigail/t/input-2-2 create mode 100644 challenge-146/abigail/t/output-1-1.exp create mode 100644 challenge-146/abigail/t/output-2-1.exp create mode 100644 challenge-146/abigail/t/output-2-2.exp create mode 100644 challenge-146/abigail/tcl/ch-1.tcl create mode 100644 challenge-146/abigail/tcl/ch-2.tcl diff --git a/challenge-146/abigail/README.md b/challenge-146/abigail/README.md index 9841e920c1..f819e6f82c 100644 --- a/challenge-146/abigail/README.md +++ b/challenge-146/abigail/README.md @@ -4,24 +4,40 @@ * [AWK](awk/ch-1.awk) * [Bash](bash/ch-1.sh) -* [bc](bc/ch-1.bc) +* [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](lua/ch-1.erl) +* [Forth](lua/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) -* [Tcl](tcl/ch-1.tcl) * [Scheme](scheme/ch-1.scm) +* [Sed](sed/ch-1.sed) +* [SQL](sql/ch-1.sql) +* [Tcl](tcl/ch-1.tcl) ## Part 2 * [AWK](awk/ch-2.awk) * [Bash](bash/ch-2.sh) +* [bc](bc/ch-2.bc) * [C](c/ch-2.c) * [Go](go/ch-2.go) * [Java](java/ch-2.java) diff --git a/challenge-146/abigail/awk/ch-1.awk b/challenge-146/abigail/awk/ch-1.awk new file mode 100644 index 0000000000..53c43cdbc1 --- /dev/null +++ b/challenge-146/abigail/awk/ch-1.awk @@ -0,0 +1,13 @@ +#!/usr/bin/awk + +# +# See ../README.md +# + +# +# Run as: awk -f ch-1.awk +# + +BEGIN { + print "104743" +} \ No newline at end of file diff --git a/challenge-146/abigail/awk/ch-2.awk b/challenge-146/abigail/awk/ch-2.awk new file mode 100644 index 0000000000..6556f70797 --- /dev/null +++ b/challenge-146/abigail/awk/ch-2.awk @@ -0,0 +1,30 @@ +#!/usr/bin/awk + +# +# See ../README.md +# + +# +# Run as: awk -f ch-2.awk < input-file +# + +BEGIN { + FS = "/" +} + +{ + a = $1; b = $2 + for (i = 1; i <= 2; i ++) { + if (a < b) { + b = b - a + } + else { + a = a - b + } + if (!a || !b) { + break + } + printf "%d/%d ", a, b + } + printf "\n" +} diff --git a/challenge-146/abigail/bash/ch-1.sh b/challenge-146/abigail/bash/ch-1.sh new file mode 100644 index 0000000000..64ba3a2d29 --- /dev/null +++ b/challenge-146/abigail/bash/ch-1.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +# +# See ../README.md +# + +# +# Run as: bash ch-1.sh +# + +echo "104743" \ No newline at end of file diff --git a/challenge-146/abigail/bash/ch-2.sh b/challenge-146/abigail/bash/ch-2.sh new file mode 100644 index 0000000000..5a5ee147f5 --- /dev/null +++ b/challenge-146/abigail/bash/ch-2.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +# +# See ../README.md +# + +# +# Run as: bash ch-2.sh < input-file +# + +set -f + +IFS=/ + +while read a b +do for ((i = 1; i <= 2; i ++)) + do if ((a < b)) + then ((b -= a)) + else ((a -= b)) + fi + if ((a == 0 || b == 0)) + then break + fi + printf "$a/$b " + done + echo +done diff --git a/challenge-146/abigail/basic/ch-1.bas b/challenge-146/abigail/basic/ch-1.bas new file mode 100644 index 0000000000..0d4fc1fd20 --- /dev/null +++ b/challenge-146/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 "104743" \ No newline at end of file diff --git a/challenge-146/abigail/bc/ch-1.bc b/challenge-146/abigail/bc/ch-1.bc new file mode 100644 index 0000000000..6a298809f8 --- /dev/null +++ b/challenge-146/abigail/bc/ch-1.bc @@ -0,0 +1,10 @@ +# +# See ../README.md +# + +# +# Run as: bc ch-1.bc +# +"104743 +" +quit \ No newline at end of file diff --git a/challenge-146/abigail/bc/ch-2.bc b/challenge-146/abigail/bc/ch-2.bc new file mode 100644 index 0000000000..04f267e202 --- /dev/null +++ b/challenge-146/abigail/bc/ch-2.bc @@ -0,0 +1,26 @@ +# +# See ../README.md +# + +# +# Run as: bc ch-2.bc < input-file +# + +while (1) { + a = read (); if (a == 0) {break} + b = read (); if (b == 0) {break} + for (i = 1; i <= 2; i ++) { + if (a < b) { + b = b - a + } else { + a = a - b + } + if (a == 0 || b == 0) { + break + } + print a, "/", b, " " + } + " +" +} + diff --git a/challenge-146/abigail/befunge-93/ch-1.bf93 b/challenge-146/abigail/befunge-93/ch-1.bf93 new file mode 100644 index 0000000000..2db34c5d84 --- /dev/null +++ b/challenge-146/abigail/befunge-93/ch-1.bf93 @@ -0,0 +1,2 @@ +< v,_@#:< "104743" +55 + > ^ \ No newline at end of file diff --git a/challenge-146/abigail/c/ch-1.c b/challenge-146/abigail/c/ch-1.c new file mode 100644 index 0000000000..c2fb69f376 --- /dev/null +++ b/challenge-146/abigail/c/ch-1.c @@ -0,0 +1,16 @@ +# include +# include +# include + +/* + * See ../README.md + */ + +/* + * Run as: cc -o ch-1.o ch-1.c; ./ch-1.o + */ + +int main (void) { + printf ("104743\n"); + exit (0); +} \ No newline at end of file diff --git a/challenge-146/abigail/c/ch-2.c b/challenge-146/abigail/c/ch-2.c new file mode 100644 index 0000000000..ca81789f6f --- /dev/null +++ b/challenge-146/abigail/c/ch-2.c @@ -0,0 +1,33 @@ +# include +# include +# include + +/* + * See ../README.md + */ + +/* + * Run as: cc -o ch-2.o ch-2.c; ./ch-2.o < input-file + */ + +int main (void) { + int a, b; + + while (scanf ("%d/%d", &a, &b) == 2) { + for (int i = 1; i <= 2; i ++) { + if (a < b) { + b -= a; + } + else { + a -= b; + } + if (!a || !b) { + break; + } + printf ("%d/%d ", a, b); + } + printf ("\n"); + } + + return (0); +} diff --git a/challenge-146/abigail/cobol/ch-1.cb b/challenge-146/abigail/cobol/ch-1.cb new file mode 100644 index 0000000000..6769477733 --- /dev/null +++ b/challenge-146/abigail/cobol/ch-1.cb @@ -0,0 +1,14 @@ +IDENTIFICATION DIVISION. +PROGRAM-ID. XXX. + +*> +*> See ../README.md +*> + +*> +*> Run as: cobc -xF -o ch-1.o ch-1.cb; ./ch-1.o +*> + +PROCEDURE DIVISION. + DISPLAY "104743". + STOP RUN. diff --git a/challenge-146/abigail/csh/ch-1.csh b/challenge-146/abigail/csh/ch-1.csh new file mode 100644 index 0000000000..4997623bf2 --- /dev/null +++ b/challenge-146/abigail/csh/ch-1.csh @@ -0,0 +1,11 @@ +#!/bin/csh + +# +# See ../README.md +# + +# +# Run as: csh ch-1.csh +# + +echo "104743" \ No newline at end of file diff --git a/challenge-146/abigail/erlang/ch-1.erl b/challenge-146/abigail/erlang/ch-1.erl new file mode 100644 index 0000000000..978a2ef1b4 --- /dev/null +++ b/challenge-146/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 ("104743\n"). \ No newline at end of file diff --git a/challenge-146/abigail/forth/ch-1.fs b/challenge-146/abigail/forth/ch-1.fs new file mode 100644 index 0000000000..0ee96cf454 --- /dev/null +++ b/challenge-146/abigail/forth/ch-1.fs @@ -0,0 +1,5 @@ +\ +\ See ../README.md +\ + +.( 104743) \ No newline at end of file diff --git a/challenge-146/abigail/fortran/ch-1.f90 b/challenge-146/abigail/fortran/ch-1.f90 new file mode 100644 index 0000000000..4cda0b2f0b --- /dev/null +++ b/challenge-146/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 (*, *) "104743" +end \ No newline at end of file diff --git a/challenge-146/abigail/go/ch-1.go b/challenge-146/abigail/go/ch-1.go new file mode 100644 index 0000000000..52cc0af532 --- /dev/null +++ b/challenge-146/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 ("104743\n") +} \ No newline at end of file diff --git a/challenge-146/abigail/go/ch-2.go b/challenge-146/abigail/go/ch-2.go new file mode 100644 index 0000000000..6aff154b1f --- /dev/null +++ b/challenge-146/abigail/go/ch-2.go @@ -0,0 +1,42 @@ +package main + +// +// See ../README.md +// + +// +// Run as: go run ch-2.go +// + +import ( + "fmt" + "bufio" + "os" +) + +func main () { + var reader = bufio . NewReader (os. Stdin) + for { + var text, err = reader . ReadString ('\n') + if (err != nil) { + break + } + var a, b int; + var n, err2 = fmt . Sscanf (text, "%d/%d", &a, &b) + if (n != 2 || err2 != nil) { + continue + } + for i := 1; i <= 2; i ++ { + if a < b { + b -= a + } else { + a -= b + } + if a == 0 || b == 0 { + break + } + fmt . Printf ("%d/%d ", a, b) + } + fmt . Println ("") + } +} diff --git a/challenge-146/abigail/java/ch-1.java b/challenge-146/abigail/java/ch-1.java new file mode 100644 index 0000000000..33133c5aa1 --- /dev/null +++ b/challenge-146/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 ("104743\n"); + } +} \ No newline at end of file diff --git a/challenge-146/abigail/java/ch-2.java b/challenge-146/abigail/java/ch-2.java new file mode 100644 index 0000000000..07ab2feea9 --- /dev/null +++ b/challenge-146/abigail/java/ch-2.java @@ -0,0 +1,33 @@ +// +// See ../README.md +// + +// +// Run as: ln ch-2.java ch2.java; javac ch2.java; java ch2 < input-file +// + +import java.util.*; + +public class ch2 { + public static void main (String [] args) { + Scanner scanner = new Scanner (System . in); + while (scanner . hasNextLine ()) { + String [] parts = scanner . nextLine () . trim () . split ("/"); + int a = Integer . parseInt (parts [0]); + int b = Integer . parseInt (parts [1]); + for (int i = 1; i <= 2; i ++) { + if (a < b) { + b -= a; + } + else { + a -= b; + } + if (a == 0 || b == 0) { + break; + } + System . out . printf ("%d/%d ", a, b); + } + System . out . printf ("\n"); + } + } +} diff --git a/challenge-146/abigail/lua/ch-1.lua b/challenge-146/abigail/lua/ch-1.lua new file mode 100644 index 0000000000..563c4fbf4b --- /dev/null +++ b/challenge-146/abigail/lua/ch-1.lua @@ -0,0 +1,11 @@ +#!/opt/local/bin/lua + +-- +-- See ../README.md +-- + +-- +-- Run as: lua ch-1.lua +-- + +print ("104743") \ No newline at end of file diff --git a/challenge-146/abigail/lua/ch-2.lua b/challenge-146/abigail/lua/ch-2.lua new file mode 100644 index 0000000000..7429222642 --- /dev/null +++ b/challenge-146/abigail/lua/ch-2.lua @@ -0,0 +1,28 @@ +#!/opt/local/bin/lua + +-- +-- See ../README.md +-- + +-- +-- Run as: lua ch-2.lua < input-file +-- + +for line in io . lines () do + local _, _, a, b = line : find ("([0-9]+)/([0-9]+)") + a = tonumber (a) + b = tonumber (b) + for i = 1, 2 do + if a < b then + b = b - a + else + a = a - b + end + if a == 0 or b == 0 then + goto out_of_loop + end + io . write (a .. "/" .. b .. " ") + end + ::out_of_loop:: + io . write ("\n") +end diff --git a/challenge-146/abigail/m4/ch-1.m4 b/challenge-146/abigail/m4/ch-1.m4 new file mode 100644 index 0000000000..3f5232d9b5 --- /dev/null +++ b/challenge-146/abigail/m4/ch-1.m4 @@ -0,0 +1 @@ +104743 diff --git a/challenge-146/abigail/mmix/ch-1.mms b/challenge-146/abigail/mmix/ch-1.mms new file mode 100644 index 0000000000..a5c39532dd --- /dev/null +++ b/challenge-146/abigail/mmix/ch-1.mms @@ -0,0 +1,16 @@ +% +% See ../README.md +% + +% +% Run as: mmixal -o ch-1.mmo ch-1.mms; mmix -q ch-1.mmo +% + LOC Data_Segment + GREG @ +Text BYTE "104743",10,0 + + LOC #100 + +Main LDA $255,Text + TRAP 0,Fputs,StdOut + TRAP 0,Halt,0 \ No newline at end of file diff --git a/challenge-146/abigail/node/ch-1.js b/challenge-146/abigail/node/ch-1.js new file mode 100644 index 0000000000..51ce680b89 --- /dev/null +++ b/challenge-146/abigail/node/ch-1.js @@ -0,0 +1,11 @@ +#!/usr/local/bin/node + +// +// See ../README.md +// + +// +// Run as: node ch-1.js +// + +console . log ("104743") \ No newline at end of file diff --git a/challenge-146/abigail/node/ch-2.js b/challenge-146/abigail/node/ch-2.js new file mode 100644 index 0000000000..ce7fba74c7 --- /dev/null +++ b/challenge-146/abigail/node/ch-2.js @@ -0,0 +1,31 @@ +#!/usr/local/bin/node + +// +// See ../README.md +// + +// +// Run as: node ch-2.js < input-file +// + + require ('readline') +. createInterface ({input: process . stdin}) +. on ('line', line => { + let [a, b] = line . trim () . split ("/") . map (x => +x) + for (let i = 1; i <= 2; i ++) { + if (a < b) { + b -= a + } + else { + a -= b + } + if (a == 0 || b == 0) { + break + } + process . stdout . write (a . toString ()) + process . stdout . write ("/") + process . stdout . write (b . toString ()) + process . stdout . write (" ") + } + process . stdout . write ("\n") +}) diff --git a/challenge-146/abigail/ocaml/ch-1.ml b/challenge-146/abigail/ocaml/ch-1.ml new file mode 100644 index 0000000000..606c4d6dcc --- /dev/null +++ b/challenge-146/abigail/ocaml/ch-1.ml @@ -0,0 +1,9 @@ +(* *) +(* See ../README.md *) +(* *) + +(* *) +(* Run as: ocaml ch-1.ml *) +(* *) + +print_endline "104743"; \ No newline at end of file diff --git a/challenge-146/abigail/pascal/ch-1.p b/challenge-146/abigail/pascal/ch-1.p new file mode 100644 index 0000000000..5cbe457fcf --- /dev/null +++ b/challenge-146/abigail/pascal/ch-1.p @@ -0,0 +1,13 @@ +Program XXX; + +(* *) +(* See ../README.md *) +(* *) + +(* *) +(* Run as: fpc -och-1.out ch-1.p; ./ch-1.out *) +(* *) + +begin + writeln ('104743') +end. \ No newline at end of file diff --git a/challenge-146/abigail/pascal/ch-2.p b/challenge-146/abigail/pascal/ch-2.p new file mode 100644 index 0000000000..983d69379c --- /dev/null +++ b/challenge-146/abigail/pascal/ch-2.p @@ -0,0 +1,42 @@ +Program ch2; + +(* *) +(* See ../README.md *) +(* *) + +(* *) +(* Run as: fpc -och-2.out ch-2.p; ./ch-2.out < input-file *) +(* *) + +uses + sysutils; + +var + line: string; + a, b: integer; + i, x: integer; + +begin + while not eof do begin + readln (line); + x := pos ('/', line); + a := strtoint (copy (line, 1, x - 1)); + b := strtoint (copy (line, x + 1, length (line) - x)); + for i := 1 to 2 do begin + if a < b then begin + b := b - a; + end + else begin + a := a - b; + end; + if (a = 0) or (b = 0) then begin + break; + end; + write (a); + write ('/'); + write (b); + write (' '); + end; + writeln (''); + end +end. diff --git a/challenge-146/abigail/perl/ch-1.pl b/challenge-146/abigail/perl/ch-1.pl new file mode 100644 index 0000000000..1ea427f161 --- /dev/null +++ b/challenge-146/abigail/perl/ch-1.pl @@ -0,0 +1,31 @@ +#!/opt/perl/bin/perl + +use 5.032; + +use strict; +use warnings; +no warnings 'syntax'; + +use experimental 'signatures'; +use experimental 'lexical_subs'; + +# +# See Project Euler, task 7. +# + +# +# Run as: perl ch-1.pl +# + +# +# Math::Prime::Util::PrimeArray gives us a tied array, so that it's +# Nth element is the Nth prime. Which is all we need. +# +# Still far less efficient (both in loc and run time) than just "say 104743" +# + +use Math::Prime::Util::PrimeArray; +tie my @p, 'Math::Prime::Util::PrimeArray'; +say $p [10000]; + +__END__ diff --git a/challenge-146/abigail/perl/ch-2.pl b/challenge-146/abigail/perl/ch-2.pl new file mode 100644 index 0000000000..c50e325692 --- /dev/null +++ b/challenge-146/abigail/perl/ch-2.pl @@ -0,0 +1,40 @@ +#!/opt/perl/bin/perl + +use 5.032; + +use strict; +use warnings; +no warnings 'syntax'; + +use experimental 'signatures'; +use experimental 'lexical_subs'; + +# +# Run as: perl ch-2.pl < input-file +# + +# +# Let's assume the "Curious Fraction Tree" is the one of Google's +# first hit, and which can unambiguously described as: +# +# * The root is 1/1 +# * Each node a/b has children a/(a + b) and (a + b)/b +# +# without having to rely on an image which needs to be interpolated. +# Of course, we also have to utterly ignore the existance of +# "the tree created similar to the above sample", as similar implies +# it being different. +# +# (PLEASE, PLEASE, PLEASE, spend 30 seconds more to make your challenges +# less ambiguous. Ambiguous challenges are not a feature, it's sloppiness). +# + +while (<>) { + my ($a, $b) = /[0-9]+/g; + for (1, 2) { + $a < $b ? ($b -= $a) : ($a -= $b); + last unless $a && $b; + print "$a/$b "; + } + print "\n"; +} diff --git a/challenge-146/abigail/php/ch-1.php b/challenge-146/abigail/php/ch-1.php new file mode 100644 index 0000000000..418c08c70c --- /dev/null +++ b/challenge-146/abigail/php/ch-1.php @@ -0,0 +1,11 @@ + \ No newline at end of file diff --git a/challenge-146/abigail/postscript/ch-1.ps b/challenge-146/abigail/postscript/ch-1.ps new file mode 100644 index 0000000000..f3893eef24 --- /dev/null +++ b/challenge-146/abigail/postscript/ch-1.ps @@ -0,0 +1,10 @@ +%!PS +% +% See ../README.md +% + +% +% Run as: ps2ascii ch-1.ps +% + +(104743) = \ No newline at end of file diff --git a/challenge-146/abigail/python/ch-1.py b/challenge-146/abigail/python/ch-1.py new file mode 100644 index 0000000000..b82ae3bd95 --- /dev/null +++ b/challenge-146/abigail/python/ch-1.py @@ -0,0 +1,11 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-1.py +# + +print ("104743") \ No newline at end of file diff --git a/challenge-146/abigail/python/ch-2.py b/challenge-146/abigail/python/ch-2.py new file mode 100644 index 0000000000..bf3f380742 --- /dev/null +++ b/challenge-146/abigail/python/ch-2.py @@ -0,0 +1,24 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-2.py < input-file +# + +import fileinput +import sys + +for line in fileinput . input (): + a, b = map (lambda x: int (x), line . strip () . split ("/")) + for i in range (2): + if a < b: + b = b - a + else: + a = a - b + if a == 0 or b == 0: + break + sys . stdout . write ("{:}/{:} " . format (a, b)) + print ("") diff --git a/challenge-146/abigail/r/ch-1.r b/challenge-146/abigail/r/ch-1.r new file mode 100644 index 0000000000..5eab4a195b --- /dev/null +++ b/challenge-146/abigail/r/ch-1.r @@ -0,0 +1,9 @@ +# +# See ../README.md +# + +# +# Run as: Rscript ch-1.r +# + +cat ("104743\n") \ No newline at end of file diff --git a/challenge-146/abigail/r/ch-2.r b/challenge-146/abigail/r/ch-2.r new file mode 100644 index 0000000000..2402e7a77f --- /dev/null +++ b/challenge-146/abigail/r/ch-2.r @@ -0,0 +1,31 @@ +# +# See ../README.md +# + +# +# Run as: Rscript ch-2.r < input-file +# + +stdin <- file ('stdin', 'r') +repeat { + line <- readLines (stdin, n = 1) + if (length (line) == 0) { + break + } + parts <- strsplit (line, '/') + a <- as.numeric (parts [[1]] [[1]]) + b <- as.numeric (parts [[1]] [[2]]) + for (i in 1 : 2) { + if (a < b) { + b = b - a + } + else { + a = a - b + } + if (a == 0 || b == 0) { + break + } + cat (a, '/', b, ' ', sep = '') + } + cat ("\n") +} diff --git a/challenge-146/abigail/rexx/ch-1.rexx b/challenge-146/abigail/rexx/ch-1.rexx new file mode 100644 index 0000000000..b1f554c48e --- /dev/null +++ b/challenge-146/abigail/rexx/ch-1.rexx @@ -0,0 +1,9 @@ +/* + * See ../README.md + */ + +/* + * Run as: rexx ch-1.rexx + */ + +say "104743" \ No newline at end of file diff --git a/challenge-146/abigail/ruby/ch-1.rb b/challenge-146/abigail/ruby/ch-1.rb new file mode 100644 index 0000000000..5c5bbf5bb5 --- /dev/null +++ b/challenge-146/abigail/ruby/ch-1.rb @@ -0,0 +1,11 @@ +#!/usr/bin/ruby + +# +# See ../README.md +# + +# +# Run as: ruby ch-1.rb +# + +puts ("104743"); \ No newline at end of file diff --git a/challenge-146/abigail/ruby/ch-2.rb b/challenge-146/abigail/ruby/ch-2.rb new file mode 100644 index 0000000000..e664fb75e2 --- /dev/null +++ b/challenge-146/abigail/ruby/ch-2.rb @@ -0,0 +1,26 @@ +#!/usr/bin/ruby + +# +# See ../README.md +# + +# +# Run as: ruby ch-2.rb < input-file +# + +ARGF . each_line do + | line | + a, b = line . strip() . split("/") . map {|x| x . to_i} + for i in 1 .. 2 do + if a < b then + b -= a + else + a -= b + end + if a == 0 || b == 0 then + next + end + print a, "/", b, " " + end + puts ("") +end diff --git a/challenge-146/abigail/scheme/ch-1.scm b/challenge-146/abigail/scheme/ch-1.scm new file mode 100644 index 0000000000..4908a6cc3a --- /dev/null +++ b/challenge-146/abigail/scheme/ch-1.scm @@ -0,0 +1,9 @@ +;;; +;;; See ../README.md +;;; + +;;; +;;; Run as: guile --no-auto-compile ch-1.scm +;;; + +(display "104743\n") \ No newline at end of file diff --git a/challenge-146/abigail/scheme/ch-2.scm b/challenge-146/abigail/scheme/ch-2.scm new file mode 100644 index 0000000000..d6768079ef --- /dev/null +++ b/challenge-146/abigail/scheme/ch-2.scm @@ -0,0 +1,41 @@ +;;; +;;; See ../README.md +;;; + +;;; +;;; Run as: guile --no-auto-compile ch-2.scm < input-file +;;; + +(use-modules (ice-9 rdelim)) + +(define (main) + (define line (read-line)) + (define parts) + (define a) + (define b) + (if (not (eof-object? line)) + (begin + (set! parts (string-split line #\/)) + (set! a (string->number (list-ref parts 0))) + (set! b (string->number (list-ref parts 1))) + (do ((i 1 (1+ i))) + ((or (= i 3) (= a 0) (= b 0))) + (begin + (if (< a b) (set! b (- b a)) (set! a (- a b))) + (if (and (> a 0) (> b 0)) + (begin + (display a) + (display "/") + (display b) + (display " ") + ) + ) + ) + ) + (newline) + (main) + ) + ) +) + +(main) diff --git a/challenge-146/abigail/sed/ch-1.sed b/challenge-146/abigail/sed/ch-1.sed new file mode 100644 index 0000000000..3502f1d6ef --- /dev/null +++ b/challenge-146/abigail/sed/ch-1.sed @@ -0,0 +1,12 @@ +# +# See ../README.md +# + +# +# Run as: sed -f ch-1.sed +# +# For each line in the input file, we write the first three +# self-describing numbers. +# + +s/.*/104743/ \ No newline at end of file diff --git a/challenge-146/abigail/sql/ch-1.sql b/challenge-146/abigail/sql/ch-1.sql new file mode 100644 index 0000000000..6ffc9be0ec --- /dev/null +++ b/challenge-146/abigail/sql/ch-1.sql @@ -0,0 +1,9 @@ +-- +-- See ../README.md +-- + +-- +-- Run as: sqlite3 < ch-1.sql +-- + +SELECT "104743"; \ No newline at end of file diff --git a/challenge-146/abigail/t/ctest.ini b/challenge-146/abigail/t/ctest.ini new file mode 100644 index 0000000000..d530e688e9 --- /dev/null +++ b/challenge-146/abigail/t/ctest.ini @@ -0,0 +1,12 @@ +# +# Configuration file for running tests, using ctest. +# See https://github.com/Abigail/Misc/blob/master/ctest +# + +[names] +1-1 = Fixed Output +2-1 = Given Examples +2-2 = Root and roots children + +[2-1,2-2/bc] +add_to_input = 0 diff --git a/challenge-146/abigail/t/input-1-1 b/challenge-146/abigail/t/input-1-1 new file mode 100644 index 0000000000..8d1c8b69c3 --- /dev/null +++ b/challenge-146/abigail/t/input-1-1 @@ -0,0 +1 @@ + diff --git a/challenge-146/abigail/t/input-2-1 b/challenge-146/abigail/t/input-2-1 new file mode 100644 index 0000000000..388a080335 --- /dev/null +++ b/challenge-146/abigail/t/input-2-1 @@ -0,0 +1,2 @@ +3/5 +4/3 diff --git a/challenge-146/abigail/t/input-2-2 b/challenge-146/abigail/t/input-2-2 new file mode 100644 index 0000000000..a9c1689aba --- /dev/null +++ b/challenge-146/abigail/t/input-2-2 @@ -0,0 +1,3 @@ +1/1 +1/2 +2/1 diff --git a/challenge-146/abigail/t/output-1-1.exp b/challenge-146/abigail/t/output-1-1.exp new file mode 100644 index 0000000000..3f5232d9b5 --- /dev/null +++ b/challenge-146/abigail/t/output-1-1.exp @@ -0,0 +1 @@ +104743 diff --git a/challenge-146/abigail/t/output-2-1.exp b/challenge-146/abigail/t/output-2-1.exp new file mode 100644 index 0000000000..a5b53bfef4 --- /dev/null +++ b/challenge-146/abigail/t/output-2-1.exp @@ -0,0 +1,2 @@ +3/2 1/2 +1/3 1/2 diff --git a/challenge-146/abigail/t/output-2-2.exp b/challenge-146/abigail/t/output-2-2.exp new file mode 100644 index 0000000000..ee4c9f0f32 --- /dev/null +++ b/challenge-146/abigail/t/output-2-2.exp @@ -0,0 +1,3 @@ + +1/1 +1/1 diff --git a/challenge-146/abigail/tcl/ch-1.tcl b/challenge-146/abigail/tcl/ch-1.tcl new file mode 100644 index 0000000000..87c83235ee --- /dev/null +++ b/challenge-146/abigail/tcl/ch-1.tcl @@ -0,0 +1,9 @@ +# +# See ../README.md +# + +# +# Run as: tclsh ch-1.tcl +# + +puts "104743" \ No newline at end of file diff --git a/challenge-146/abigail/tcl/ch-2.tcl b/challenge-146/abigail/tcl/ch-2.tcl new file mode 100644 index 0000000000..91aad66eb6 --- /dev/null +++ b/challenge-146/abigail/tcl/ch-2.tcl @@ -0,0 +1,23 @@ +# +# See ../README.md +# + +# +# Run as: tclsh ch-2.tcl < input-file +# + +while {[gets stdin line] >= 0} { + lassign [split $line "/"] a b + for {set i 1} {$i <= 2} {incr i} { + if {$a < $b} { + set b [expr $b - $a] + } else { + set a [expr $a - $b] + } + if {$a == 0 || $b == 0} { + break + } + puts -nonewline "$a/$b " + } + puts "" +} -- cgit From d96dfbf63a67c75ef9ee4b625527c71687a9b530 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 3 Jan 2022 20:20:37 +0100 Subject: Links to blog posts --- challenge-146/abigail/blog.txt | 1 + challenge-146/abigail/blog1.txt | 1 + 2 files changed, 2 insertions(+) create mode 100644 challenge-146/abigail/blog.txt create mode 100644 challenge-146/abigail/blog1.txt diff --git a/challenge-146/abigail/blog.txt b/challenge-146/abigail/blog.txt new file mode 100644 index 0000000000..52f0ef8198 --- /dev/null +++ b/challenge-146/abigail/blog.txt @@ -0,0 +1 @@ +https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-146-1.html diff --git a/challenge-146/abigail/blog1.txt b/challenge-146/abigail/blog1.txt new file mode 100644 index 0000000000..c3d3aa63e3 --- /dev/null +++ b/challenge-146/abigail/blog1.txt @@ -0,0 +1 @@ +https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-146-2.html -- cgit From 41c3d16c97874e85d25f28d37e59df3e2d9a9d66 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 3 Jan 2022 20:21:23 +0100 Subject: Typo fix --- challenge-146/abigail/perl/ch-2.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/challenge-146/abigail/perl/ch-2.pl b/challenge-146/abigail/perl/ch-2.pl index c50e325692..546e2d0ca7 100644 --- a/challenge-146/abigail/perl/ch-2.pl +++ b/challenge-146/abigail/perl/ch-2.pl @@ -20,7 +20,7 @@ use experimental 'lexical_subs'; # * The root is 1/1 # * Each node a/b has children a/(a + b) and (a + b)/b # -# without having to rely on an image which needs to be interpolated. +# without having to rely on an image which needs to be extrapolated. # Of course, we also have to utterly ignore the existance of # "the tree created similar to the above sample", as similar implies # it being different. -- cgit