From e17d0995d756e101c96e9c5b173939f5a2263cb9 Mon Sep 17 00:00:00 2001 From: Simon Proctor Date: Wed, 16 Jun 2021 12:34:36 +0100 Subject: Second attempt at challenge 2... slightly faster --- challenge-115/simon-proctor/raku/ch-2-2.raku | 71 ++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 challenge-115/simon-proctor/raku/ch-2-2.raku diff --git a/challenge-115/simon-proctor/raku/ch-2-2.raku b/challenge-115/simon-proctor/raku/ch-2-2.raku new file mode 100644 index 0000000000..81ba11d805 --- /dev/null +++ b/challenge-115/simon-proctor/raku/ch-2-2.raku @@ -0,0 +1,71 @@ +#!/usr/bin/env raku + +#|( Given a triangle of height $N return the possible routes from the top + To the bottom right +) +multi sub MAIN(UInt $N) { + say traverse-triangle($N).join(", "); +} + +multi sub MAIN("test") is hidden-from-USAGE { + use Test; + ok traverse-triangle(1) (==) ; + ok traverse-triangle(2) (==) ; +} + +sub traverse-triangle( $size ) { + my %seen; + my @routes = ["R" x $size]; + + while (@routes) { + my @promises; + while (@routes && @promises.elems < 1000) { + my $route = shift @routes; + next if %seen{$route}; + %seen{$route} = True; + given $route { + when /R/ { + @promises.push( start mod-right( $route ) ); + proceed; + } + when /HL/ { + @promises.push( start mod-hl( $route ) ); + } + } + } + + await @promises; + + for (@promises) -> $p { + for ( $p.result ) { + @routes.push( $_ ) if ! %seen{$_} && ($_ !(elem) @routes); + } + } + + #note @routes.elems ~ ":" ~ @promises.elems ~ ":" ~ %seen.keys.elems; + + } + + + return %seen.keys; +} + +sub mod-right( Str $row ) { + my @out; + for (0..^$row.codes) -> $i { + if ( $row.substr($i,1) eq "R" ) { + @out.push( $row.substr(0,$i) ~ "LH" ~ $row.substr($i+1) ); + } + } + return @out; +} + +sub mod-hl( Str $row ) { + my @out; + for (0..^$row.codes-1) -> $i { + if ( $row.substr($i,2) eq "HL" ) { + @out.push( $row.substr(0,$i) ~ "R" ~ $row.substr($i+2) ); + } + } + return @out; +} \ No newline at end of file -- cgit From f6a8d5af7bb92ef0d021fe409b466c9ed25bb0dd Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 21 Jun 2021 12:42:22 +0200 Subject: README for week 118 --- challenge-118/abigail/README.md | 88 +++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 51 deletions(-) diff --git a/challenge-118/abigail/README.md b/challenge-118/abigail/README.md index 7db94b7f39..05677d379c 100644 --- a/challenge-118/abigail/README.md +++ b/challenge-118/abigail/README.md @@ -1,27 +1,20 @@ # Solutions by Abigail -## [Missing Row](https://perlweeklychallenge.org/blog/perl-weekly-challenge-117/#TASK1) +## [Binary Palindrome](https://perlweeklychallenge.org/blog/perl-weekly-challenge-118/#TASK1) -> You are given text file with rows numbered `1-15` in random order but -> there is a catch one row in missing in the file. +> You are given a positive integer $N. +> +> Write a script to find out if the binary representation of the given +> integer is Palindrome. Print 1 if it is otherwise 0. +> +### Examples ~~~~ -11, Line Eleven -1, Line one -9, Line Nine -13, Line Thirteen -2, Line two -6, Line Six -8, Line Eight -10, Line Ten -7, Line Seven -4, Line Four -14, Line Fourteen -3, Line three -15, Line Fifteen -5, Line Five -~~~~ +Input: $N = 5 +Output: 1 as binary representation of 5 is 101 which is Palindrome. -Write a script to find the missing row number. +Input: $N = 4 +Output: 0 as binary representation of 4 is 100 which is NOT Palindrome. +~~~~ ### Solutions * [AWK](awk/ch-1.awk) @@ -36,41 +29,34 @@ Write a script to find the missing row number. * [Ruby](ruby/ch-1.rb) ### Blog -[Missing Row](https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-117-1.html) +[Binary Palindrome](https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-118-1.html) -## [Find Possible Paths](https://perlweeklychallenge.org/blog/perl-weekly-challenge-115/#TASK2) +## [Adventure of Knight](https://perlweeklychallenge.org/blog/perl-weekly-challenge-118/#TASK2) -> You are given size of a triangle. -> -> Write a script to find all possible paths from top to the bottom -> right corner. -> -> In each step, we can either move horizontally to the right (`H`), or -> move downwards to the left (`L`) or right (`R`). +> A knight is restricted to move on an 8x8 chessboard. The knight is denoted +> by `N` and its way of movement is the same as what it is defined in Chess. +> `*` represents an empty square. `x` represents a square with treasure. +> +> > The Knight's movement is unique. It may move two squares vertically and +> > one square horizontally, or two squares horizontally and one square +> > vertically (with both forming the shape of an L). +> +> There are 6 squares with treasures. +> +> Write a script to find the path such that Knight can capture all +> treasures. The Knight can start from the top-left square. > -> BONUS: Try if it can handle triangle of size `10` or `20`. - -### Examples -~~~~ -Input: $N = 2 - - S - / \ - / _ \ - /\ /\ - /__\ /__\ E - -Output: RR, LHR, LHLH, LLHH, RLH, LRH -~~~~ - ~~~~ -Input: $N = 1 - - S - / \ - / _ \ E - -Output: R, LH + a b c d e f g h + 8 N * * * * * * * 8 + 7 * * * * * * * * 7 + 6 * * * * x * * * 6 + 5 * * * * * * * * 5 + 4 * * x * * * * * 4 + 3 * x * * * * * * 3 + 2 x x * * * * * * 2 + 1 * x * * * * * * 1 + a b c d e f g h ~~~~ ### Solutions @@ -86,4 +72,4 @@ Output: R, LH * [Ruby](ruby/ch-2.rb) ### Blog -[Find Possible Paths](https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-117-2.html) +[Adventure of Knight](https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-118-2.html) -- cgit From eff92d47c584ac99c453a0f5572d6bc0a2843da3 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 21 Jun 2021 13:20:20 +0200 Subject: Perl solution for week 118, part 1 --- challenge-118/abigail/perl/ch-1.pl | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 challenge-118/abigail/perl/ch-1.pl diff --git a/challenge-118/abigail/perl/ch-1.pl b/challenge-118/abigail/perl/ch-1.pl new file mode 100644 index 0000000000..99df6f0f65 --- /dev/null +++ b/challenge-118/abigail/perl/ch-1.pl @@ -0,0 +1,26 @@ +#!/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 +# + +# +# More efficient is to store the binary representation of the number +# in a variable, and see whether it's the same as its reverse, but +# using a pattern turns it into a one liner. +# + +say sprintf ("%b" => $_) =~ /^(([01])(?1)\g{2}|[01]?)$/ || 0 while <>; -- cgit From fb8b828cd7c83894fed534d9d1894981a0dce203 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 21 Jun 2021 14:12:53 +0200 Subject: AWK solution for week 118, part 1 --- challenge-118/abigail/awk/ch-1.awk | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 challenge-118/abigail/awk/ch-1.awk diff --git a/challenge-118/abigail/awk/ch-1.awk b/challenge-118/abigail/awk/ch-1.awk new file mode 100644 index 0000000000..490a5ceefc --- /dev/null +++ b/challenge-118/abigail/awk/ch-1.awk @@ -0,0 +1,36 @@ +#!/usr/bin/awk + +# +# See ../README.md +# + +# +# Run as: awk -f ch-1.awk < input-file +# + +# +# Get a binary representation +# +function dec2bin (dec, bin) { + while (dec) { + bin = dec % 2 bin + dec = int (dec / 2) + } + return (bin) +} + +{ + bin = dec2bin($1) + l = length (bin) + # + # Check if it's a palindrome + # + for (i = 1; i < l / 2; i ++) { + if (substr (bin, i, 1) != substr (bin, l - i + 1, 1)) { + print (0) + next + } + } + print (1) +} + -- cgit From 5ab7990c1199c721345fe3f9beb52634862f8396 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 21 Jun 2021 14:56:54 +0200 Subject: Bash solution for week 118, part 1 --- challenge-118/abigail/bash/ch-1.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 challenge-118/abigail/bash/ch-1.sh diff --git a/challenge-118/abigail/bash/ch-1.sh b/challenge-118/abigail/bash/ch-1.sh new file mode 100644 index 0000000000..873decd636 --- /dev/null +++ b/challenge-118/abigail/bash/ch-1.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +# +# See ../README.md +# + +# +# Run as: bash ch-1.sh < input-file +# + +set -f + +function dec2bin () { + dec=$1 + bin="" + while ((dec > 0)) + do bin=$((dec % 2))$bin + ((dec /= 2)) + done +} + +while read dec +do dec2bin $dec + for ((i = 0; i < ${#bin} / 2; i ++)) + do if [ "${bin:$i:1}" = "${bin:$((${#bin} - i - 1)):1}" ] + then continue + fi + echo 0 + continue 2 + done + echo 1 +done -- cgit From 8f7b0abc3ed0410970c5944e912f449a44f14a80 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 21 Jun 2021 15:25:11 +0200 Subject: C solution for week 118, part 1 --- challenge-118/abigail/c/ch-1.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 challenge-118/abigail/c/ch-1.c diff --git a/challenge-118/abigail/c/ch-1.c b/challenge-118/abigail/c/ch-1.c new file mode 100644 index 0000000000..637c938d0e --- /dev/null +++ b/challenge-118/abigail/c/ch-1.c @@ -0,0 +1,42 @@ +# include +# include +# include + +/* + * See ../README.md + */ + +/* + * Run as: cc -o ch-1.o ch-1.c; ./ch-1.o < input-file + */ + + +int main (void) { + long long dec; + while (scanf ("%lld", &dec) == 1) { + /* + * Find the largest power of 2 smaller than dec; + * this is the position of the leading 1. + */ + long long i = 1; + int k = 0; + for (k = 0; i <= dec; k ++, i = i << 1); + /* + * We overshot by 1 + */ + k -= 1; + + /* + * Now, compare the bits + */ + int is_palin = 1; + for (int j = 0; j < k; k --, j ++) { + if (((dec & (1 << j)) >> j) != ((dec & (1 << k)) >> k)) { + is_palin = 0; + break; + } + } + printf ("%d\n", is_palin); + } + return (0); +} -- cgit From 7ac27fdb94896a8250018ff135e72f9a99071f54 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 21 Jun 2021 18:48:27 +0200 Subject: Lua solution for week 118, part 1 --- challenge-118/abigail/lua/ch-1.lua | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 challenge-118/abigail/lua/ch-1.lua diff --git a/challenge-118/abigail/lua/ch-1.lua b/challenge-118/abigail/lua/ch-1.lua new file mode 100644 index 0000000000..a129db19e4 --- /dev/null +++ b/challenge-118/abigail/lua/ch-1.lua @@ -0,0 +1,32 @@ +#!/opt/local/bin/lua + +-- +-- See ../README.md +-- + +-- +-- Run as: lua ch-1.lua < input-file +-- + +-- +-- Find the binary representation of a number. +-- Note that the function return a string in reverse order; +-- this will do for our purpose as we want a palindrome anyway. +-- +function dec2bin (dec) + local bin = {} + while dec > 0 do + bin [#bin + 1] = dec % 2 + dec = math . floor (dec / 2) + end + return table . concat (bin) +end + +for line in io . lines () do + bin = dec2bin (tonumber (line)) + if bin == string . reverse (bin) then + print (1) + else + print (0) + end +end -- cgit From 7160801add8cbeff393124515ad2846da6265a69 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 21 Jun 2021 19:02:10 +0200 Subject: Node.js solution for week 118, part 1 --- challenge-118/abigail/node/ch-1.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 challenge-118/abigail/node/ch-1.js diff --git a/challenge-118/abigail/node/ch-1.js b/challenge-118/abigail/node/ch-1.js new file mode 100644 index 0000000000..7247cb5eef --- /dev/null +++ b/challenge-118/abigail/node/ch-1.js @@ -0,0 +1,16 @@ +#!/usr/local/bin/node + +// +// See ../README.md +// + +// +// Run as: node ch-1.js < input-file +// + + require ('readline') +. createInterface ({input: process . stdin}) +. on ('line', (line) => { + let bin = (+line) . toString (2) + console . log (bin == bin . split ("") . reverse () . join ("") ? 1 : 0) +}) -- cgit From f245cfefa46f122166a0034aa82507ea2b84ee5e Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 21 Jun 2021 19:29:32 +0200 Subject: Python solution for week 118, part 1 --- challenge-118/abigail/python/ch-1.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 challenge-118/abigail/python/ch-1.py diff --git a/challenge-118/abigail/python/ch-1.py b/challenge-118/abigail/python/ch-1.py new file mode 100644 index 0000000000..df0451a44e --- /dev/null +++ b/challenge-118/abigail/python/ch-1.py @@ -0,0 +1,19 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-1.py < input-file +# + +import fileinput + +for line in fileinput . input (): + bin = '{:b}' . format (int (line)) # Turn to binary representation + if bin == bin [::-1]: # bin [::-1] reverse the string + print (1) + else: + print (0) + -- cgit From 1b31356bcb86b22fa81bd86f0a4345cf0eb9e784 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 21 Jun 2021 19:42:25 +0200 Subject: Ruby solution for week 118, part 1 --- challenge-118/abigail/ruby/ch-1.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 challenge-118/abigail/ruby/ch-1.rb diff --git a/challenge-118/abigail/ruby/ch-1.rb b/challenge-118/abigail/ruby/ch-1.rb new file mode 100644 index 0000000000..2609253a2d --- /dev/null +++ b/challenge-118/abigail/ruby/ch-1.rb @@ -0,0 +1,15 @@ +#!/usr/bin/ruby + +# +# See ../README.md +# + +# +# Run as: ruby ch-1.rb < input-file +# + +ARGF . each_line do + |dec| + bin = "%b" % dec + puts (bin == bin . reverse ? 1 : 0) +end -- cgit From d37b3bd215636fd3dbac1935a6cfd4dd42a1d7cb Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 21 Jun 2021 20:24:14 +0200 Subject: Go solution for week 118, part 1 --- challenge-118/abigail/go/ch-1.go | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 challenge-118/abigail/go/ch-1.go diff --git a/challenge-118/abigail/go/ch-1.go b/challenge-118/abigail/go/ch-1.go new file mode 100644 index 0000000000..466a5e574f --- /dev/null +++ b/challenge-118/abigail/go/ch-1.go @@ -0,0 +1,41 @@ +package main + +// +// See ../README.md +// + +// +// Run as: go run ch-1.go +// + +import ( + "fmt" + "strconv" +) + +func reverse (str string) string { + rev := [] rune (str) + for i, j := 0, len (rev) - 1; i < j; i, j = i + 1, j - 1 { + rev [i], rev [j] = rev [j], rev [i] + } + return string (rev) +} + +func main () { + var dec int64 + for { + var n, err = fmt . Scanf ("%d", &dec) + if (n != 1 || err != nil) { + break + } + var bin = strconv . FormatInt (dec, 2) + if (bin == reverse (bin)) { + fmt . Println (1) + } else { + fmt . Println (0) + } + } +} + + + -- cgit From c96706ce3310f524797452e334c84bbff90a9a5d Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 21 Jun 2021 22:02:41 +0200 Subject: Java solution for week 118, part 1 --- challenge-118/abigail/java/ch-1.java | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 challenge-118/abigail/java/ch-1.java diff --git a/challenge-118/abigail/java/ch-1.java b/challenge-118/abigail/java/ch-1.java new file mode 100644 index 0000000000..a806d2c237 --- /dev/null +++ b/challenge-118/abigail/java/ch-1.java @@ -0,0 +1,34 @@ +// +// 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 void main (String [] args) { + Scanner scanner = new Scanner (System . in); + try { + while (true) { + int dec = scanner . nextInt (); + String bin = Integer . toBinaryString (dec); + + if (bin . equals (new StringBuilder (bin) . + reverse () . toString ())) { + System . out . println (1); + } + else { + System . out . println (0); + } + } + } + catch (Exception e) { + // + // EOF + // + } + } +} -- cgit From 0b3b62e85d589d3389982c7eefb6865459c93934 Mon Sep 17 00:00:00 2001 From: Abigail Date: Tue, 22 Jun 2021 18:31:06 +0200 Subject: Perl solution for week 118, part 2 --- challenge-118/abigail/perl/ch-2.pl | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 challenge-118/abigail/perl/ch-2.pl diff --git a/challenge-118/abigail/perl/ch-2.pl b/challenge-118/abigail/perl/ch-2.pl new file mode 100644 index 0000000000..e0dafb03f0 --- /dev/null +++ b/challenge-118/abigail/perl/ch-2.pl @@ -0,0 +1,49 @@ +#!/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 +# +# First thing which spring to mind is: there is a closed knight's tour +# on a chess board. In fact, there are 19,591,828,170,979,904 of them +# (counting rotations and reflections, but not direction). See A165134 +# in the OEIS. (And there are also billions of open tours visiting all +# squares...) +# +# And any knight's tour will visit all squares, including the ones with +# treasure. So, we could just pick a tour visiting all squares and +# calling it a day. This would turn the challenge into a glorified +# Hello World! program. +# +# So, perhaps we should focus on the bonus part. +# +# But wait, there's no variable input. There's just a fixed board +# to work with. And one can quickly see there's an 11 step path +# visiting all the treasure, and no 10 step path. +# +# So, this challenge is yet another boring Hello, World! program. +# After all, it's much easier to write down the 11 knights moves than +# to write a program. +# +# To up the ante, we'll write a second program (ch-2a.pl) which actually +# reads input and does calculations. But the main solution will just print +# out the 11-move path. +# +# I really do hope the PWC steps away from fixed output challenges. +# + +say "c7 e6 c5 b3 c1 a2 c3 b1 d2 c4 b2"; + +__END__ -- cgit From cea0a95b6889a97885e46c6147faf21a4888af25 Mon Sep 17 00:00:00 2001 From: Abigail Date: Tue, 22 Jun 2021 18:31:47 +0200 Subject: Upping the ante for week 118, part 2 (Perl) --- challenge-118/abigail/perl/ch-2a.pl | 102 ++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 challenge-118/abigail/perl/ch-2a.pl diff --git a/challenge-118/abigail/perl/ch-2a.pl b/challenge-118/abigail/perl/ch-2a.pl new file mode 100644 index 0000000000..f2bbef804c --- /dev/null +++ b/challenge-118/abigail/perl/ch-2a.pl @@ -0,0 +1,102 @@ +#!/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-2a.pl < input-file +# +# Second solution; this time we actually read a challenge from +# STDIN. Each line of input stands for another challenge, +# Each line consists of 2 or more chess squares; the first is +# the starting point of the knight, the rest treasures to be visited. +# + +my $MAX_FILE = 8; +my $MAX_RANK = 8; + +# +# Given a file and rank as numbers, return the algebraic name of a square +# +sub c2a ($file, $rank) { + sprintf "%c%d", ord ('a') + $file - 1, $rank +} + +# +# Precompute all knight moves on the board. +# +my %knight_moves; # Maps square to all squares reachable from it. +for my $file (1 .. $MAX_FILE) { + for my $rank (1 .. $MAX_RANK) { + my $square = c2a $file, $rank; + # + # Consider only moves in one direction; we add reverse moves as well. + # Knight moves 2 in one direction, and 1 orthogonally from that. + # + for my $move ([1, 2], [1, -2], [2, 1], [2, -1]) { + next unless 1 <= $file + $$move [0] <= $MAX_FILE && + 1 <= $rank + $$move [1] <= $MAX_RANK; + my $target = c2a $file + $$move [0], $rank + $$move [1]; + push @{$knight_moves {$square}} => $target; + push @{$knight_moves {$target}} => $square; + } + } +} + + + +# +# Given a starting square, and a set of treasure locations, do a +# breath first search to find a shortest path visiting all the +# treasure locations. +# +# Note that we do allow to revisit squares, but only if they have a +# different set of visited "treasure" squares. It is after all possible +# that the shortest path revisits squares. +# +sub find_treasure ($start_square, @treasure) { + my %treasure = map {$_ => 1} @treasure; + + my %visited; # Maps square x seen treasure to 1 + + my @todo = ([[$start_square], {}]); + # Entries in the @todo list are tuples: + # - The path that got us here; the last element being + # the "current" square + # - A mapping of which treasure squares we have visited + # on the path. + + while (@todo) { + my ($path, $old_seen) = @{shift @todo}; + my $square = $$path [-1]; + my $seen = {%$old_seen}; + $$seen {$square} = 1 if $treasure {$square}; + + my $key = join " " => $square, sort keys %$seen; + next if $visited {$key} ++; + + if (keys %$seen == keys %treasure) { + # + # We have seen all the treasure: return the path. + # + return $path; + } + + push @todo => map {[[@$path => $_], $seen]} @{$knight_moves {$square}}; + } +} + + +say "@{find_treasure split}" while <>; + +__END__ -- cgit From ef87285d2c8d743bf79a781d1a4314d4c30d12a3 Mon Sep 17 00:00:00 2001 From: Abigail Date: Tue, 22 Jun 2021 19:57:37 +0200 Subject: Print starting square --- challenge-118/abigail/perl/ch-2.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/challenge-118/abigail/perl/ch-2.pl b/challenge-118/abigail/perl/ch-2.pl index e0dafb03f0..3a28598fac 100644 --- a/challenge-118/abigail/perl/ch-2.pl +++ b/challenge-118/abigail/perl/ch-2.pl @@ -44,6 +44,6 @@ use experimental 'lexical_subs'; # I really do hope the PWC steps away from fixed output challenges. # -say "c7 e6 c5 b3 c1 a2 c3 b1 d2 c4 b2"; +say "a8 c7 e6 c5 b3 c1 a2 c3 b1 d2 c4 b2"; __END__ -- cgit From d2907c9dfe40252ea7e11c7c822f06ea2bc793bf Mon Sep 17 00:00:00 2001 From: Abigail Date: Tue, 22 Jun 2021 19:57:51 +0200 Subject: Tests for week 118 --- challenge-118/abigail/t/ctest.ini | 7 +++++++ challenge-118/abigail/t/input-1-1 | 2 ++ challenge-118/abigail/t/input-2-1 | 1 + challenge-118/abigail/t/output-1-1.exp | 2 ++ challenge-118/abigail/t/output-2-1.exp | 1 + 5 files changed, 13 insertions(+) create mode 100644 challenge-118/abigail/t/ctest.ini create mode 100644 challenge-118/abigail/t/input-1-1 create mode 100644 challenge-118/abigail/t/input-2-1 create mode 100644 challenge-118/abigail/t/output-1-1.exp create mode 100644 challenge-118/abigail/t/output-2-1.exp diff --git a/challenge-118/abigail/t/ctest.ini b/challenge-118/abigail/t/ctest.ini new file mode 100644 index 0000000000..d1a3f6baf6 --- /dev/null +++ b/challenge-118/abigail/t/ctest.ini @@ -0,0 +1,7 @@ +# +# Configuration file for running tests, using ctest. +# See https://github.com/Abigail/Misc/blob/master/ctest +# + +[names] +1-1 = Given Examples diff --git a/challenge-118/abigail/t/input-1-1 b/challenge-118/abigail/t/input-1-1 new file mode 100644 index 0000000000..b5104f3ba9 --- /dev/null +++ b/challenge-118/abigail/t/input-1-1 @@ -0,0 +1,2 @@ +5 +4 diff --git a/challenge-118/abigail/t/input-2-1 b/challenge-118/abigail/t/input-2-1 new file mode 100644 index 0000000000..376243accc --- /dev/null +++ b/challenge-118/abigail/t/input-2-1 @@ -0,0 +1 @@ +a8 b1 a2 b2 b3 c4 e6 diff --git a/challenge-118/abigail/t/output-1-1.exp b/challenge-118/abigail/t/output-1-1.exp new file mode 100644 index 0000000000..b261da18d5 --- /dev/null +++ b/challenge-118/abigail/t/output-1-1.exp @@ -0,0 +1,2 @@ +1 +0 diff --git a/challenge-118/abigail/t/output-2-1.exp b/challenge-118/abigail/t/output-2-1.exp new file mode 100644 index 0000000000..47e497232b --- /dev/null +++ b/challenge-118/abigail/t/output-2-1.exp @@ -0,0 +1 @@ +a8 c7 e6 c5 b3 c1 a2 c3 b1 d2 c4 b2 -- cgit From f23ea63093e2ae3a4cba10e54b374d9b46f9b764 Mon Sep 17 00:00:00 2001 From: Abigail Date: Tue, 22 Jun 2021 20:04:40 +0200 Subject: Move via a3 instead of d2 --- challenge-118/abigail/perl/ch-2.pl | 2 +- challenge-118/abigail/t/output-2-1.exp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/challenge-118/abigail/perl/ch-2.pl b/challenge-118/abigail/perl/ch-2.pl index 3a28598fac..2d224fd1fc 100644 --- a/challenge-118/abigail/perl/ch-2.pl +++ b/challenge-118/abigail/perl/ch-2.pl @@ -44,6 +44,6 @@ use experimental 'lexical_subs'; # I really do hope the PWC steps away from fixed output challenges. # -say "a8 c7 e6 c5 b3 c1 a2 c3 b1 d2 c4 b2"; +say "a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2"; __END__ diff --git a/challenge-118/abigail/t/output-2-1.exp b/challenge-118/abigail/t/output-2-1.exp index 47e497232b..f0803658c1 100644 --- a/challenge-118/abigail/t/output-2-1.exp +++ b/challenge-118/abigail/t/output-2-1.exp @@ -1 +1 @@ -a8 c7 e6 c5 b3 c1 a2 c3 b1 d2 c4 b2 +a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2 -- cgit From 9c47a695c2f01a7fb23e1647c40b5c31ade33c2f Mon Sep 17 00:00:00 2001 From: Abigail Date: Tue, 22 Jun 2021 20:12:51 +0200 Subject: Solutions for 29 languages. Since we have a gloried Hello, World! challenge.... --- challenge-118/abigail/awk/ch-2.awk | 14 ++++++++++++++ challenge-118/abigail/bash/ch-2.sh | 11 +++++++++++ challenge-118/abigail/basic/ch-2.bas | 9 +++++++++ challenge-118/abigail/bc/ch-2.bc | 10 ++++++++++ challenge-118/abigail/befunge-93/ch-2.bf93 | 2 ++ challenge-118/abigail/c/ch-2.c | 16 ++++++++++++++++ challenge-118/abigail/cobol/ch-2.cb | 14 ++++++++++++++ challenge-118/abigail/csh/ch-2.csh | 11 +++++++++++ challenge-118/abigail/erlang/ch-2.erl | 15 +++++++++++++++ challenge-118/abigail/forth/ch-2.fs | 5 +++++ challenge-118/abigail/fortran/ch-2.f90 | 12 ++++++++++++ challenge-118/abigail/go/ch-2.go | 15 +++++++++++++++ challenge-118/abigail/java/ch-2.java | 13 +++++++++++++ challenge-118/abigail/lua/ch-2.lua | 11 +++++++++++ challenge-118/abigail/m4/ch-2.m4 | 1 + challenge-118/abigail/mmix/ch-2.mms | 16 ++++++++++++++++ challenge-118/abigail/node/ch-2.js | 11 +++++++++++ challenge-118/abigail/ocaml/ch-2.ml | 9 +++++++++ challenge-118/abigail/pascal/ch-2.p | 13 +++++++++++++ challenge-118/abigail/php/ch-2.php | 11 +++++++++++ challenge-118/abigail/postscript/ch-2.ps | 10 ++++++++++ challenge-118/abigail/python/ch-2.py | 11 +++++++++++ challenge-118/abigail/r/ch-2.r | 9 +++++++++ challenge-118/abigail/rexx/ch-2.rexx | 9 +++++++++ challenge-118/abigail/ruby/ch-2.rb | 11 +++++++++++ challenge-118/abigail/scheme/ch-2.scm | 9 +++++++++ challenge-118/abigail/sed/ch-2.sed | 12 ++++++++++++ challenge-118/abigail/sql/ch-2.sql | 9 +++++++++ challenge-118/abigail/tcl/ch-2.tcl | 9 +++++++++ 29 files changed, 308 insertions(+) create mode 100644 challenge-118/abigail/awk/ch-2.awk create mode 100644 challenge-118/abigail/bash/ch-2.sh create mode 100644 challenge-118/abigail/basic/ch-2.bas create mode 100644 challenge-118/abigail/bc/ch-2.bc create mode 100644 challenge-118/abigail/befunge-93/ch-2.bf93 create mode 100644 challenge-118/abigail/c/ch-2.c create mode 100644 challenge-118/abigail/cobol/ch-2.cb create mode 100644 challenge-118/abigail/csh/ch-2.csh create mode 100644 challenge-118/abigail/erlang/ch-2.erl create mode 100644 challenge-118/abigail/forth/ch-2.fs create mode 100644 challenge-118/abigail/fortran/ch-2.f90 create mode 100644 challenge-118/abigail/go/ch-2.go create mode 100644 challenge-118/abigail/java/ch-2.java create mode 100644 challenge-118/abigail/lua/ch-2.lua create mode 100644 challenge-118/abigail/m4/ch-2.m4 create mode 100644 challenge-118/abigail/mmix/ch-2.mms create mode 100644 challenge-118/abigail/node/ch-2.js create mode 100644 challenge-118/abigail/ocaml/ch-2.ml create mode 100644 challenge-118/abigail/pascal/ch-2.p create mode 100644 challenge-118/abigail/php/ch-2.php create mode 100644 challenge-118/abigail/postscript/ch-2.ps create mode 100644 challenge-118/abigail/python/ch-2.py create mode 100644 challenge-118/abigail/r/ch-2.r create mode 100644 challenge-118/abigail/rexx/ch-2.rexx create mode 100644 challenge-118/abigail/ruby/ch-2.rb create mode 100644 challenge-118/abigail/scheme/ch-2.scm create mode 100644 challenge-118/abigail/sed/ch-2.sed create mode 100644 challenge-118/abigail/sql/ch-2.sql create mode 100644 challenge-118/abigail/tcl/ch-2.tcl diff --git a/challenge-118/abigail/awk/ch-2.awk b/challenge-118/abigail/awk/ch-2.awk new file mode 100644 index 0000000000..d4cf905f2e --- /dev/null +++ b/challenge-118/abigail/awk/ch-2.awk @@ -0,0 +1,14 @@ +#!/usr/bin/awk + +# +# See ../README.md +# + +# +# Run as: awk -f ch-2.awk +# + +BEGIN { + print "a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2" +} + diff --git a/challenge-118/abigail/bash/ch-2.sh b/challenge-118/abigail/bash/ch-2.sh new file mode 100644 index 0000000000..e48430410e --- /dev/null +++ b/challenge-118/abigail/bash/ch-2.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +# +# See ../README.md +# + +# +# Run as: bash ch-2.sh +# + +echo "a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2" diff --git a/challenge-118/abigail/basic/ch-2.bas b/challenge-118/abigail/basic/ch-2.bas new file mode 100644 index 0000000000..8e07ba8840 --- /dev/null +++ b/challenge-118/abigail/basic/ch-2.bas @@ -0,0 +1,9 @@ +010 REM +020 REM See ../README.md +030 REM + +040 REM +050 REM Run as: basic ch-2.bas +060 REM + +100 PRINT "a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2" diff --git a/challenge-118/abigail/bc/ch-2.bc b/challenge-118/abigail/bc/ch-2.bc new file mode 100644 index 0000000000..5125d6a827 --- /dev/null +++ b/challenge-118/abigail/bc/ch-2.bc @@ -0,0 +1,10 @@ +# +# See ../README.md +# + +# +# Run as: bc ch-2.bc +# +"a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2 +" +quit diff --git a/challenge-118/abigail/befunge-93/ch-2.bf93 b/challenge-118/abigail/befunge-93/ch-2.bf93 new file mode 100644 index 0000000000..b31e3efee9 --- /dev/null +++ b/challenge-118/abigail/befunge-93/ch-2.bf93 @@ -0,0 +1,2 @@ +< v,_@#:< "a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2" +55 + > ^ diff --git a/challenge-118/abigail/c/ch-2.c b/challenge-118/abigail/c/ch-2.c new file mode 100644 index 0000000000..74531ee18d --- /dev/null +++ b/challenge-118/abigail/c/ch-2.c @@ -0,0 +1,16 @@ +# include +# include +# include + +/* + * See ../README.md + */ + +/* + * Run as: cc -o ch-2.o ch-2.c; ./ch-2.o + */ + +int main (void) { + printf ("a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2\n"); + exit (0); +} diff --git a/challenge-118/abigail/cobol/ch-2.cb b/challenge-118/abigail/cobol/ch-2.cb new file mode 100644 index 0000000000..a756c0f8d2 --- /dev/null +++ b/challenge-118/abigail/cobol/ch-2.cb @@ -0,0 +1,14 @@ +IDENTIFICATION DIVISION. +PROGRAM-ID. XXX. + +*> +*> See ../README.md +*> + +*> +*> Run as: cobc -xF -o ch-2.o ch-2.cb; ./ch-2.o +*> + +PROCEDURE DIVISION. + DISPLAY "a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2". + STOP RUN. diff --git a/challenge-118/abigail/csh/ch-2.csh b/challenge-118/abigail/csh/ch-2.csh new file mode 100644 index 0000000000..bdcc9cee6d --- /dev/null +++ b/challenge-118/abigail/csh/ch-2.csh @@ -0,0 +1,11 @@ +#!/bin/csh + +# +# See ../README.md +# + +# +# Run as: csh ch-2.csh +# + +echo "a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2" diff --git a/challenge-118/abigail/erlang/ch-2.erl b/challenge-118/abigail/erlang/ch-2.erl new file mode 100644 index 0000000000..8357a62e7d --- /dev/null +++ b/challenge-118/abigail/erlang/ch-2.erl @@ -0,0 +1,15 @@ +% +% See ../README.md +% + +% +% Run as: ln ch-2.erl ch2.erl +% erl -compile ch2 +% erl -noshell -s ch2 main -s init stop +% + +-module (ch2). +-export ([main/0]). + +main () -> + io:fwrite ("a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2\n"). diff --git a/challenge-118/abigail/forth/ch-2.fs b/challenge-118/abigail/forth/ch-2.fs new file mode 100644 index 0000000000..adf08a7137 --- /dev/null +++ b/challenge-118/abigail/forth/ch-2.fs @@ -0,0 +1,5 @@ +\ +\ See ../README.md +\ + +.( a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2) diff --git a/challenge-118/abigail/fortran/ch-2.f90 b/challenge-118/abigail/fortran/ch-2.f90 new file mode 100644 index 0000000000..bb8c2851b0 --- /dev/null +++ b/challenge-118/abigail/fortran/ch-2.f90 @@ -0,0 +1,12 @@ +! +! See ../README.md +! + +! +! Run as: gfortran -o ch-2.o ch-2.f90; ./ch-2.o +! + +program ch2 + implicit none + write (*, *) "a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2" +end diff --git a/challenge-118/abigail/go/ch-2.go b/challenge-118/abigail/go/ch-2.go new file mode 100644 index 0000000000..6fd5616aec --- /dev/null +++ b/challenge-118/abigail/go/ch-2.go @@ -0,0 +1,15 @@ +package main + +// +// See ../README.md +// + +// +// Run as: go run ch-2.go +// + +import "fmt" + +func main () { + fmt . Print ("a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2\n") +} diff --git a/challenge-118/abigail/java/ch-2.java b/challenge-118/abigail/java/ch-2.java new file mode 100644 index 0000000000..d9f0c4edcc --- /dev/null +++ b/challenge-118/abigail/java/ch-2.java @@ -0,0 +1,13 @@ +// +// See ../README.md +// + +// +// Run as: ln ch-2.java ch2.java; javac ch2; java ch2 +// + +public class ch2 { + public static void main (String [] args) { + System . out . print ("a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2\n"); + } +} diff --git a/challenge-118/abigail/lua/ch-2.lua b/challenge-118/abigail/lua/ch-2.lua new file mode 100644 index 0000000000..5c40dfc99c --- /dev/null +++ b/challenge-118/abigail/lua/ch-2.lua @@ -0,0 +1,11 @@ +#!/opt/local/bin/lua + +-- +-- See ../README.md +-- + +-- +-- Run as: lua ch-2.lua +-- + +print ("a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2") diff --git a/challenge-118/abigail/m4/ch-2.m4 b/challenge-118/abigail/m4/ch-2.m4 new file mode 100644 index 0000000000..6ebcee6dd2 --- /dev/null +++ b/challenge-118/abigail/m4/ch-2.m4 @@ -0,0 +1 @@ +a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2 diff --git a/challenge-118/abigail/mmix/ch-2.mms b/challenge-118/abigail/mmix/ch-2.mms new file mode 100644 index 0000000000..416ce1c81e --- /dev/null +++ b/challenge-118/abigail/mmix/ch-2.mms @@ -0,0 +1,16 @@ +% +% See ../README.md +% + +% +% Run as: mmixal -o ch-2.mmo ch-2.mms; mmix -q ch-2.mmo +% + LOC Data_Segment + GREG @ +Text BYTE "a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2",10,0 + + LOC #100 + +Main LDA $255,Text + TRAP 0,Fputs,StdOut + TRAP 0,Halt,0 diff --git a/challenge-118/abigail/node/ch-2.js b/challenge-118/abigail/node/ch-2.js new file mode 100644 index 0000000000..e032ef0448 --- /dev/null +++ b/challenge-118/abigail/node/ch-2.js @@ -0,0 +1,11 @@ +#!/usr/local/bin/node + +// +// See ../README.md +// + +// +// Run as: node ch-2.js +// + +console . log ("a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2") diff --git a/challenge-118/abigail/ocaml/ch-2.ml b/challenge-118/abigail/ocaml/ch-2.ml new file mode 100644 index 0000000000..553e3af70f --- /dev/null +++ b/challenge-118/abigail/ocaml/ch-2.ml @@ -0,0 +1,9 @@ +(* *) +(* See ../README.md *) +(* *) + +(* *) +(* Run as: ocaml ch-2.ml *) +(* *) + +print_endline "a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2"; diff --git a/challenge-118/abigail/pascal/ch-2.p b/challenge-118/abigail/pascal/ch-2.p new file mode 100644 index 0000000000..e95a839a4b --- /dev/null +++ b/challenge-118/abigail/pascal/ch-2.p @@ -0,0 +1,13 @@ +Program XXX; + +(* *) +(* See ../README.md *) +(* *) + +(* *) +(* Run as: fpc -och-1.out ch-2.p; ./ch-2.out *) +(* *) + +begin + writeln ('a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2') +end. diff --git a/challenge-118/abigail/php/ch-2.php b/challenge-118/abigail/php/ch-2.php new file mode 100644 index 0000000000..46cfeff6a7 --- /dev/null +++ b/challenge-118/abigail/php/ch-2.php @@ -0,0 +1,11 @@ + diff --git a/challenge-118/abigail/postscript/ch-2.ps b/challenge-118/abigail/postscript/ch-2.ps new file mode 100644 index 0000000000..97a3a77cd3 --- /dev/null +++ b/challenge-118/abigail/postscript/ch-2.ps @@ -0,0 +1,10 @@ +%!PS +% +% See ../README.md +% + +% +% Run as: ps2ascii ch-2.ps +% + +(a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2) = diff --git a/challenge-118/abigail/python/ch-2.py b/challenge-118/abigail/python/ch-2.py new file mode 100644 index 0000000000..12dd966554 --- /dev/null +++ b/challenge-118/abigail/python/ch-2.py @@ -0,0 +1,11 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-2.py +# + +print ("a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2") diff --git a/challenge-118/abigail/r/ch-2.r b/challenge-118/abigail/r/ch-2.r new file mode 100644 index 0000000000..b021f84006 --- /dev/null +++ b/challenge-118/abigail/r/ch-2.r @@ -0,0 +1,9 @@ +# +# See ../README.md +# + +# +# Run as: Rscript ch-2.r +# + +cat ("a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2\n") diff --git a/challenge-118/abigail/rexx/ch-2.rexx b/challenge-118/abigail/rexx/ch-2.rexx new file mode 100644 index 0000000000..f77556e087 --- /dev/null +++ b/challenge-118/abigail/rexx/ch-2.rexx @@ -0,0 +1,9 @@ +/* + * See ../README.md + */ + +/* + * Run as: rexx ch-2.rexx + */ + +say "a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2" diff --git a/challenge-118/abigail/ruby/ch-2.rb b/challenge-118/abigail/ruby/ch-2.rb new file mode 100644 index 0000000000..0a575319f9 --- /dev/null +++ b/challenge-118/abigail/ruby/ch-2.rb @@ -0,0 +1,11 @@ +#!/usr/bin/ruby + +# +# See ../README.md +# + +# +# Run as: ruby ch-2.rb +# + +puts ("a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2"); diff --git a/challenge-118/abigail/scheme/ch-2.scm b/challenge-118/abigail/scheme/ch-2.scm new file mode 100644 index 0000000000..def3bfb2b5 --- /dev/null +++ b/challenge-118/abigail/scheme/ch-2.scm @@ -0,0 +1,9 @@ +;;; +;;; See ../README.md +;;; + +;;; +;;; Run as: guile --no-auto-compile ch-2.scm +;;; + +(display "a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2\n") diff --git a/challenge-118/abigail/sed/ch-2.sed b/challenge-118/abigail/sed/ch-2.sed new file mode 100644 index 0000000000..e7d2004aa5 --- /dev/null +++ b/challenge-118/abigail/sed/ch-2.sed @@ -0,0 +1,12 @@ +# +# See ../README.md +# + +# +# Run as: sed -f ch-2.sed +# +# For each line in the input file, we write the first three +# self-describing numbers. +# + +s/.*/a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2/ diff --git a/challenge-118/abigail/sql/ch-2.sql b/challenge-118/abigail/sql/ch-2.sql new file mode 100644 index 0000000000..5ff02b7df8 --- /dev/null +++ b/challenge-118/abigail/sql/ch-2.sql @@ -0,0 +1,9 @@ +-- +-- See ../README.md +-- + +-- +-- Run as: sqlite3 < ch-2.sql +-- + +SELECT "a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2"; diff --git a/challenge-118/abigail/tcl/ch-2.tcl b/challenge-118/abigail/tcl/ch-2.tcl new file mode 100644 index 0000000000..f1e2f7b109 --- /dev/null +++ b/challenge-118/abigail/tcl/ch-2.tcl @@ -0,0 +1,9 @@ +# +# See ../README.md +# + +# +# Run as: tclsh ch-2.tcl +# + +puts "a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2" -- cgit From ed65f9e4f5f0e1200acedd279bcb6e52b4cecb2b Mon Sep 17 00:00:00 2001 From: Abigail Date: Tue, 22 Jun 2021 20:14:46 +0200 Subject: Don't give the SQL solution input --- challenge-118/abigail/t/ctest.ini | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/challenge-118/abigail/t/ctest.ini b/challenge-118/abigail/t/ctest.ini index d1a3f6baf6..261644e4f1 100644 --- a/challenge-118/abigail/t/ctest.ini +++ b/challenge-118/abigail/t/ctest.ini @@ -5,3 +5,7 @@ [names] 1-1 = Given Examples +2-1 = Given Example + +[2-1/sql] +no_input = 1 -- cgit From 77b6a08e8eeec92b2547029d2777e5cd968d2b45 Mon Sep 17 00:00:00 2001 From: Tyler Wardhaugh Date: Sat, 26 Jun 2021 10:28:58 -0700 Subject: Ch118: prep for challenge --- challenge-118/tyler-wardhaugh/clojure/README.md | 14 +++++++------- challenge-118/tyler-wardhaugh/clojure/bb.edn | 4 +--- challenge-118/tyler-wardhaugh/clojure/deps.edn | 3 +-- challenge-118/tyler-wardhaugh/clojure/pom.xml | 13 ++++--------- .../clojure/src/tw/weekly/c118/core.clj | 12 ++++++++++++ .../tyler-wardhaugh/clojure/src/tw/weekly/c118/t1.clj | 18 ++++++++++++++++++ .../tyler-wardhaugh/clojure/src/tw/weekly/c118/t2.clj | 15 +++++++++++++++ .../clojure/test/tw/weekly/c118_test.clj | 12 ++++++++++++ 8 files changed, 70 insertions(+), 21 deletions(-) create mode 100644 challenge-118/tyler-wardhaugh/clojure/src/tw/weekly/c118/core.clj create mode 100644 challenge-118/tyler-wardhaugh/clojure/src/tw/weekly/c118/t1.clj create mode 100644 challenge-118/tyler-wardhaugh/clojure/src/tw/weekly/c118/t2.clj create mode 100644 challenge-118/tyler-wardhaugh/clojure/test/tw/weekly/c118_test.clj diff --git a/challenge-118/tyler-wardhaugh/clojure/README.md b/challenge-118/tyler-wardhaugh/clojure/README.md index 46dde45ce4..de2edc3f59 100644 --- a/challenge-118/tyler-wardhaugh/clojure/README.md +++ b/challenge-118/tyler-wardhaugh/clojure/README.md @@ -1,7 +1,7 @@ -# tw.weekly.c117 +# tw.weekly.c118 -The Weekly Challenge - #117 - Tyler Wardhaugh +The Weekly Challenge - #118 - Tyler Wardhaugh ## Usage @@ -9,7 +9,7 @@ Clojure ([installation instructions](https://clojure.org/guides/getting_started# Run the project directly (shows default output from both tasks): - $ clojure -M -m tw.weekly.c117.core + $ clojure -M -m tw.weekly.c118.core # ... or ... $ bb run both @@ -21,15 +21,15 @@ Run the project's tests (which are samples from the task descriptions): Run Task #1 with input - $ clojure -M -m tw.weekly.c117.t1 FILE + $ clojure -M -m tw.weekly.c118.t1 N # ... or ... - $ bb run task-1 FILE + $ bb run task-1 N Run Task #2 with input: - $ clojure -M -m tw.weekly.c117.t2 N + $ clojure -M -m tw.weekly.c118.t2 # ... or ... - $ bb run task-2 N + $ bb run task-2 ## Project Template diff --git a/challenge-118/tyler-wardhaugh/clojure/bb.edn b/challenge-118/tyler-wardhaugh/clojure/bb.edn index 0409645368..d6814eab4a 100644 --- a/challenge-118/tyler-wardhaugh/clojure/bb.edn +++ b/challenge-118/tyler-wardhaugh/clojure/bb.edn @@ -63,9 +63,7 @@ :task (run-task :t1 *command-line-args*)} task-1-bb {:doc "Run Task 1 (via Babashka)" - :task (binding [*out* *err*] - (println "error: can't run Task 1 via Babashka because it depends on an incompatible library.") - (System/exit 1))} + :task (run-task-bb :t1 *command-line-args*)} task-2 {:doc "Run Task 2 (via clojure)" :task (run-task :t2 *command-line-args*)} diff --git a/challenge-118/tyler-wardhaugh/clojure/deps.edn b/challenge-118/tyler-wardhaugh/clojure/deps.edn index b971f3081f..803cdffd33 100644 --- a/challenge-118/tyler-wardhaugh/clojure/deps.edn +++ b/challenge-118/tyler-wardhaugh/clojure/deps.edn @@ -1,6 +1,5 @@ {:paths ["src" "resources"] - :deps {org.clojure/clojure {:mvn/version "1.10.3"} - net.cgrand/xforms {:mvn/version "0.19.2"}} + :deps {org.clojure/clojure {:mvn/version "1.10.3"}} :aliases {:test {:extra-paths ["test"] diff --git a/challenge-118/tyler-wardhaugh/clojure/pom.xml b/challenge-118/tyler-wardhaugh/clojure/pom.xml index ed74b5497a..ca25679f9e 100644 --- a/challenge-118/tyler-wardhaugh/clojure/pom.xml +++ b/challenge-118/tyler-wardhaugh/clojure/pom.xml @@ -2,11 +2,11 @@ 4.0.0 tw.weekly - tw.weekly.c117 + tw.weekly.c118 0.1.0-SNAPSHOT - tw.weekly.c117 - Challenge #117 - https://github.com/tw.weekly/tw.weekly.c117 + tw.weekly.c118 + Challenge #118 + https://github.com/tw.weekly/tw.weekly.c118 Eclipse Public License @@ -24,11 +24,6 @@ clojure 1.10.3 - - net.cgrand - xforms - 0.19.2 - src diff --git a/challenge-118/tyler-wardhaugh/clojure/src/tw/weekly/c118/core.clj b/challenge-118/tyler-wardhaugh/clojure/src/tw/weekly/c118/core.clj new file mode 100644 index 0000000000..a138d86127 --- /dev/null +++ b/challenge-118/tyler-wardhaugh/clojure/src/tw/weekly/c118/core.clj @@ -0,0 +1,12 @@ +(ns tw.weekly.c118.core + (:require [tw.weekly.c118.t1 :as t1]) + (:require [tw.weekly.c118.t2 :as t2]) + (:gen-class)) + +(defn -main + "Run all tasks" + [& _] + (println "Task #1:") + (t1/-main) + (println "\nTask #2:") + (t2/-main)) diff --git a/challenge-118/tyler-wardhaugh/clojure/src/tw/weekly/c118/t1.clj b/challenge-118/tyler-wardhaugh/clojure/src/tw/weekly/c118/t1.clj new file mode 100644 index 0000000000..d5f2bdb703 --- /dev/null +++ b/challenge-118/tyler-wardhaugh/clojure/src/tw/weekly/c118/t1.clj @@ -0,0 +1,18 @@ +(ns tw.weekly.c118.t1 + (:require [clojure.edn :as edn])) + +;;; +; Task description for TASK #1 › Binary Palindrom +;;; +(def DEFAULT-INPUT [5]) + +(defn binary-palindrome + "" + [n]) + +(defn -main + "Run Task 1 with a given input N, defaulting to the first example from the + task description." + [& args] + (let [[N] (or (some->> args (map edn/read-string)) DEFAULT-INPUT)] + (println (if (binary-palindrome N) 1 0)))) diff --git a/challenge-118/tyler-wardhaugh/clojure/src/tw/weekly/c118/t2.clj b/challenge-118/tyler-wardhaugh/clojure/src/tw/weekly/c118/t2.clj new file mode 100644 index 0000000000..a9d990ccd5 --- /dev/null +++ b/challenge-118/tyler-wardhaugh/clojure/src/tw/weekly/c118/t2.clj @@ -0,0 +1,15 @@ +(ns tw.weekly.c118.t2 + (:require [clojure.edn :as edn] + [clojure.pprint :refer [cl-format]])) + +;;; +; Task description for TASK #2 › Adventure of Knight +;;; +(def DEFAULT-INPUT []) + +(defn -main + "Run Task 2 with a given input N, defaulting to the first example from the + task description." + [& args] + (let [[N] (or (some->> args (map edn/read-string)) DEFAULT-INPUT)] + )) diff --git a/challenge-118/tyler-wardhaugh/clojure/test/tw/weekly/c118_test.clj b/challenge-118/tyler-wardhaugh/clojure/test/tw/weekly/c118_test.clj new file mode 100644 index 0000000000..999b044703 --- /dev/null +++ b/challenge-118/tyler-wardhaugh/clojure/test/tw/weekly/c118_test.clj @@ -0,0 +1,12 @@ +(ns tw.weekly.c118-test + (:require [clojure.test :refer [deftest is testing]] + #_[tw.weekly.c118.t1 :refer []] + #_[tw.weekly.c118.t2 :refer []])) + +(deftest task-1 + (testing "Task 1, Binary Palindrom" + )) + +(deftest task-2 + (testing "Task 2, Adventure of Knight" + )) -- cgit From 1e4f18c8552dec891946162593a2bd451f8ca30b Mon Sep 17 00:00:00 2001 From: Abigail Date: Sat, 26 Jun 2021 20:00:58 +0200 Subject: Swap clauses in pattern --- challenge-118/abigail/perl/ch-1.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/challenge-118/abigail/perl/ch-1.pl b/challenge-118/abigail/perl/ch-1.pl index 99df6f0f65..51892d3f65 100644 --- a/challenge-118/abigail/perl/ch-1.pl +++ b/challenge-118/abigail/perl/ch-1.pl @@ -23,4 +23,4 @@ use experimental 'lexical_subs'; # using a pattern turns it into a one liner. # -say sprintf ("%b" => $_) =~ /^(([01])(?1)\g{2}|[01]?)$/ || 0 while <>; +say sprintf ("%b" => $_) =~ /^([01]?|([01])(?1)\g{2})$/ || 0 while <>; -- cgit From 1abf08f81e712055017a65304d8e1be6d7d62c6b Mon Sep 17 00:00:00 2001 From: Tyler Wardhaugh Date: Sat, 26 Jun 2021 11:28:52 -0700 Subject: Ch118 (Clojure): Task 1 --- .../tyler-wardhaugh/clojure/src/tw/weekly/c118/t1.clj | 14 +++++++++++--- .../tyler-wardhaugh/clojure/test/tw/weekly/c118_test.clj | 5 +++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/challenge-118/tyler-wardhaugh/clojure/src/tw/weekly/c118/t1.clj b/challenge-118/tyler-wardhaugh/clojure/src/tw/weekly/c118/t1.clj index d5f2bdb703..4b8f62cdb3 100644 --- a/challenge-118/tyler-wardhaugh/clojure/src/tw/weekly/c118/t1.clj +++ b/challenge-118/tyler-wardhaugh/clojure/src/tw/weekly/c118/t1.clj @@ -1,14 +1,22 @@ (ns tw.weekly.c118.t1 - (:require [clojure.edn :as edn])) + (:require [clojure.edn :as edn] + [clojure.string :as str])) ;;; ; Task description for TASK #1 › Binary Palindrom ;;; (def DEFAULT-INPUT [5]) +(defn bin-parse + "Parse a string as a binary representation of an integer." + [s] + (Integer/parseInt s 2)) + (defn binary-palindrome - "" - [n]) + "Determine if the binary representation of an integer is a palindrome." + [n] + (let [rev (-> n Integer/toBinaryString str/reverse bin-parse)] + (zero? (bit-xor n rev)))) (defn -main "Run Task 1 with a given input N, defaulting to the first example from the diff --git a/challenge-118/tyler-wardhaugh/clojure/test/tw/weekly/c118_test.clj b/challenge-118/tyler-wardhaugh/clojure/test/tw/weekly/c118_test.clj index 999b044703..e827c5a801 100644 --- a/challenge-118/tyler-wardhaugh/clojure/test/tw/weekly/c118_test.clj +++ b/challenge-118/tyler-wardhaugh/clojure/test/tw/weekly/c118_test.clj @@ -1,11 +1,12 @@ (ns tw.weekly.c118-test (:require [clojure.test :refer [deftest is testing]] - #_[tw.weekly.c118.t1 :refer []] + [tw.weekly.c118.t1 :refer [binary-palindrome]] #_[tw.weekly.c118.t2 :refer []])) (deftest task-1 (testing "Task 1, Binary Palindrom" - )) + (is (true? (binary-palindrome 5))) + (is (false? (binary-palindrome 4))))) (deftest task-2 (testing "Task 2, Adventure of Knight" -- cgit From 0d0d5481ca9a3f18403eb433a8b00df549892773 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Sat, 26 Jun 2021 22:33:01 +0100 Subject: - Added solutions by Arne Sommer. --- challenge-118/arne-sommer/blog.txt | 1 + challenge-118/arne-sommer/perl/ch-1.pl | 20 + challenge-118/arne-sommer/raku/ch-1.raku | 9 + challenge-118/arne-sommer/raku/ch-2.raku | 62 + stats/pwc-current.json | 353 ++- stats/pwc-language-breakdown-summary.json | 82 +- stats/pwc-language-breakdown.json | 4710 ++++++++++++++--------------- stats/pwc-leaders.json | 380 +-- stats/pwc-summary-1-30.json | 44 +- stats/pwc-summary-121-150.json | 106 +- stats/pwc-summary-151-180.json | 98 +- stats/pwc-summary-181-210.json | 84 +- stats/pwc-summary-211-240.json | 40 +- stats/pwc-summary-31-60.json | 34 +- stats/pwc-summary-61-90.json | 32 +- stats/pwc-summary-91-120.json | 102 +- stats/pwc-summary.json | 484 +-- 17 files changed, 3378 insertions(+), 3263 deletions(-) create mode 100644 challenge-118/arne-sommer/blog.txt create mode 100644 challenge-118/arne-sommer/perl/ch-1.pl create mode 100644 challenge-118/arne-sommer/raku/ch-1.raku create mode 100644 challenge-118/arne-sommer/raku/ch-2.raku diff --git a/challenge-118/arne-sommer/blog.txt b/challenge-118/arne-sommer/blog.txt new file mode 100644 index 0000000000..f3efbb4875 --- /dev/null +++ b/challenge-118/arne-sommer/blog.txt @@ -0,0 +1 @@ +https://raku-musings.com/binary-knight.html diff --git a/challenge-118/arne-sommer/perl/ch-1.pl b/challenge-118/arne-sommer/perl/ch-1.pl new file mode 100644 index 0000000000..1f64526fab --- /dev/null +++ b/challenge-118/arne-sommer/perl/ch-1.pl @@ -0,0 +1,20 @@ +#! /usr/bin/env perl + +use strict; +use warnings; +use feature 'say'; + +use Getopt::Long; +my $verbose = 0; + +GetOptions("verbose" => \$verbose); + +my $N = shift(@ARGV); + +die "Specify a positive integer" unless $N =~ /^[1-9]\d*$/; + +my $bin = sprintf('%b', $N); + +say ": $bin (binary)\n: " . reverse($bin) . " (binary flipped)" if $verbose; + +say 0 + ($bin eq reverse($bin)); \ No newline at end of file diff --git a/challenge-118/arne-sommer/raku/ch-1.raku b/challenge-118/arne-sommer/raku/ch-1.raku new file mode 100644 index 0000000000..1daa749dca --- /dev/null +++ b/challenge-118/arne-sommer/raku/ch-1.raku @@ -0,0 +1,9 @@ +#! /usr/bin/env raku + +unit sub MAIN (Int $N where $N > 0, :v($verbose)); + +my $bin = $N.fmt('%b'); + +say ": $bin (binary)\n: { $bin.flip } (binary flipped)" if $verbose; + +say + ($bin eq $bin.flip); \ No newline at end of file diff --git a/challenge-118/arne-sommer/raku/ch-2.raku b/challenge-118/arne-sommer/raku/ch-2.raku new file mode 100644 index 0000000000..9d8b8fac0d --- /dev/null +++ b/challenge-118/arne-sommer/raku/ch-2.raku @@ -0,0 +1,62 @@ +#! /usr/bin/env raku + +subset ChessPos of Str where + $_.chars == 2 && + $_.substr(0,1) ~~ /<[abcdefgh]>/ && + $_.substr(1,1) ~~ /<[12345678]>/; + +unit sub MAIN (ChessPos $pos = 'a8', :v($verbose)); + +my ($col, $row) = $pos.comb; + +my %treasures = ('e6' => True, 'c4' => True, 'b3' => True, + 'a2' => True, 'b2' => True, 'b1' => True); + +my %visited = ('a8' => True); + +my @todo = ( ('a8', 'a8', {%visited}, {%treasures}), ); + +while @todo +{ + my $next = @todo.shift; + my ($pos, $path, $visited, $treasures) = @($next); + my %visited = %($visited); + my %treasures = %($treasures); + + for get-next($pos) -> $next + { + say ": Checking pos: $next (at path \'$path\') with { %visited.elems } visits and { %treasures.elems } remaining treasures" if $verbose; + next if %visited{$next}; + + if %treasures{$next} + { + if %treasures.elems == 1 + { + say "Path: $path $next"; + exit; + } + + %treasures{$next}:delete; + } + %visited{$next} = True; + @todo.push: ($next, "$path $next", {%visited}, {%treasures}); + } +} + +sub get-next ($pos) +{ + my ($col, $row) = $pos.comb; + + my @next = ( + "{ ($col.ord - 2).chr }{ $row - 1 }", # LLD + "{ ($col.ord - 2).chr }{ $row + 1 }", # LLU + "{ ($col.ord - 1).chr }{ $row - 2 }", # LDD + "{ ($col.ord - 1).chr }{ $row + 2 }", # LUU + "{ ($col.ord + 1).chr }{ $row - 2 }", # RDD + "{ ($col.ord + 1).chr }{ $row + 2 }", # RUU + "{ ($col.ord + 2).chr }{ $row - 1 }", # RRD + "{ ($col.ord + 2).chr }{ $row + 1 }", # RRU + ).grep( * ~~ ChessPos); + + return @next; +} \ No newline at end of file diff --git a/stats/pwc-current.json b/stats/pwc-current.json index 2c371cd18c..bbd9b84f8a 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,21 +1,174 @@ { + "plotOptions" : { + "series" : { + "borderWidth" : 0, + "dataLabels" : { + "enabled" : 1, + "format" : "{point.y}" + } + } + }, + "subtitle" : { + "text" : "[Champions: 21] Last updated at 2021-06-26 21:27:51 GMT" + }, "title" : { "text" : "Perl Weekly Challenge - 118" }, + "chart" : { + "type" : "column" + }, + "tooltip" : { + "headerFormat" : "{series.name}
", + "followPointer" : 1, + "pointFormat" : "{point.name}: {point.y:f}
" + }, + "xAxis" : { + "type" : "category" + }, + "series" : [ + { + "colorByPoint" : 1, + "data" : [ + { + "y" : 4, + "drilldown" : "Arne Sommer", + "name" : "Arne Sommer" + }, + { + "drilldown" : "Cheok-Yin Fung", + "y" : 2, + "name" : "Cheok-Yin Fung" + }, + { + "name" : "Dave Jacoby", + "y" : 3, + "drilldown" : "Dave Jacoby" + }, + { + "name" : "Duane Powell", + "y" : 2, + "drilldown" : "Duane Powell" + }, + { + "name" : "E. Choroba", + "drilldown" : "E. Choroba", + "y" : 2 + }, + { + "name" : "Flavio Poletti", + "y" : 6, + "drilldown" : "Flavio Poletti" + }, + { + "y" : 3, + "drilldown" : "James Smith", + "name" : "James Smith" + }, + { + "name" : "Jorg Sommrey", + "y" : 2, + "drilldown" : "Jorg Sommrey" + }, + { + "name" : "Lance Wicks", + "drilldown" : "Lance Wicks", + "y" : 3 + }, + { + "name" : "Laurent Rosenfeld", + "drilldown" : "Laurent Rosenfeld", + "y" : 3 + }, + { + "name" : "Lucas Ransan", + "drilldown" : "Lucas Ransan", + "y" : 2 + }, + { + "name" : "Mohammad S Anwar", + "drilldown" : "Mohammad S Anwar", + "y" : 1 + }, + { + "name" : "Niels van Dijke", + "y" : 1, + "drilldown" : "Niels van Dijke" + }, + { + "drilldown" : "Paulo Custodio", + "y" : 2, + "name" : "Paulo Custodio" + }, + { + "y" : 2, + "drilldown" : "Pete Houston", + "name" : "Pete Houston" + }, + { + "y" : 4, + "drilldown" : "Roger Bell_West", + "name" : "Roger Bell_West" + }, + { + "y" : 3, + "drilldown" : "Simon Green", + "name" : "Simon Green" + }, + { + "drilldown" : "Steven Wilson", + "y" : 1, + "name" : "Steven Wilson" + }, + { + "y" : 4, + "drilldown" : "Stuart Little", + "name" : "Stuart Little" + }, + { + "name" : "Vinod Kumar K", + "drilldown" : "Vinod Kumar K", + "y" : 1 + }, + { + "y" : 3, + "drilldown" : "W. Luis Mochan", + "name" : "W. Luis Mochan" + } + ], + "name" : "Perl Weekly Challenge - 118" + } + ], "drilldown" : { "series" : [ { - "id" : "Cheok-Yin Fung", + "data" : [ + [ + "Perl", + 1 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "name" : "Arne Sommer", + "id" : "Arne Sommer" + }, + { "data" : [ [ "Perl", 2 ] ], - "name" : "Cheok-Yin Fung" + "name" : "Cheok-Yin Fung", + "id" : "Cheok-Yin Fung" }, { - "id" : "Dave Jacoby", "name" : "Dave Jacoby", "data" : [ [ @@ -26,31 +179,31 @@ "Blog", 1 ] - ] + ], + "id" : "Dave Jacoby" }, { - "name" : "Duane Powell", + "id" : "Duane Powell", "data" : [ [ "Perl", 2 ] ], - "id" : "Duane Powell" + "name" : "Duane Powell" }, { "id" : "E. Choroba", - "name" : "E. Choroba", "data" : [ [ "Perl", 2 ] - ] + ], + "name" : "E. Choroba" }, { "id" : "Flavio Poletti", - "name" : "Flavio Poletti", "data" : [ [ "Perl", @@ -64,9 +217,11 @@ "Blog", 2 ] - ] + ], + "name" : "Flavio Poletti" }, { + "id" : "James Smith", "data" : [ [ "Perl", @@ -77,18 +232,17 @@ 1 ] ], - "name" : "James Smith", - "id" : "James Smith" + "name" : "James Smith" }, { + "id" : "Jorg Sommrey", "name" : "Jorg Sommrey", "data" : [ [ "Perl", 2 ] - ], - "id" : "Jorg Sommrey" + ] }, { "name" : "Lance Wicks", @@ -105,6 +259,7 @@ "id" : "Lance Wicks" }, { + "id" : "Laurent Rosenfeld", "data" : [ [ "Perl", @@ -119,18 +274,17 @@ 1 ] ], - "name" : "Laurent Rosenfeld", - "id" : "Laurent Rosenfeld" + "name" : "Laurent Rosenfeld" }, { "id" : "Lucas Ransan", + "name" : "Lucas Ransan", "data" : [ [ "Raku", 2 ] - ], - "name" : "Lucas Ransan" + ] }, { "id" : "Mohammad S Anwar", @@ -143,34 +297,34 @@ "name" : "Mohammad S Anwar" }, { - "id" : "Niels van Dijke", "data" : [ [ "Perl", 1 ] ], - "name" : "Niels van Dijke" + "name" : "Niels van Dijke", + "id" : "Niels van Dijke" }, { - "id" : "Paulo Custodio", - "name" : "Paulo Custodio", "data" : [ [ "Perl", 2 ] - ] + ], + "name" : "Paulo Custodio", + "id" : "Paulo Custodio" }, { - "id" : "Pete Houston", "data" : [ [ "Perl", 2 ] ], - "name" : "Pete Houston" + "name" : "Pete Houston", + "id" : "Pete Houston" }, { "id" : "Roger Bell_West", @@ -191,7 +345,6 @@ "name" : "Roger Bell_West"