From fea0416101950dc2863283b6587b1f816a782d26 Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 5 Jan 2022 00:33:49 +0100 Subject: Week 2: Fix reference --- challenge-002/abigail/awk/ch-1.awk | 10 ++++++++++ challenge-002/abigail/awk/ch-2.awk | 3 ++- challenge-002/abigail/bash/ch-1.sh | 2 +- challenge-002/abigail/bc/ch-1.bc | 9 +++++++++ challenge-002/abigail/c/ch-1.c | 2 +- challenge-002/abigail/c/ch-2.c | 2 +- challenge-002/abigail/lua/ch-1.lua | 2 +- challenge-002/abigail/lua/ch-2.lua | 2 +- challenge-002/abigail/node/ch-1.js | 2 +- challenge-002/abigail/node/ch-2.js | 2 +- challenge-002/abigail/perl/ch-1.pl | 2 +- challenge-002/abigail/perl/ch-2.pl | 2 +- challenge-002/abigail/python/ch-1.py | 2 +- challenge-002/abigail/python/ch-2.py | 2 +- challenge-002/abigail/ruby/ch-1.rb | 2 +- challenge-002/abigail/ruby/ch-2.rb | 2 +- 16 files changed, 34 insertions(+), 14 deletions(-) diff --git a/challenge-002/abigail/awk/ch-1.awk b/challenge-002/abigail/awk/ch-1.awk index 6f2ef2064c..b40b9b0616 100644 --- a/challenge-002/abigail/awk/ch-1.awk +++ b/challenge-002/abigail/awk/ch-1.awk @@ -1 +1,11 @@ +#!/usr/bin/awk + +# +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-002 +# + +# +# Run as: awk -f ch-1.awk < input-file +# + {print 0 + $1} diff --git a/challenge-002/abigail/awk/ch-2.awk b/challenge-002/abigail/awk/ch-2.awk index b171fcd08f..77148f99c7 100644 --- a/challenge-002/abigail/awk/ch-2.awk +++ b/challenge-002/abigail/awk/ch-2.awk @@ -1,6 +1,7 @@ #!/usr/bin/awk + # -# See ../README.md +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-002 # # diff --git a/challenge-002/abigail/bash/ch-1.sh b/challenge-002/abigail/bash/ch-1.sh index b860cc4aa6..593a174ff3 100644 --- a/challenge-002/abigail/bash/ch-1.sh +++ b/challenge-002/abigail/bash/ch-1.sh @@ -1,7 +1,7 @@ #!/bin/sh # -# See ../README.md +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-002 # # diff --git a/challenge-002/abigail/bc/ch-1.bc b/challenge-002/abigail/bc/ch-1.bc index e69de29bb2..942d7b709f 100644 --- a/challenge-002/abigail/bc/ch-1.bc +++ b/challenge-002/abigail/bc/ch-1.bc @@ -0,0 +1,9 @@ +#!/usr/bin/bc + +# +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-002 +# + +# +# Run as: bc ch-1.bc < input-file +# diff --git a/challenge-002/abigail/c/ch-1.c b/challenge-002/abigail/c/ch-1.c index 09eb2ebf82..5e8f704b81 100644 --- a/challenge-002/abigail/c/ch-1.c +++ b/challenge-002/abigail/c/ch-1.c @@ -3,7 +3,7 @@ # include /* - * See ../README.md + * See https://theweeklychallenge.org/blog/perl-weekly-challenge-002 */ /* diff --git a/challenge-002/abigail/c/ch-2.c b/challenge-002/abigail/c/ch-2.c index 20cdd146d6..91ff62dcfd 100644 --- a/challenge-002/abigail/c/ch-2.c +++ b/challenge-002/abigail/c/ch-2.c @@ -4,7 +4,7 @@ # include /* - * See ../README.md + * See https://theweeklychallenge.org/blog/perl-weekly-challenge-002 */ /* diff --git a/challenge-002/abigail/lua/ch-1.lua b/challenge-002/abigail/lua/ch-1.lua index a60dee614f..a9cdc35ba3 100644 --- a/challenge-002/abigail/lua/ch-1.lua +++ b/challenge-002/abigail/lua/ch-1.lua @@ -1,7 +1,7 @@ #!/opt/local/bin/lua -- --- See ../README.md +-- See https://theweeklychallenge.org/blog/perl-weekly-challenge-002 -- -- diff --git a/challenge-002/abigail/lua/ch-2.lua b/challenge-002/abigail/lua/ch-2.lua index 789e2a0173..355d10d133 100644 --- a/challenge-002/abigail/lua/ch-2.lua +++ b/challenge-002/abigail/lua/ch-2.lua @@ -1,7 +1,7 @@ #!/opt/local/bin/lua -- --- See ../README.md +-- See https://theweeklychallenge.org/blog/perl-weekly-challenge-002 -- -- diff --git a/challenge-002/abigail/node/ch-1.js b/challenge-002/abigail/node/ch-1.js index 5146e85366..cae6d1fde8 100644 --- a/challenge-002/abigail/node/ch-1.js +++ b/challenge-002/abigail/node/ch-1.js @@ -1,7 +1,7 @@ #!/usr/local/bin/node // -// See ../README.md +// See https://theweeklychallenge.org/blog/perl-weekly-challenge-002 // // diff --git a/challenge-002/abigail/node/ch-2.js b/challenge-002/abigail/node/ch-2.js index 84d0f6976e..d7086b3b8f 100644 --- a/challenge-002/abigail/node/ch-2.js +++ b/challenge-002/abigail/node/ch-2.js @@ -1,7 +1,7 @@ #!/usr/local/bin/node // -// See ../README.md +// See https://theweeklychallenge.org/blog/perl-weekly-challenge-002 // // diff --git a/challenge-002/abigail/perl/ch-1.pl b/challenge-002/abigail/perl/ch-1.pl index 08572c9fa6..800784d54b 100644 --- a/challenge-002/abigail/perl/ch-1.pl +++ b/challenge-002/abigail/perl/ch-1.pl @@ -10,7 +10,7 @@ use experimental 'signatures'; use experimental 'lexical_subs'; # -# See ../README.md +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-002 # # diff --git a/challenge-002/abigail/perl/ch-2.pl b/challenge-002/abigail/perl/ch-2.pl index a9b9c006ba..983f52c9f6 100644 --- a/challenge-002/abigail/perl/ch-2.pl +++ b/challenge-002/abigail/perl/ch-2.pl @@ -10,7 +10,7 @@ use experimental 'signatures'; use experimental 'lexical_subs'; # -# See ../README.md +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-002 # # diff --git a/challenge-002/abigail/python/ch-1.py b/challenge-002/abigail/python/ch-1.py index de6839af0a..6a6c9f15f0 100644 --- a/challenge-002/abigail/python/ch-1.py +++ b/challenge-002/abigail/python/ch-1.py @@ -1,7 +1,7 @@ #!/opt/local/bin/python # -# See ../READ.md +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-002 # # diff --git a/challenge-002/abigail/python/ch-2.py b/challenge-002/abigail/python/ch-2.py index 22fe4fcaf0..107569a089 100644 --- a/challenge-002/abigail/python/ch-2.py +++ b/challenge-002/abigail/python/ch-2.py @@ -1,7 +1,7 @@ #!/opt/local/bin/python # -# See ../READ.md +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-002 # # diff --git a/challenge-002/abigail/ruby/ch-1.rb b/challenge-002/abigail/ruby/ch-1.rb index 0ef00293d6..b052cf842f 100644 --- a/challenge-002/abigail/ruby/ch-1.rb +++ b/challenge-002/abigail/ruby/ch-1.rb @@ -1,7 +1,7 @@ #!/usr/bin/ruby # -# See ../README.md +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-002 # # diff --git a/challenge-002/abigail/ruby/ch-2.rb b/challenge-002/abigail/ruby/ch-2.rb index 95efc096a7..2a55410b96 100644 --- a/challenge-002/abigail/ruby/ch-2.rb +++ b/challenge-002/abigail/ruby/ch-2.rb @@ -1,7 +1,7 @@ #!/usr/bin/ruby # -# See ../README.md +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-002 # # -- cgit From 48ebf06904931ac7aa23376e2a8ee726a07d1bcf Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 5 Jan 2022 00:49:52 +0100 Subject: Week 2. Make it work with python3 --- challenge-002/abigail/python/ch-1.py | 4 ++-- challenge-002/abigail/python/ch-2.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/challenge-002/abigail/python/ch-1.py b/challenge-002/abigail/python/ch-1.py index 6a6c9f15f0..0c7d4ebe5d 100644 --- a/challenge-002/abigail/python/ch-1.py +++ b/challenge-002/abigail/python/ch-1.py @@ -5,10 +5,10 @@ # # -# Run as python ch-1.py < input-file +# Run as: python ch-1.py < input-file # import fileinput for line in fileinput . input (): - print int (line) + print (int (line)) diff --git a/challenge-002/abigail/python/ch-2.py b/challenge-002/abigail/python/ch-2.py index 107569a089..b00e0dd541 100644 --- a/challenge-002/abigail/python/ch-2.py +++ b/challenge-002/abigail/python/ch-2.py @@ -5,7 +5,7 @@ # # -# Run as python ch-2.py {-f | -t} < input-file +# Run as: python ch-2.py {-f | -t} < input-file # import fileinput @@ -28,7 +28,7 @@ for opt, val in opts: do_to_base = 1 if do_to_base + do_from_base != 1: - print "Need exactly one of -f or -t" + print ("Need exactly one of -f or -t") sys . exit (1) @@ -52,7 +52,7 @@ def to_base (number): # Translate a number from base BASE to base 10 # def from_base (number): - return int (number, BASE) + return int (number . strip (), BASE) # # Need to clean argv, else fileinput will try to open a file @@ -60,4 +60,4 @@ def from_base (number): sys . argv [1:] = [] for line in fileinput . input (): - print from_base (line) if do_from_base else to_base (int (line)) + print (from_base (line) if do_from_base else to_base (int (line))) -- cgit From 76a305f969079f2534a8fe3ef6d88b6aa2839097 Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 5 Jan 2022 13:59:53 +0100 Subject: Week 2, part 2: bash solution --- challenge-002/abigail/README.md | 1 + challenge-002/abigail/bash/ch-2.sh | 60 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 challenge-002/abigail/bash/ch-2.sh diff --git a/challenge-002/abigail/README.md b/challenge-002/abigail/README.md index bb5cb18c8f..83153f6088 100644 --- a/challenge-002/abigail/README.md +++ b/challenge-002/abigail/README.md @@ -37,6 +37,7 @@ one number per line. Programs will use an option, -t (to base 35), or ### Solutions * [AWK](awk/ch-2.awk) +* [Bash](bash/ch-2.sh) * [C](c/ch-2.c) * [Lua](lua/ch-2.lua) * [Node](node/ch-2.js) diff --git a/challenge-002/abigail/bash/ch-2.sh b/challenge-002/abigail/bash/ch-2.sh new file mode 100644 index 0000000000..006c46a8d6 --- /dev/null +++ b/challenge-002/abigail/bash/ch-2.sh @@ -0,0 +1,60 @@ +#!/bin/sh + +# +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-002 +# + +# +# Run as: bash ch-2.sh < input-file +# + +set -f + +printf -v ord_0 %d "'0" +printf -v ord_A %d "'A" + +while getopts "ft" opt +do case "${opt}" in + f) action=from ;; + t) action=to ;; + esac +done + +function from_base_35 () { + local in=$1 + local ord + local char + base_10=0 + + for ((i = 0; i < ${#in}; i ++)) + do ((base_10 = 35 * base_10)) + char=${in:$i:1} + printf -v ord %d "'$char" + if [[ $char =~ [0-9] ]] + then ((base_10 = base_10 + ord - ord_0)) + else ((base_10 = base_10 + ord - ord_A + 10)) + fi + done +} + +function to_base_35 () { + local in=$1 + base_35="" + + while ((in > 0)) + do ((rem = in % 35)) + ((in = in / 35)) + if ((rem > 9)) + then printf -v char "\x$(printf %x $((ord_A + rem - 10)))" + else char=$rem + fi + base_35=${char}${base_35} + done +} + +while read line +do if [[ "$action" = from ]] + then from_base_35 $line; echo $base_10 + else to_base_35 $line; echo $base_35 + fi +done -- cgit From 74d9830dc5dbf14456f9e4f6b15d82761224b11f Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 5 Jan 2022 14:25:47 +0100 Subject: Week 2: Solutions in 6 more languages. --- challenge-002/abigail/README.md | 12 ++++++++ challenge-002/abigail/go/ch-1.go | 24 +++++++++++++++ challenge-002/abigail/go/ch-2.go | 46 ++++++++++++++++++++++++++++ challenge-002/abigail/java/ch-1.java | 18 +++++++++++ challenge-002/abigail/java/ch-2.java | 38 ++++++++++++++++++++++++ challenge-002/abigail/pascal/ch-1.p | 19 ++++++++++++ challenge-002/abigail/pascal/ch-2.p | 38 ++++++++++++++++++++++++ challenge-002/abigail/r/ch-1.r | 19 ++++++++++++ challenge-002/abigail/r/ch-2.r | 47 +++++++++++++++++++++++++++++ challenge-002/abigail/scheme/ch-1.scm | 22 ++++++++++++++ challenge-002/abigail/scheme/ch-2.scm | 56 +++++++++++++++++++++++++++++++++++ challenge-002/abigail/tcl/ch-1.tcl | 17 +++++++++++ challenge-002/abigail/tcl/ch-2.tcl | 56 +++++++++++++++++++++++++++++++++++ 13 files changed, 412 insertions(+) create mode 100644 challenge-002/abigail/go/ch-1.go create mode 100644 challenge-002/abigail/go/ch-2.go create mode 100644 challenge-002/abigail/java/ch-1.java create mode 100644 challenge-002/abigail/java/ch-2.java create mode 100644 challenge-002/abigail/pascal/ch-1.p create mode 100644 challenge-002/abigail/pascal/ch-2.p create mode 100644 challenge-002/abigail/r/ch-1.r create mode 100644 challenge-002/abigail/r/ch-2.r create mode 100644 challenge-002/abigail/scheme/ch-1.scm create mode 100644 challenge-002/abigail/scheme/ch-2.scm create mode 100644 challenge-002/abigail/tcl/ch-1.tcl create mode 100644 challenge-002/abigail/tcl/ch-2.tcl diff --git a/challenge-002/abigail/README.md b/challenge-002/abigail/README.md index 83153f6088..83ac952703 100644 --- a/challenge-002/abigail/README.md +++ b/challenge-002/abigail/README.md @@ -16,11 +16,17 @@ We cannot have a number with just 0's, as that would not be a positive number. * [bc](bc/ch-1.bc) * [Befunge-93](befunge-93/ch-1.bf93) * [C](c/ch-1.c) +* [Go](go/ch-1.go) +* [Java](java/ch-1.java) * [Lua](lua/ch-1.lua) * [Node.js](node/ch-1.js) +* [Pascal](pascal/ch-1.p) * [Perl](perl/ch-1.pl) * [Python](python/ch-1.py) +* [R](r/ch-1.r) * [Ruby](ruby/ch-1.rb) +* [Scheme](scheme/ch-1.scm) +* [Tcl](tcl/ch-1.tcl) ## [Challenge #2](https://perlweeklychallenge.org/blog/perl-weekly-challenge-002/#challenge-2) @@ -39,8 +45,14 @@ one number per line. Programs will use an option, -t (to base 35), or * [AWK](awk/ch-2.awk) * [Bash](bash/ch-2.sh) * [C](c/ch-2.c) +* [Go](go/ch-1.go) +* [Java](java/ch-1.java) * [Lua](lua/ch-2.lua) * [Node](node/ch-2.js) +* [Pascal](pascal/ch-1.p) * [Perl](perl/ch-2.pl) * [Python](python/ch-2.py) +* [R](r/ch-2.r) * [Ruby](ruby/ch-2.by) +* [Scheme](scheme/ch-2.scm) +* [Tcl](tcl/ch-2.tcl) diff --git a/challenge-002/abigail/go/ch-1.go b/challenge-002/abigail/go/ch-1.go new file mode 100644 index 0000000000..5c99f26012 --- /dev/null +++ b/challenge-002/abigail/go/ch-1.go @@ -0,0 +1,24 @@ +package main + +// +// See https://theweeklychallenge.org/blog/perl-weekly-challenge-002 +// + +// +// Run as: go run ch-1.go < input-file +// + +import ( + "fmt" +) + +func main () { + var i int; + for { + var n, err = fmt . Scanf ("%d", &i) + if n != 1 || err != nil { + break + } + fmt . Println (i) + } +} diff --git a/challenge-002/abigail/go/ch-2.go b/challenge-002/abigail/go/ch-2.go new file mode 100644 index 0000000000..328b13dbdc --- /dev/null +++ b/challenge-002/abigail/go/ch-2.go @@ -0,0 +1,46 @@ +package main + +// +// See https://theweeklychallenge.org/blog/perl-weekly-challenge-002 +// + +// +// Run as: go run ch-2.go < input-file +// + +import ( + "fmt" + "flag" + "bufio" + "os" + "strconv" + "strings" +) + +func main () { + to_base := flag . Bool ("t", false, "a bool") + from_base := flag . Bool ("f", false, "a bool") + + flag . Parse () + + var reader = bufio . NewReader (os. Stdin) + for { + var line, err = reader . ReadString ('\n') + if (err != nil) { + break + } + line = strings . Trim (line, "\n") + if *from_base { + i, err := strconv . ParseInt (line, 35, 0) + if (err == nil) { + fmt . Println (i) + } + } + if *to_base { + i, err := strconv . ParseInt (line, 10, 0) + if (err == nil) { + fmt . Println (strings . ToUpper (strconv . FormatInt (i, 35))) + } + } + } +} diff --git a/challenge-002/abigail/java/ch-1.java b/challenge-002/abigail/java/ch-1.java new file mode 100644 index 0000000000..d2b574e76d --- /dev/null +++ b/challenge-002/abigail/java/ch-1.java @@ -0,0 +1,18 @@ +// +// See https://theweeklychallenge.org/blog/perl-weekly-challenge-002 +// + +// +// Run as: ln ch-1.java ch1.java; javac ch1.java; java ch1 < input-file +// + +import java.util.*; + +public class ch1 { + public static void main (String [] args) { + Scanner scanner = new Scanner (System . in); + while (scanner . hasNextInt ()) { + System . out . println (scanner . nextInt ()); + } + } +} diff --git a/challenge-002/abigail/java/ch-2.java b/challenge-002/abigail/java/ch-2.java new file mode 100644 index 0000000000..8c15c6ed49 --- /dev/null +++ b/challenge-002/abigail/java/ch-2.java @@ -0,0 +1,38 @@ +// +// See https://theweeklychallenge.org/blog/perl-weekly-challenge-002 +// + +// +// 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) { + Boolean from_base = false; + Boolean to_base = false; + + if (args . length == 1) { + if (args [0] . equals ("-f")) { + from_base = true; + } + if (args [0] . equals ("-t")) { + to_base = true; + } + } + + Scanner scanner = new Scanner (System . in); + while (scanner . hasNextLine ()) { + String line = scanner . nextLine () . trim (); + if (from_base) { + System . out . println (Integer . parseInt (line, 35)); + } + if (to_base) { + System . out . println (Integer . toString ( + Integer . parseInt (line), 35) . + toUpperCase ()); + } + } + } +} diff --git a/challenge-002/abigail/pascal/ch-1.p b/challenge-002/abigail/pascal/ch-1.p new file mode 100644 index 0000000000..85fee3525a --- /dev/null +++ b/challenge-002/abigail/pascal/ch-1.p @@ -0,0 +1,19 @@ +Program XXX; + +(* *) +(* See https://theweeklychallenge.org/blog/perl-weekly-challenge-002 *) +(* *) + +(* *) +(* Run as: fpc -och-1.out ch-1.p; ./ch-1.out < input-file *) +(* *) + +var + i: LongInt; + +begin + while not eof do begin + readln (i); + writeln (i); + end +end. diff --git a/challenge-002/abigail/pascal/ch-2.p b/challenge-002/abigail/pascal/ch-2.p new file mode 100644 index 0000000000..636bcb43c0 --- /dev/null +++ b/challenge-002/abigail/pascal/ch-2.p @@ -0,0 +1,38 @@ +Program ch2; + +(* *) +(* See https://theweeklychallenge.org/blog/perl-weekly-challenge-002 *) +(* *) + +(* *) +(* Run as: fpc -och-2.out ch-2.p; ./ch-2.out [-f | -t] < input-file *) +(* *) + +uses + strutils; + +var + line: string; + num: longint; + to_base, from_base: boolean; + +begin + if paramCount () = 1 then begin + if paramStr (1) = '-f' then begin + from_base := true; + end; + if paramStr (1) = '-t' then begin + to_base := true; + end + end; + while not eof do begin + if to_base then begin + readln (num); + writeln (Dec2Numb (num, 1, 35)); + end; + if from_base then begin + readln (line); + writeln (Numb2Dec (line, 35)); + end + end +end. diff --git a/challenge-002/abigail/r/ch-1.r b/challenge-002/abigail/r/ch-1.r new file mode 100644 index 0000000000..2dfc049aea --- /dev/null +++ b/challenge-002/abigail/r/ch-1.r @@ -0,0 +1,19 @@ +#!/usr/local/bin/Rscript + +# +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-002 +# + +# +# Run as: Rscript ch-1.r < input-file +# + +stdin <- file ('stdin', 'r') +repeat { + n <- readLines (stdin, n = 1) + if (length (n) == 0) { + break + } + n = as.integer (n) + cat (n, "\n") +} diff --git a/challenge-002/abigail/r/ch-2.r b/challenge-002/abigail/r/ch-2.r new file mode 100644 index 0000000000..26e6796fd4 --- /dev/null +++ b/challenge-002/abigail/r/ch-2.r @@ -0,0 +1,47 @@ +#!/usr/local/bin/Rscript + +# +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-002 +# + +# +# Run as: Rscript ch-2.r < input-file +# + +from_base <- FALSE +to_base <- FALSE + +args <- commandArgs () +for (i in 1 : length (args)) { + if (args [i] == "-f") { + from_base <- TRUE + } + if (args [i] == "-t") { + to_base <- TRUE + } +} + +to_base_35 <- function (num) { + glyphs <- c (0 : 9, LETTERS) + out <- c () + while (num > 0) { + rem <- num %% 35 + num <- num %/% 35 + out <- c (glyphs [rem + 1], out) + } + paste0 (out, collapse = "") +} + +stdin <- file ('stdin', 'r') +repeat { + line <- readLines (stdin, n = 1) + if (length (line) == 0) { + break + } + if (from_base) { + cat (strtoi (line, 35), "\n") + } + if (to_base) { + cat (to_base_35 (as.numeric (line)), "\n") + } +} diff --git a/challenge-002/abigail/scheme/ch-1.scm b/challenge-002/abigail/scheme/ch-1.scm new file mode 100644 index 0000000000..62e68b8964 --- /dev/null +++ b/challenge-002/abigail/scheme/ch-1.scm @@ -0,0 +1,22 @@ +;;; +;;; See https://theweeklychallenge.org/blog/perl-weekly-challenge-002 +;;; + +;;; +;;; Run as: guile --no-auto-compile ch-1.scm +;;; + + +(use-modules (ice-9 rdelim)) +(define (main) + (define line (read-line)) + (if (not (eof-object? line)) + (begin + (display (string->number line)) + (newline) + (main) + ) + ) +) + +(main) diff --git a/challenge-002/abigail/scheme/ch-2.scm b/challenge-002/abigail/scheme/ch-2.scm new file mode 100644 index 0000000000..a78e77faa6 --- /dev/null +++ b/challenge-002/abigail/scheme/ch-2.scm @@ -0,0 +1,56 @@ +#!/usr/local/bin/guile +!# + +;;; +;;; See https://theweeklychallenge.org/blog/perl-weekly-challenge-002 +;;; + +;;; +;;; Run as: guile --no-auto-compile ch-2.scm +;;; + + +(use-modules (ice-9 rdelim)) + +(define frombase #f) +(define tobase #f) +(define base 35) + +(if (= (length (command-line)) 2) + (cond ((string=? (list-ref (command-line) 1) "-f") (set! frombase #t)) + ((string=? (list-ref (command-line) 1) "-t") (set! tobase #t))) +) + +(define glyphs "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") + +(define (_to_base num base) + (cond ((= num 0) "") + (else (string-concatenate + (list (_to_base (floor-quotient num base) base) + (substring glyphs (modulo num base) + (+ 1 (modulo num base)))))))) +(define (to_base num base) + (cond ((= num 0) "0") + (else (_to_base num base)))) + + +(define (from_base num base) + (define len (string-length num)) + (cond ((= len 0) 0) + (else (+ (string-contains glyphs (string-take-right num 1)) + (* base (from_base (string-drop-right num 1) base)))))) + + +(define (main) + (define line (read-line)) + (if (not (eof-object? line)) + (begin + (if tobase (display ( to_base (string->number line) base))) + (if frombase (display (from_base line base))) + (newline) + (main) + ) + ) +) + +(main) diff --git a/challenge-002/abigail/tcl/ch-1.tcl b/challenge-002/abigail/tcl/ch-1.tcl new file mode 100644 index 0000000000..856d91641e --- /dev/null +++ b/challenge-002/abigail/tcl/ch-1.tcl @@ -0,0 +1,17 @@ +#!/usr/local/opt/tcl-tk/bin/tclsh + +# +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-002 +# + +# +# Run as: tclsh ch-1.tcl < input-file +# + +while {[gets stdin line] >= 0} { + set line [string trimleft $line 0] + if {[string length $line] == 0} { + set line 0 + } + puts $line +} diff --git a/challenge-002/abigail/tcl/ch-2.tcl b/challenge-002/abigail/tcl/ch-2.tcl new file mode 100644 index 0000000000..4feed6d2cb --- /dev/null +++ b/challenge-002/abigail/tcl/ch-2.tcl @@ -0,0 +1,56 @@ +#!/usr/local/opt/tcl-tk/bin/tclsh + +# +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-002 +# + +# +# Run as: tclsh ch-2.tcl < input-file +# + +set frombase 0 +set tobase 0 +set glyphs "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" +set base 35 + +if {$argc == 1} { + if {[lindex $argv 0] == "-f"} { + set frombase 1 + } + if {[lindex $argv 0] == "-t"} { + set tobase 1 + } +} + +proc from_base {num base} { + global glyphs + set out 0 + foreach c [split $num {}] { + set out [expr $base * $out + [string first $c $glyphs]] + } + return $out +} + +proc to_base {num base} { + global glyphs + if {$num == 0} { + return 0 + } + set out "" + while {$num > 0} { + set out [string index $glyphs [expr {$num % $base}]]$out + set num [expr $num / $base] + } + return $out +} + + + +while {[gets stdin line] >= 0} { + if {$frombase == 1} { + puts [from_base $line $base] + } + if { $tobase == 1} { + puts [ to_base $line $base] + } +} -- cgit From ada8b466f3fe8efcf3b85f22495c744517df42ca Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 5 Jan 2022 20:35:32 +0100 Subject: Week 3: copied solutions from week 123. Week 123 has exactly the same challenge. Since I prefer that solution, I copied those results. Tests adjusted accordingly. --- challenge-003/abigail/README.md | 32 +--- challenge-003/abigail/awk/ch-1.awk | 44 +++-- challenge-003/abigail/bash/ch-1.sh | 32 +++- challenge-003/abigail/c/ch-1.c | 48 +++-- challenge-003/abigail/lua/ch-1.lua | 54 ++++-- challenge-003/abigail/node/ch-1.js | 29 +-- challenge-003/abigail/perl/ch-1.pl | 55 ++++-- challenge-003/abigail/python/ch-1.py | 40 +++-- challenge-003/abigail/r/ch-1.r | 33 ++++ challenge-003/abigail/ruby/ch-1.rb | 35 ++-- challenge-003/abigail/t/ctest.ini | 8 +- challenge-003/abigail/t/input-1-1 | 3 +- challenge-003/abigail/t/input-1-2 | 5 +- challenge-003/abigail/t/output-1-1.exp | 60 ------- challenge-003/abigail/t/output-1-2.exp | 313 +-------------------------------- 15 files changed, 269 insertions(+), 522 deletions(-) create mode 100644 challenge-003/abigail/r/ch-1.r diff --git a/challenge-003/abigail/README.md b/challenge-003/abigail/README.md index 586b7ee14e..365945625a 100644 --- a/challenge-003/abigail/README.md +++ b/challenge-003/abigail/README.md @@ -1,25 +1,6 @@ -# Solution by Abigail +# Solution by Abigail, week 3 -## [Challenge #1](https://perlweeklychallenge.org/blog/perl-weekly-challenge-003/#challenge-1) -Create a script to generate `5`-smooth numbers, whose prime divisors -are less or equal to `5`. They are also called Hamming/Regular/Ugly -numbers. For more information, please check this -[wikipedia](https://en.wikipedia.org/wiki/Regular_number). - -### Notes -We are going to generate all numbers `n = 2^i * 3^j * 5^k`, with -`i >= 0`, `j >= 0`, `k >= 0`, and `n <= MAX`, where `MAX` is read -from `STDIN`. No other numbers are generated. - -We are *not* going to generate the numbers `n` in -numerical order. Instead, if we have two numbers `n1 = 2^i1 * 3^j1 * 5^k1`, -and `n2 = 2^i2 * 3^j2 * 5^k2`, then `n1` is generated before `n2`, iff - - i1 < i2 || - i1 == i2 && j1 < j2 || - i1 == i2 && j1 == j2 && k1 < k2 - -### Solutions +### Part 1 * [AWK](awk/ch-1.awk) * [Bash](bash/ch-1.sh) * [bc](bc/ch-1.bc) @@ -29,15 +10,10 @@ and `n2 = 2^i2 * 3^j2 * 5^k2`, then `n1` is generated before `n2`, iff * [Perl](perl/ch-1.pl) * [Python](python/ch-1.py) * [Ruby](ruby/ch-1.rb) +* [R](r/ch-1.r) -## [Challenge #2](https://perlweeklychallenge.org/blog/perl-weekly-challenge-003/#challenge-2) -Create a script that generates Pascal Triangle. Accept number of -rows from the command line. The Pascal Triangle should have at least -3 rows. For more information about Pascal Triangle, check this -[wikipedia](https://en.wikipedia.org/wiki/Pascal%27s_triangle) page. - -### Solutions +### Part 2 * [AWK](awk/ch-2.awk) * [C](c/ch-2.c) * [Lua](lua/ch-2.lua) diff --git a/challenge-003/abigail/awk/ch-1.awk b/challenge-003/abigail/awk/ch-1.awk index 706014ed91..c6fd5a3e55 100644 --- a/challenge-003/abigail/awk/ch-1.awk +++ b/challenge-003/abigail/awk/ch-1.awk @@ -1,29 +1,39 @@ #!/usr/bin/awk # -# See ../README.md +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-003 # # # Run as: awk -f ch-1.awk < input-file # -# -# Generate the 5-smooth numbers up to $0. -# This does *NOT* generate the numbers is order. It does, however, -# generate all of them, and no other numbers. -# -# -# base2 is of the form 2^i; i >= 0 -# base3 if of the form 2^i * 3^j; i, j >= 0 -# base5 is of the form 2^i * 3^j * 5^k; i, j, k >= 0 -# +BEGIN { + ugly [0] = 1 + next_2 = 0 + next_3 = 0 + next_5 = 0 + count = 1 +} + { - for (base2 = 1; base2 <= $0; base2 *= 2) { - for (base3 = base2; base3 <= $0; base3 *= 3) { - for (base5 = base3; base5 <= $0; base5 *= 5) { - print base5 - } - } + while (count < $1) { + c2 = 2 * ugly [next_2] + c3 = 3 * ugly [next_3] + c5 = 5 * ugly [next_5] + + ugly [count] = c2 < c3 ? c2 < c5 ? c2 : c5 \ + : c3 < c5 ? c3 : c5 + + if (2 * ugly [next_2] <= ugly [count]) {next_2 ++} + if (3 * ugly [next_3] <= ugly [count]) {next_3 ++} + if (5 * ugly [next_5] <= ugly [count]) {next_5 ++} + + count ++ } + print ugly [$1 - 1] } + + + + diff --git a/challenge-003/abigail/bash/ch-1.sh b/challenge-003/abigail/bash/ch-1.sh index 76029e700b..b2f98abec9 100644 --- a/challenge-003/abigail/bash/ch-1.sh +++ b/challenge-003/abigail/bash/ch-1.sh @@ -1,7 +1,7 @@ #!/bin/sh # -# See ../README.md +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-003 # # @@ -10,12 +10,28 @@ set -f -while read max -do for ((base2 = 1; $base2 <= $max; base2 *= 2)) - do for ((base3 = $base2; $base3 <= $max; base3 *= 3)) - do for ((base5 = $base3; $base5 <= $max; base5 *= 5)) - do echo $base5 - done - done +declare -a ugly +ugly[0]=1 +((next_2 = 0)) +((next_3 = 0)) +((next_5 = 0)) +count=1 + +while read n +do while ((count < n)) + do ((c2 = 2 * ${ugly[next_2]})) + ((c3 = 3 * ${ugly[next_3]})) + ((c5 = 5 * ${ugly[next_5]})) + + if ((c2 <= c3 && c2 <= c5)); then ((ugly[count] = c2)); fi + if ((c3 <= c2 && c3 <= c5)); then ((ugly[count] = c3)); fi + if ((c5 <= c3 && c5 <= c2)); then ((ugly[count] = c5)); fi + + if ((2 * ${ugly[next_2]} <= ${ugly[count]})); then ((next_2 ++)); fi + if ((3 * ${ugly[next_3]} <= ${ugly[count]})); then ((next_3 ++)); fi + if ((5 * ${ugly[next_5]} <= ${ugly[count]})); then ((next_5 ++)); fi + + ((count ++)) done + echo ${ugly[$((n - 1))]} done diff --git a/challenge-003/abigail/c/ch-1.c b/challenge-003/abigail/c/ch-1.c index eb6a053705..a5a503cb32 100644 --- a/challenge-003/abigail/c/ch-1.c +++ b/challenge-003/abigail/c/ch-1.c @@ -3,29 +3,51 @@ # include /* - * See ../README.md + * See https://theweeklychallenge.org/blog/perl-weekly-challenge-003 */ /* * Run as: cc -o ch-1.o ch-1.c; ./ch-1.o < input-file */ +typedef long long number; int main (void) { - char * line = NULL; - size_t len = 0; - size_t strlen; - - while ((strlen = getline (&line, &len, stdin)) != -1) { - long long max = atoll (line); - for (long long base2 = 1; base2 <= max; base2 *= 2) { - for (long long base3 = base2; base3 <= max; base3 *= 3) { - for (long long base5 = base3; base5 <= max; base5 *= 5) { - printf ("%lld\n", base5); - } + int n; + number * ugly = NULL; + size_t count = 0; + size_t next_2, next_3, next_5; + + + while (scanf ("%d", &n) == 1) { + if (n > count) { + if ((ugly = (number *) realloc (ugly, n * sizeof (number))) + == NULL) { + perror ("Realloc failed"); + exit (1); } } + if (count == 0) { + ugly [0] = 1; + count = 1; + next_2 = next_3 = next_5 = 0; + } + while (count < n) { + number c2 = 2 * ugly [next_2]; + number c3 = 3 * ugly [next_3]; + number c5 = 5 * ugly [next_5]; + + ugly [count] = c2 < c3 ? c2 < c5 ? c2 : c5 + : c3 < c5 ? c3 : c5; + + if (2 * ugly [next_2] <= ugly [count]) {next_2 ++;} + if (3 * ugly [next_3] <= ugly [count]) {next_3 ++;} + if (5 * ugly [next_5] <= ugly [count]) {next_5 ++;} + + count ++; + } + printf ("%lld\n", ugly [n - 1]); } - free (line); + free (ugly); return (0); } diff --git a/challenge-003/abigail/lua/ch-1.lua b/challenge-003/abigail/lua/ch-1.lua index 70de9b1923..3f0bf5b9fe 100644 --- a/challenge-003/abigail/lua/ch-1.lua +++ b/challenge-003/abigail/lua/ch-1.lua @@ -1,30 +1,48 @@ #!/opt/local/bin/lua -- --- See ../README.md +-- See https://theweeklychallenge.org/blog/perl-weekly-challenge-003 -- -- -- Run as: lua ch-1.lua < input-file -- -for max in io . lines () do - local max = tonumber (max) - local base2 = 1 - -- - -- Lua doesn't have a for (expr; expr; expr) syntax. - -- This is missed here. - -- - while base2 <= max do - local base3 = base2 - while base3 <= max do - local base5 = base3 - while base5 <= max do - print (base5) - base5 = base5 * 5 - end - base3 = base3 * 3 +local ugly = {} +ugly [1] = 1 +local next_2 = 1 +local next_3 = 1 +local next_5 = 1 +local count = 1 + +for n in io . lines () do + n = tonumber (n) + while count < n do + local c2 = 2 * ugly [next_2] + local c3 = 3 * ugly [next_3] + local c5 = 5 * ugly [next_5] + + count = count + 1 + + if c2 <= c3 and c2 <= c5 then + ugly [count] = c2 + end + if c3 <= c2 and c3 <= c5 then + ugly [count] = c3 + end + if c5 <= c2 and c5 <= c3 then + ugly [count] = c5 + end + + if 2 * ugly [next_2] <= ugly [count] then + next_2 = next_2 + 1 + end + if 3 * ugly [next_3] <= ugly [count] then + next_3 = next_3 + 1 + end + if 5 * ugly [next_5] <= ugly [count] then + next_5 = next_5 + 1 end - base2 = base2 * 2 end + print (ugly [n]) end diff --git a/challenge-003/abigail/node/ch-1.js b/challenge-003/abigail/node/ch-1.js index a1ffe969ac..e44318f34c 100644 --- a/challenge-003/abigail/node/ch-1.js +++ b/challenge-003/abigail/node/ch-1.js @@ -1,21 +1,30 @@ #!/usr/local/bin/node // -// See ../README.md +// See https://theweeklychallenge.org/blog/perl-weekly-challenge-003 // // // Run as: node ch-1.js < input-file // -require ('readline') +let ugly = [1] +let next_2 = 0 +let next_3 = 0 +let next_5 = 0 + + require ('readline') . createInterface ({input: process . stdin}) -. on ('line', max => { - for (let base2 = 1; base2 <= max; base2 *= 2) { - for (let base3 = base2; base3 <= max; base3 *= 3) { - for (let base5 = base3; base5 <= max; base5 *= 5) { - console . log (base5) - } - } +. on ('line', n => { + n =+ n + while (ugly . length < n) { + ugly . push (Math . min (2 * ugly [next_2], + 3 * ugly [next_3], + 5 * ugly [next_5])) + + if (2 * ugly [next_2] <= ugly [ugly . length - 1]) {next_2 ++} + if (3 * ugly [next_3] <= ugly [ugly . length - 1]) {next_3 ++} + if (5 * ugly [next_5] <= ugly [ugly . length - 1]) {next_5 ++} } -}); + console . log (ugly [n - 1]) +}) diff --git a/challenge-003/abigail/perl/ch-1.pl b/challenge-003/abigail/perl/ch-1.pl index 352466e41c..2b9787b3c9 100644 --- a/challenge-003/abigail/perl/ch-1.pl +++ b/challenge-003/abigail/perl/ch-1.pl @@ -10,32 +10,55 @@ use experimental 'signatures'; use experimental 'lexical_subs'; # -# See ../README.md +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-003 # # # Run as: perl ch-1.pl < input-file # -# -# Read the maximum number from STDIN -# -chomp (my $MAX = <>); +use List::Util qw [min]; +my @ugly = (1); +my $next_2 = 0; +my $next_3 = 0; +my $next_5 = 0; # -# Generate the 5-smooth numbers up to $MAX. -# This does *NOT* generate the numbers is order. It does, however, -# generate all of them, and no other numbers. +# We will maintain the following invariants: # +# 2 * $ugly [$next_2 - 1] <= $ugly [-1] < 2 * $ugly [$next_2] +# 3 * $ugly [$next_3 - 1] <= $ugly [-1] < 3 * $ugly [$next_2] +# 5 * $ugly [$next_5 - 1] <= $ugly [-1] < 5 * $ugly [$next_2] # -# $base2 is of the form 2^i; i >= 0 -# $base3 if of the form 2^i * 3^j; i, j >= 0 -# $base5 is of the form 2^i * 3^j * 5^k; i, j, k >= 0 +# And since every ugly number (except the first) is either twice an +# ugly number, three times an ugly number, or five times an ugly +# number, the next ugly number will be the minimum of +# (2 * $ugly [$next_2], 3 * $ugly [$next_3], 5 * $ugly [$next_5]). # -for (my $base2 = 1; $base2 <= $MAX; $base2 *= 2) { - for (my $base3 = $base2; $base3 <= $MAX; $base3 *= 3) { - for (my $base5 = $base3; $base5 <= $MAX; $base5 *= 5) { - say $base5; - } +# We will spend O(1) time per generated ugly number, so our +# program will run in O(N) time, using O(N) memory. +# + +while (my $n = <>) { + while (@ugly < $n) { + # + # Calculate the next ugly number. + # + push @ugly => min 2 * $ugly [$next_2], + 3 * $ugly [$next_3], + 5 * $ugly [$next_5]; + + # + # Update pointers. It could be that more than one pointer needs + # updating. (This happens if the ugly number generated is + # divisible by 6, 10, 15, or 30). No pointer ever needs updating twice. + # + $next_2 ++ if 2 * $ugly [$next_2] <= $ugly [-1]; + $next_3 ++ if 3 * $ugly [$next_3] <= $ugly [-1]; + $next_5 ++ if 5 * $ugly [$next_5] <= $ugly [-1]; } + say $ugly [-1]; } + + +__END__ diff --git a/challenge-003/abigail/python/ch-1.py b/challenge-003/abigail/python/ch-1.py index 30b41dd8fe..8b3ac1e035 100644 --- a/challenge-003/abigail/python/ch-1.py +++ b/challenge-003/abigail/python/ch-1.py @@ -1,27 +1,33 @@ #!/opt/local/bin/python # -# See ../READ.md +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-003 # # -# Run as python ch-1.py < input-file +# Run as: python ch-1.py < input-file # import fileinput -for line in fileinput . input (): - max = int (line) - # - # Python does not have a for (;;) style loop - # - base2 = 1 - while base2 <= max: - base3 = base2 - while base3 <= max: - base5 = base3 - while base5 <= max: - print base5 - base5 *= 5 - base3 *= 3 - base2 *= 2 +ugly = [1] +next_2 = 0 +next_3 = 0 +next_5 = 0 + + +for n in fileinput . input (): + n = int (n) + while len (ugly) < n: + ugly . append (min ([2 * ugly [next_2], + 3 * ugly [next_3], + 5 * ugly [next_5]])) + + if 2 * ugly [next_2] <= ugly [-1]: + next_2 = next_2 + 1 + if 3 * ugly [next_3] <= ugly [-1]: + next_3 = next_3 + 1 + if 5 * ugly [next_5] <= ugly [-1]: + next_5 = next_5 + 1 + + print (ugly [n - 1]) diff --git a/challenge-003/abigail/r/ch-1.r b/challenge-003/abigail/r/ch-1.r new file mode 100644 index 0000000000..208c5b4dde --- /dev/null +++ b/challenge-003/abigail/r/ch-1.r @@ -0,0 +1,33 @@ +# +# See ../README.md +# + +# +# Run as: Rscript ch-1.r < input-file +# + +ugly <- c (1) +next_2 <- 1 +next_3 <- 1 +next_5 <- 1 +count <- 1 + +stdin <- file ('stdin', 'r') +repeat { + n <- readLines (stdin, n = 1) + if (length (n) == 0) { + break + } + n = as.integer (n) + + while (count < n) { + count = count + 1 + ugly [count] = min (c (2 * ugly [next_2], 3 * ugly [next_3], + 5 * ugly [next_5])) + + if (2 * ugly [next_2] <= ugly [count]) {next_2 <- next_2 + 1} + if (3 * ugly [next_3] <= ugly [count]) {next_3 <- next_3 + 1} + if (5 * ugly [next_5] <= ugly [count]) {next_5 <- next_5 + 1} + } + cat (format (ugly [n], digits = 15), "\n") +} diff --git a/challenge-003/abigail/ruby/ch-1.rb b/challenge-003/abigail/ruby/ch-1.rb index c0a22397b0..d07d858bda 100644 --- a/challenge-003/abigail/ruby/ch-1.rb +++ b/challenge-003/abigail/ruby/ch-1.rb @@ -1,26 +1,29 @@ #!/usr/bin/ruby # -# See ../README.md +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-003 # # # Run as: ruby ch-1.rb < input-file # -ARGF . each_line do |_| - max = _ . to_i - base2 = 1 - while base2 <= max - base3 = base2 - while base3 <= max - base5 = base3 - while base5 <= max - puts base5 - base5 *= 5 - end - base3 *= 3 - end - base2 *= 2 - end +ugly = [1] +next_2 = 0 +next_3 = 0 +next_5 = 0 + +ARGF . each_line do + |n| + n = n . to_i + while ugly . length < n do + ugly . push ([2 * ugly [next_2], + 3 * ugly [next_3], + 5 * ugly [next_5]] . min) + + next_2 += 1 if 2 * ugly [next_2] <= ugly [-1] + next_3 += 1 if 3 * ugly [next_3] <= ugly [-1] + next_5 += 1 if 5 * ugly [next_5] <= ugly [-1] + end + puts (ugly [n - 1]) end diff --git a/challenge-003/abigail/t/ctest.ini b/challenge-003/abigail/t/ctest.ini index 959e85ac42..a3434f63d2 100644 --- a/challenge-003/abigail/t/ctest.ini +++ b/challenge-003/abigail/t/ctest.ini @@ -4,11 +4,7 @@ # [names] -1-1 = OEIS Example -1-2 = Large input +1-1 = Given Examples from week 123 +1-2 = Larger Numbers 2-1 = Minimal triangle 2-2 = 15 row triangle - - -[1-1,1-2] -sort = numeric diff --git a/challenge-003/abigail/t/input-1-1 b/challenge-003/abigail/t/input-1-1 index ec8785ec99..1831e2e66c 100644 --- a/challenge-003/abigail/t/input-1-1 +++ b/challenge-003/abigail/t/input-1-1 @@ -1 +1,2 @@ -405 +7 +10 diff --git a/challenge-003/abigail/t/input-1-2 b/challenge-003/abigail/t/input-1-2 index f7393e847d..d59e6110af 100644 --- a/challenge-003/abigail/t/input-1-2 +++ b/challenge-003/abigail/t/input-1-2 @@ -1 +1,4 @@ -100000 +10 +100 +1000 +5000 diff --git a/challenge-003/abigail/t/output-1-1.exp b/challenge-003/abigail/t/output-1-1.exp index 04fd1a4f4b..60d24f7251 100644 --- a/challenge-003/abigail/t/output-1-1.exp +++ b/challenge-003/abigail/t/output-1-1.exp @@ -1,62 +1,2 @@ -1 -2 -3 -4 -5 -6 8 -9 -10 12 -15 -16 -18 -20 -24 -25 -27 -30 -32 -36 -40 -45 -48 -50 -54 -60 -64 -72 -75 -80 -81 -90 -96 -100 -108 -120 -125 -128 -135 -144 -150 -160 -162 -180 -192 -200 -216 -225 -240 -243 -250 -256 -270 -288 -300 -320 -324 -360 -375 -384 -400 -405 diff --git a/challenge-003/abigail/t/output-1-2.exp b/challenge-003/abigail/t/output-1-2.exp index 69a24cd064..8ba1659605 100644 --- a/challenge-003/abigail/t/output-1-2.exp +++ b/challenge-003/abigail/t/output-1-2.exp @@ -1,313 +1,4 @@ -1 -2 -3 -4 -5 -6 -8 -9 -10 12 -15 -16 -18 -20 -24 -25 -27 -30 -32 -36 -40 -45 -48 -50 -54 -60 -64 -72 -75 -80 -81 -90 -96 -100 -108 -120 -125 -128 -135 -144 -150 -160 -162 -180 -192 -200 -216 -225 -240 -243 -250 -256 -270 -288 -300 -320 -324 -360 -375 -384 -400 -405 -432 -450 -480 -486 -500 -512 -540 -576 -600 -625 -640 -648 -675 -720 -729 -750 -768 -800 -810 -864 -900 -960 -972 -1000 -1024 -1080 -1125 -1152 -1200 -1215 -1250 -1280 -1296 -1350 -1440 -1458 -1500 1536 -1600 -1620 -1728 -1800 -1875 -1920 -1944 -2000 -2025 -2048 -2160 -2187 -2250 -2304 -2400 -2430 -2500 -2560 -2592 -2700 -2880 -2916 -3000 -3072 -3125 -3200 -3240 -3375 -3456 -3600 -3645 -3750 -3840 -3888 -4000 -4050 -4096 -4320 -4374 -4500 -4608 -4800 -4860 -5000 -5120 -5184 -5400 -5625 -5760 -5832 -6000 -6075 -6144 -6250 -6400 -6480 -6561 -6750 -6912 -7200 -7290 -7500 -7680 -7776 -8000 -8100 -8192 -8640 -8748 -9000 -9216 -9375 -9600 -9720 -10000 -10125 -10240 -10368 -10800 -10935 -11250 -11520 -11664 -12000 -12150 -12288 -12500 -12800 -12960 -13122 -13500 -13824 -14400 -14580 -15000 -15360 -15552 -15625 -16000 -16200 -16384 -16875 -17280 -17496 -18000 -18225 -18432 -18750 -19200 -19440 -19683 -20000 -20250 -20480 -20736 -21600 -21870 -22500 -23040 -23328 -24000 -24300 -24576 -25000 -25600 -25920 -26244 -27000 -27648 -28125 -28800 -29160 -30000 -30375 -30720 -31104 -31250 -32000 -32400 -32768 -32805 -33750 -34560 -34992 -36000 -36450 -36864 -37500 -38400 -38880 -39366 -40000 -40500 -40960 -41472 -43200 -43740 -45000 -46080 -46656 -46875 -48000 -48600 -49152 -50000 -50625 -51200 -51840 -52488 -54000 -54675 -55296 -56250 -57600 -58320 -59049 -60000 -60750 -61440 -62208 -62500 -64000 -64800 -65536 -65610 -67500 -69120 -69984 -72000 -72900 -73728 -75000 -76800 -77760 -78125 -78732 -80000 -81000 -81920 -82944 -84375 -86400 -87480 -90000 -91125 -92160 -93312 -93750 -96000 -97200 -98304 -98415 -100000 +51200000 +50837316566580 -- cgit From bbc66927a06a44a3e4c4223ef4d159b597734a5b Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 5 Jan 2022 21:01:57 +0100 Subject: Week 3, part 1: different algorithm for bc solution. --- challenge-003/abigail/bc/ch-1.bc | 39 +++++++++++++++++++++++++++++++++------ challenge-003/abigail/t/ctest.ini | 3 +++ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/challenge-003/abigail/bc/ch-1.bc b/challenge-003/abigail/bc/ch-1.bc index d3336b509d..bbbbdf3a2e 100644 --- a/challenge-003/abigail/bc/ch-1.bc +++ b/challenge-003/abigail/bc/ch-1.bc @@ -1,8 +1,35 @@ -max = read () -for (base2 = 1; base2 <= max; base2 *= 2) { - for (base3 = base2; base3 <= max; base3 *= 3) { - for (base5 = base3; base5 <= max; base5 *= 5) { - base5 - } +#!/usr/bin/bc + +# +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-003 +# + +# +# Run as: bc ch-1.bc < input-file +# + +while (1) { + n = read () + if (n == 0) { + break } + ugly [0] = 1 + next_2 = 0 + next_3 = 0 + next_5 = 0 + index = 1 + while (index < n) { + u2 = 2 * ugly [next_2] + u3 = 3 * ugly [next_3] + u5 = 5 * ugly [next_5] + if ((u2 <= u3) && (u2 <= u5)) {min = u2} + if ((u3 <= u2) && (u3 <= u5)) {min = u3} + if ((u5 <= u2) && (u5 <= u3)) {min = u5} + ugly [index] = min + if (2 * ugly [next_2] <= ugly [index]) {next_2 = next_2 + 1} + if (3 * ugly [next_3] <= ugly [index]) {next_3 = next_3 + 1} + if (5 * ugly [next_5] <= ugly [index]) {next_5 = next_5 + 1} + index = index + 1 + } + ugly [index - 1] } diff --git a/challenge-003/abigail/t/ctest.ini b/challenge-003/abigail/t/ctest.ini index a3434f63d2..71b4641536 100644 --- a/challenge-003/abigail/t/ctest.ini +++ b/challenge-003/abigail/t/ctest.ini @@ -8,3 +8,6 @@ 1-2 = Larger Numbers 2-1 = Minimal triangle 2-2 = 15 row triangle + +[1-1,1-2/bc] +add_to_input = 0 -- cgit From e22456cd4100b9d24449a0a1623236f0b5ecb412 Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 6 Jan 2022 01:47:00 +0100 Subject: Week 3, part 2: fix references --- challenge-003/abigail/awk/ch-2.awk | 2 +- challenge-003/abigail/c/ch-2.c | 2 +- challenge-003/abigail/lua/ch-2.lua | 2 +- challenge-003/abigail/node/ch-2.js | 2 +- challenge-003/abigail/perl/ch-2.pl | 2 +- challenge-003/abigail/python/ch-2.py | 2 +- challenge-003/abigail/ruby/ch-2.rb | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/challenge-003/abigail/awk/ch-2.awk b/challenge-003/abigail/awk/ch-2.awk index 1689ce668f..1079aaab62 100644 --- a/challenge-003/abigail/awk/ch-2.awk +++ b/challenge-003/abigail/awk/ch-2.awk @@ -1,7 +1,7 @@ #!/usr/bin/awk # -# See ../README.md +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-003 # # diff --git a/challenge-003/abigail/c/ch-2.c b/challenge-003/abigail/c/ch-2.c index 805f0d93be..7dee8c4eff 100644 --- a/challenge-003/abigail/c/ch-2.c +++ b/challenge-003/abigail/c/ch-2.c @@ -3,7 +3,7 @@ # include /* - * See ../README.md + * See https://theweeklychallenge.org/blog/perl-weekly-challenge-003 */ /* diff --git a/challenge-003/abigail/lua/ch-2.lua b/challenge-003/abigail/lua/ch-2.lua index 0e30b0a9c6..aed77c8e32 100644 --- a/challenge-003/abigail/lua/ch-2.lua +++ b/challenge-003/abigail/lua/ch-2.lua @@ -1,7 +1,7 @@ #!/opt/local/bin/lua -- --- See ../README.md +-- See https://theweeklychallenge.org/blog/perl-weekly-challenge-003 -- -- diff --git a/challenge-003/abigail/node/ch-2.js b/challenge-003/abigail/node/ch-2.js index af1724bb18..a161017ede 100644 --- a/challenge-003/abigail/node/ch-2.js +++ b/challenge-003/abigail/node/ch-2.js @@ -1,7 +1,7 @@ #!/usr/local/bin/node // -// See ../README.md +// See https://theweeklychallenge.org/blog/perl-weekly-challenge-003 // // diff --git a/challenge-003/abigail/perl/ch-2.pl b/challenge-003/abigail/perl/ch-2.pl index d5c14c4701..6d107b1e2d 100644 --- a/challenge-003/abigail/perl/ch-2.pl +++ b/challenge-003/abigail/perl/ch-2.pl @@ -10,7 +10,7 @@ use experimental 'signatures'; use experimental 'lexical_subs'; # -# See ../README.md +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-003 # # diff --git a/challenge-003/abigail/python/ch-2.py b/challenge-003/abigail/python/ch-2.py index 9370561d8b..3518b91c8e 100644 --- a/challenge-003/abigail/python/ch-2.py +++ b/challenge-003/abigail/python/ch-2.py @@ -1,7 +1,7 @@ #!/opt/local/bin/python # -# See ../READ.md +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-003 # # diff --git a/challenge-003/abigail/ruby/ch-2.rb b/challenge-003/abigail/ruby/ch-2.rb index 85736b99cb..1712bedc83 100644 --- a/challenge-003/abigail/ruby/ch-2.rb +++ b/challenge-003/abigail/ruby/ch-2.rb @@ -1,7 +1,7 @@ #!/usr/bin/ruby # -# See ../README.md +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-003 # # -- cgit From 76e71dbba093a8fa883b945df09e22d4b5b94ae2 Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 6 Jan 2022 13:56:30 +0100 Subject: Week 3, part 2: bash solution --- challenge-003/abigail/bash/ch-2.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 challenge-003/abigail/bash/ch-2.sh diff --git a/challenge-003/abigail/bash/ch-2.sh b/challenge-003/abigail/bash/ch-2.sh new file mode 100644 index 0000000000..ca5e5fb510 --- /dev/null +++ b/challenge-003/abigail/bash/ch-2.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +# +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-003 +# + +# +# Run as: bash ch-2.sh < input-file +# + +set -f + +declare -A p + +while read n +do for ((row = 0; row <= n; row ++)) + do p["$row;0"]=1 + printf "1 " + for ((col = 1; col <= row; col ++)) + do p["$row;$col"]=$((${p["$((row-1));$((col-1))"]:-0} + \ + ${p["$((row-1));$col"]:-0})) + printf "%d " ${p["$row;$col"]} + done + echo + done +done -- cgit From 27889f392ae8b7b56530ad79424eb9054a249275 Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 6 Jan 2022 13:59:18 +0100 Subject: Copied bc solution of week 3, part 1 --- challenge-003/abigail/README.md | 1 + challenge-123/abigail/README.md | 1 + challenge-123/abigail/bc/ch-1.bc | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 challenge-123/abigail/bc/ch-1.bc diff --git a/challenge-003/abigail/README.md b/challenge-003/abigail/README.md index 365945625a..83d08b3cd7 100644 --- a/challenge-003/abigail/README.md +++ b/challenge-003/abigail/README.md @@ -15,6 +15,7 @@ ### Part 2 * [AWK](awk/ch-2.awk) +* [Bash](bash/ch-2.sh) * [C](c/ch-2.c) * [Lua](lua/ch-2.lua) * [Node.js](node/ch-2.js) diff --git a/challenge-123/abigail/README.md b/challenge-123/abigail/README.md index e71bda7e0f..b3a9755e81 100644 --- a/challenge-123/abigail/README.md +++ b/challenge-123/abigail/README.md @@ -21,6 +21,7 @@ Output: 12 ### Solutions * [AWK](awk/ch-1.awk) * [Bash](bash/ch-1.sh) +* [bc](bc/ch-1.bc) * [C](c/ch-1.c) * [Lua](lua/ch-1.lua) * [Node.js](node/ch-1.js) diff --git a/challenge-123/abigail/bc/ch-1.bc b/challenge-123/abigail/bc/ch-1.bc new file mode 100644 index 0000000000..17ac31515a --- /dev/null +++ b/challenge-123/abigail/bc/ch-1.bc @@ -0,0 +1,35 @@ +#!/usr/bin/bc + +# +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-123 +# + +# +# Run as: bc ch-1.bc < input-file +# + +while (1) { + n = read () + if (n == 0) { + break + } + ugly [0] = 1 + next_2 = 0 + next_3 = 0 + next_5 = 0 + index = 1 + while (index < n) { + u2 = 2 * ugly [next_2] + u3 = 3 * ugly [next_3] + u5 = 5 * ugly [next_5] + if ((u2 <= u3) && (u2 <= u5)) {min = u2} + if ((u3 <= u2) && (u3 <= u5)) {min = u3} + if ((u5 <= u2) && (u5 <= u3)) {min = u5} + ugly [index] = min + if (2 * ugly [next_2] <= ugly [index]) {next_2 = next_2 + 1} + if (3 * ugly [next_3] <= ugly [index]) {next_3 = next_3 + 1} + if (5 * ugly [next_5] <= ugly [index]) {next_5 = next_5 + 1} + index = index + 1 + } + ugly [index - 1] +} -- cgit From bccd1e3a8efb165516051edab359b83b4b86cf03 Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 6 Jan 2022 15:33:59 +0100 Subject: Week 3 & Week 123. Go solutions for part 1. --- challenge-003/abigail/README.md | 1 + challenge-003/abigail/go/ch-1.go | 47 ++++++++++++++++++++++++++++++++++++++++ challenge-123/abigail/README.md | 1 + challenge-123/abigail/go/ch-1.go | 47 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+) create mode 100644 challenge-003/abigail/go/ch-1.go create mode 100644 challenge-123/abigail/go/ch-1.go diff --git a/challenge-003/abigail/README.md b/challenge-003/abigail/README.md index 83d08b3cd7..742ccb1714 100644 --- a/challenge-003/abigail/README.md +++ b/challenge-003/abigail/README.md @@ -5,6 +5,7 @@ * [Bash](bash/ch-1.sh) * [bc](bc/ch-1.bc) * [C](c/ch-1.c) +* [Go](go/ch-1.go) * [Lua](lua/ch-1.lua) * [Node.js](node/ch-1.js) * [Perl](perl/ch-1.pl) diff --git a/challenge-003/abigail/go/ch-1.go b/challenge-003/abigail/go/ch-1.go new file mode 100644 index 0000000000..03229cb964 --- /dev/null +++ b/challenge-003/abigail/go/ch-1.go @@ -0,0 +1,47 @@ +package main + +// +// See https://theweeklychallenge.org/blog/perl-weekly-challenge-003 +// + +// +// Run as: go run ch-1.go < input-file +// + +import ( + "fmt" +) + +func main () { + var max int + for { + n, err := fmt . Scanf ("%d", &max) + if (n != 1 || err != nil) { + break + } + ugly := make ([] int, max) + ugly [0] = 1 + count := 0 + next_2 := 0 + next_3 := 0 + next_5 := 0 + min := 0 + + for count < max - 1 { + count ++ + + c2 := 2 * ugly [next_2] + c3 := 3 * ugly [next_3] + c5 := 5 * ugly [next_5] + if c2 <= c3 && c2 <= c5 {min = c2} + if c3 <= c2 && c3 <= c5 {min = c3} + if c5 <= c2 && c5 <= c3 {min = c5} + ugly [count] = min + + if (c2 <= ugly [count]) {next_2 ++} + if (c3 <= ugly [count]) {next_3 ++} + if (c5 <= ugly [count]) {next_5 ++} + } + fmt . Println (ugly [count]) + } +} diff --git a/challenge-123/abigail/README.md b/challenge-123/abigail/README.md index b3a9755e81..da26e4f567 100644 --- a/challenge-123/abigail/README.md +++ b/challenge-123/abigail/README.md @@ -23,6 +23,7 @@ Output: 12 * [Bash](bash/ch-1.sh) * [bc](bc/ch-1.bc) * [C](c/ch-1.c) +* [Go](go/ch-1.go) * [Lua](lua/ch-1.lua) * [Node.js](node/ch-1.js) * [Perl](perl/ch-1.pl) diff --git a/challenge-123/abigail/go/ch-1.go b/challenge-123/abigail/go/ch-1.go new file mode 100644 index 0000000000..01e14fdef8 --- /dev/null +++ b/challenge-123/abigail/go/ch-1.go @@ -0,0 +1,47 @@ +package main + +// +// See https://theweeklychallenge.org/blog/perl-weekly-challenge-123 +// + +// +// Run as: go run ch-1.go < input-file +// + +import ( + "fmt" +) + +func main () { + var max int + for { + n, err := fmt . Scanf ("%d", &max) + if (n != 1 || err != nil) { + break + } + ugly := make ([] int, max) + ugly [0] = 1 + count := 0 + next_2 := 0 + next_3 := 0 + next_5 := 0 + min := 0 + + for count < max - 1 { + count ++ + + c2 := 2 * ugly [next_2] + c3 := 3 * ugly [next_3] + c5 := 5 * ugly [next_5] + if c2 <= c3 && c2 <= c5 {min = c2} + if c3 <= c2 && c3 <= c5 {min = c3} + if c5 <= c2 && c5 <= c3 {min = c5} + ugly [count] = min + + if (c2 <= ugly [count]) {next_2 ++} + if (c3 <= ugly [count]) {next_3 ++} + if (c5 <= ugly [count]) {next_5 ++} + } + fmt . Println (ugly [count]) + } +} -- cgit From 117db0cb5639368433cc1d1b683841ff91251665 Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 6 Jan 2022 15:35:13 +0100 Subject: Week 3: bc solution for part 2 --- challenge-003/abigail/README.md | 1 + challenge-003/abigail/bc/ch-2.bc | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 challenge-003/abigail/bc/ch-2.bc diff --git a/challenge-003/abigail/README.md b/challenge-003/abigail/README.md index 742ccb1714..3902fc3410 100644 --- a/challenge-003/abigail/README.md +++ b/challenge-003/abigail/README.md @@ -17,6 +17,7 @@ ### Part 2 * [AWK](awk/ch-2.awk) * [Bash](bash/ch-2.sh) +* [bc](bc/ch-2.bc) * [C](c/ch-2.c) * [Lua](lua/ch-2.lua) * [Node.js](node/ch-2.js) diff --git a/challenge-003/abigail/bc/ch-2.bc b/challenge-003/abigail/bc/ch-2.bc new file mode 100644 index 0000000000..e2c41b0455 --- /dev/null +++ b/challenge-003/abigail/bc/ch-2.bc @@ -0,0 +1,35 @@ +#!/usr/bin/bc + +# +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-003 +# + +# +# Run as: bc ch-2.bc < input-file +# + +while (1) { + n = read () + if (n == 0) { + break + } + + p [0] = 1 + p [0] + for (i = 1; i <= n; i ++) { + for (j = 0; j < i; j ++) { + n [j] = p [j] + if (j - 1 >= 0) { + n [j] = n [j] + p [j - 1] + } + print n [j], " " + } + n [i] = 1 + print "1 +" + for (j = 0; j <= i; j ++) { + p [j] = n [j] + } + } + break +} -- cgit From bb78b469bdba75ebe82f4f7c9d728281b97d515c Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 6 Jan 2022 16:05:11 +0100 Subject: Week 3 & Week 123: Java solutions for part 1 --- challenge-003/abigail/README.md | 1 + challenge-003/abigail/java/ch-1.java | 46 ++++++++++++++++++++++++++++++++++++ challenge-123/abigail/README.md | 1 + challenge-123/abigail/java/ch-1.java | 46 ++++++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+) create mode 100644 challenge-003/abigail/java/ch-1.java create mode 100644 challenge-123/abigail/java/ch-1.java diff --git a/challenge-003/abigail/README.md b/challenge-003/abigail/README.md index 3902fc3410..5a95fe5f0c 100644 --- a/challenge-003/abigail/README.md +++ b/challenge-003/abigail/README.md @@ -6,6 +6,7 @@ * [bc](bc/ch-1.bc) * [C](c/ch-1.c) * [Go](go/ch-1.go) +* [Java](java/ch-1.java) * [Lua](lua/ch-1.lua) * [Node.js](node/ch-1.js) * [Perl](perl/ch-1.pl) diff --git a/challenge-003/abigail/java/ch-1.java b/challenge-003/abigail/java/ch-1.java new file mode 100644 index 0000000000..651f938314 --- /dev/null +++ b/challenge-003/abigail/java/ch-1.java @@ -0,0 +1,46 @@ +// +// See https://theweeklychallenge.org/blog/perl-weekly-challenge-003 +// + +// +// Run as: ln ch-1.java ch1.java; javac ch1.java; java ch1 < input-file +// + +import java.util.*; + +public class ch1 { + public static void main (String [] args) { + Scanner scanner = new Scanner (System . in); + while (scanner . hasNextInt ()) { + int max = scanner . nextInt (); + long [] ugly = new long [max]; + + ugly [0] = 1L; + int count = 0; + int next_2 = 0; + int next_3 = 0; + int next_5 = 0; + + while (count < max - 1) { + count ++; + long min = 0; + + long c2 = 2 * ugly [next_2]; + long c3 = 3 * ugly [next_3]; + long c5 = 5 * ugly [next_5]; + + if (c2 <= c3 && c2 <= c5) {min = c2;} + if (c3 <= c2 && c3 <= c5) {min = c3;} + if (c5 <= c2 && c5 <= c3) {min = c5;} + + ugly [count] = min; + + if (c2 <= ugly [count]) {next_2 ++;} + if (c3 <= ugly [count]) {next_3 ++;} + if (c5 <= ugly [count]) {next_5 ++;} + } + + System . out . println (ugly [count]); + } + } +} diff --git a/challenge-123/abigail/README.md b/challenge-123/abigail/README.md index da26e4f567..4625c6930f 100644 --- a/challenge-123/abigail/README.md +++ b/challenge-123/abigail/README.md @@ -24,6 +24,7 @@ Output: 12 * [bc](bc/ch-1.bc) * [C](c/ch-1.c) * [Go](go/ch-1.go) +* [Java](java/ch-1.java) * [Lua](lua/ch-1.lua) * [Node.js](node/ch-1.js) * [Perl](perl/ch-1.pl) diff --git a/challenge-123/abigail/java/ch-1.java b/challenge-123/abigail/java/ch-1.java new file mode 100644 index 0000000000..51fc0881bb --- /dev/null +++ b/challenge-123/abigail/java/ch-1.java @@ -0,0 +1,46 @@ +// +// See https://theweeklychallenge.org/blog/perl-weekly-challenge-123 +// + +// +// Run as: ln ch-1.java ch1.java; javac ch1.java; java ch1 < input-file +// + +import java.util.*; + +public class ch1 { + public static void main (String [] args) { + Scanner scanner = new Scanner (System . in); + while (scanner . hasNextInt ()) { + int max = scanner . nextInt (); + long [] ugly = new long [max]; + + ugly [0] = 1L; + int count = 0; + int next_2 = 0; + int next_3 = 0; + int next_5 = 0; + + while (count < max - 1) { + count ++; + long min = 0; + + long c2 = 2 * ugly [next_2]; + long c3 = 3 * ugly [next_3]; + long c5 = 5 * ugly [next_5]; + + if (c2 <= c3 && c2 <= c5) {min = c2;} + if (c3 <= c2 && c3 <= c5) {min = c3;} + if (c5 <= c2 && c5 <= c3) {min = c5;} + + ugly [count] = min; + + if (c2 <= ugly [count]) {next_2 ++;} + if (c3 <= ugly [count]) {next_3 ++;} + if (c5 <= ugly [count]) {next_5 ++;} + } + + System . out . println (ugly [count]); + } + } +} -- cgit From ec311b177fa675877c45ed1518dceff5c787d13b Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 6 Jan 2022 18:22:18 +0100 Subject: Week 3, part 2. Go and Java solutions. --- challenge-003/abigail/README.md | 2 ++ challenge-003/abigail/go/ch-2.go | 40 ++++++++++++++++++++++++++++++++++++ challenge-003/abigail/java/ch-2.java | 34 ++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 challenge-003/abigail/go/ch-2.go create mode 100644 challenge-003/abigail/java/ch-2.java diff --git a/challenge-003/abigail/README.md b/challenge-003/abigail/README.md index 5a95fe5f0c..966649afde 100644 --- a/challenge-003/abigail/README.md +++ b/challenge-003/abigail/README.md @@ -20,6 +20,8 @@ * [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) * [Lua](lua/ch-2.lua) * [Node.js](node/ch-2.js) * [Perl](perl/ch-2.pl) diff --git a/challenge-003/abigail/go/ch-2.go b/challenge-003/abigail/go/ch-2.go new file mode 100644 index 0000000000..d66b10dec9 --- /dev/null +++ b/challenge-003/abigail/go/ch-2.go @@ -0,0 +1,40 @@ +package main + +// +// See https://theweeklychallenge.org/blog/perl-weekly-cha