From 2fab5d67cc491f62388de15a89794816607a2b76 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 30 Nov 2020 12:22:54 +0100 Subject: Copy test file from previous week, and deal with no-input programs. --- challenge-089/abigail/test.pl | 289 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 289 insertions(+) create mode 100755 challenge-089/abigail/test.pl diff --git a/challenge-089/abigail/test.pl b/challenge-089/abigail/test.pl new file mode 100755 index 0000000000..5f6950ed3c --- /dev/null +++ b/challenge-089/abigail/test.pl @@ -0,0 +1,289 @@ +#!/opt/perl/bin/perl + +# +# Test the solutions. Either call it with the directory name you +# want to test in, or call it as "../test.pl" from within the directory. +# + +use 5.032; + +use strict; +use warnings; +no warnings 'syntax'; + +chdir ".." if -f "../test.pl"; + +use experimental 'signatures'; + +use Test::More; +use DBI; + +use Getopt::Long; + +GetOptions 'slow' => \my $run_slow_tests, + 'lang|language=s' => \my @languages, +; + + +my %languages = ( + Perl => { + exe => "/opt/perl/bin/perl", + ext => "pl", + }, + JavaScript => { + exe => "/usr/local/bin/node", + ext => "js", + dir => "node", + }, + bc => { + exe => "/usr/bin/bc", + ext => "bc", + filter => 's/.*/main($&)/', + }, + awk => { + exe => "/usr/bin/awk", + ext => "awk", + args => ["-f"], + }, + C => { + exe => "/usr/bin/cc", + ext => "c", + dir => "c", + }, + SQL => { + ext => "sql", + }, +); + +my $perl_exe = $languages {Perl} {exe}; + +@languages = sort keys %languages if !@languages; +my @challenges = @ARGV ? @ARGV : (1, 2); + +foreach my $challenge (@challenges) { + my ($dbh, $query, $tables_info); # Only for SQL tests. + + my @outputs = or next; + subtest "Challenge $challenge" => sub { + foreach my $language (@languages) { + my $info = $languages {$language}; + my $exe = $$info {exe}; + my $ext = $$info {ext}; + my $dir = $$info {dir} // lc $language; + my @args = @{$$info {args} // []}; + my $filter = $$info {filter} // ''; + my $ext_out = $$info {ext_out} // "out"; + my $source = "$dir/ch-$challenge.$ext"; + my $compiled; + next unless -r $source; + + # + # C requires special handling. The source needs to be compiled. + # + if ($language eq "C") { + $compiled = $source =~ s/\.$ext$/.$ext_out/r; + system $exe, "-o", $compiled, $source; + } + + # + # SQL requires requires creating an in-memory database, + # and loading some tables. For that, we need a .tables + # file. We also read the actual query at this time. + # + if ($language eq "SQL") { + my $tables = $source =~ s/\.\Q$ext\E$/.table/r; + ($dbh, $query, $tables_info) = init_sql ($source, $tables); + } + + subtest $language => sub { + foreach my $output_exp (@outputs) { + SKIP: { + my $input = $output_exp =~ s/output/input/r + =~ s/\.exp$//r; + my $exp = `cat $output_exp`; + + my $name = $input; + + if (!-f $input) { + $name = "No input"; + $input = "/dev/null"; + } + + my %pragma; + my @options; + + while ($exp =~ s/^\s*#%\s*(.*)\n//) { + my $pragma = $1; + $pragma =~ s/\s+$//; + if (lc $pragma eq "slow") { + $pragma {slow} = 1; + next; + } + if ($pragma =~ /^\s*(\w+):\s*(.*)/) { + my ($key, $value) = ($1, $2); + if (lc $key eq "opt") { + push @options => $value; + } + } + } + + if ($exp =~ s/^\s*#\s*(.*)\n//) { + $name = $1; + } + + skip "Skipping slow test", 1 + if $pragma {slow} && !$run_slow_tests; + + my $got; + if ($compiled) { + $got = `$perl_exe -ple '$filter' $input |\ + ./$compiled @options`; + } + elsif ($language eq "SQL") { + $got = test_sql ($dbh, $query, $tables_info, $input); + } + else { + $got = `$perl_exe -ple '$filter' $input |\ + $exe @args ./$source @options`; + } + + s/\h+$//gm for $exp, $got; + is $got, $exp, $name; + }} + }; + + unlink $compiled if $compiled; + } + } +} + +done_testing; + +# +# Parse the tables SQL, extract the table names, and the column names, +# *EXCLUDING* any primary key of the form "integer PRIMARY KEY" +# We're assuming some sane formatting (one column per line). +# +# Returns an array of arrays. Each (inner) array consists of a table +# name, followed by the name of the columns of that table. +# +# We will also create the database handle, use it to create the tables, +# and return the database handle as a second value. +# +sub init_sql ($query_file, $tables_file) { + my $query = `cat $query_file`; + my $tables = -f $tables_file ? `cat $tables_file` : ""; + + my $in_table = 0; + my @info; + foreach (split /\n/ => $tables) { + if (!$in_table) { + if (/^\s* CREATE \s+ TABLE \s+ (\w+)/xi) { + $in_table = 1; + push @info => [$1]; + } + next; + } + else { + if (/^\s* \)/x) { + $in_table = 0; + next; + } + # Any other line is a column definition + next if /^ \s* \w+ \s+ integer \s+ PRIMARY \s+ KEY \s*,/xi; + if (/^ \s* (\w+)/x) { + push @{$info [-1]} => $1; + } + } + } + # + # Does the query have place holders? + # + if ($query =~ /\?/) { + push @info => ["Placeholder"]; + } + + my $dbh = DBI:: -> connect ("dbi:SQLite:dbname=:memory:", "", "", + {RaiseError => 1, + PrintError => 1, + AutoCommit => 1}); + $dbh -> do ($tables) if $tables; + + return ($dbh, $query, \@info); +} + + +sub test_sql ($dbh, $query, $tables_info, $input) { + # + # For now, assume we each set of N lines, where N is the number of tables + # is a test. We also assume that if a line has P items (space separated), + # and the corresponing table has Q columns (not counting any integer primary + # keys, as SQLite fills them automatically), we have to fill int (P/Q) rows. + # + + # + # Read the input, if any + # + my @input; + if (-f $input) { + open my $i_fh, "<", $input or die "Failed to open $input: $!"; + @input = <$i_fh>; + } + + my $output = ""; + + TEST: + while (@input >= @$tables_info) { + my $real_query = $query; + foreach my $table_info (@$tables_info) { + my ($table, @fields) = @$table_info; + my $input = shift @input; + my @values = split ' ' => $input; + last TEST if @values < @fields && $table ne "Placeholder"; + + # + # Handle place holder queries + # + if ($table eq "Placeholder") { + $real_query =~ s/\?/shift @values/eg; + next; + } + + # + # Clear the table + # + $dbh -> do ("DELETE FROM $table"); + + # + # Construct an input query + # + my $place = "(" . join (", " => ("?") x @fields) . ")"; + my $insert = do {local $" = ", "; <<~ "--"}; + INSERT + INTO $table + (@fields) + VALUES @{[($place) x (@values / @fields)]} + -- + + $dbh -> do ($insert, undef, @values); + } + + + # + # Run the query. If we have multiple results, join columns + # by spaces, and rows by newlines. + # + my $result = $dbh -> selectall_arrayref ($real_query); + + $output .= join "\n" => map {join " " => @$_} @$result; + $output .= "\n"; + last unless @input; + } + + $output; +} + + + + +__END__ -- cgit From 520908f8d0d782ccacbc7236cac153f8dbec4ef1 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 30 Nov 2020 13:40:44 +0100 Subject: Perl solution for week 89/part 2 --- challenge-089/abigail/perl/ch-2.pl | 74 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 challenge-089/abigail/perl/ch-2.pl diff --git a/challenge-089/abigail/perl/ch-2.pl b/challenge-089/abigail/perl/ch-2.pl new file mode 100644 index 0000000000..f23979079e --- /dev/null +++ b/challenge-089/abigail/perl/ch-2.pl @@ -0,0 +1,74 @@ +#!/opt/perl/bin/perl + +use 5.032; + +use strict; +use warnings; +no warnings 'syntax'; + +use experimental 'signatures'; +use experimental 'lexical_subs'; + +# +# Challenge +# +# Write a script to display matrix as below with numbers 1 - 9. +# Please make sure numbers are used once. +# +# [ a b c ] +# [ d e f ] +# [ g h i ] +# +# So that it satisfies the following: +# +# a + b + c = 15 +# d + e + f = 15 +# g + h + i = 15 +# a + d + g = 15 +# b + e + h = 15 +# c + f + i = 15 +# a + e + i = 15 +# c + e + g = 15 +# + +# +# Well, this is utter trival, and there is absolute nothing to +# calculate. +# +# There is only one 3x3 matrix, 8 if you count rotations +# and reflections. +# +# For those who don't know the 3x3 magic square since childhood, +# and who don't look it up on the internet: +# +# - You need an odd number of odd numbers to sum to 15, so each +# row, column or diagonal contain 0 or 2 even numbers. +# - There are 5 odd numbers in the range 1-9, and 4 even numbers. +# - Hence, all the corners contain even numbers, the rest are odd. +# - This means, there are 2 triples with all odd numbers; together +# they contain all the odd numbers, and one odd number (the one +# in the center) is part of both. +# - The only all odd triplet containing a 9 which sums to 15 is +# (9, 5, 1). Which means the other triplet must contain a 7 and a 3, +# and to have that sum to 15, a 5 as well. Which means, 5 is in +# the center. +# - Now we can pick any even number (one of four) and place it in a corner. +# This fixes the number in the opposite corner. We then place the remaining +# two even numbers in the remaining corners (either possibility works). +# - There is now one way to place the remaining four odd numbers. +# +# This leads to the following solutions (all the others can be +# obtained by rotations and reflections): +# +# 8 1 6 +# 3 5 7 +# 4 9 2 +# + +print << '--'; +8 1 6 +3 5 7 +4 9 2 +-- + +__END__ -- cgit From 0314a093c37a51601725898920477cbdefedeff9 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 30 Nov 2020 13:44:31 +0100 Subject: C solution for week 89/part 2 --- challenge-089/abigail/c/ch-2.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 challenge-089/abigail/c/ch-2.c diff --git a/challenge-089/abigail/c/ch-2.c b/challenge-089/abigail/c/ch-2.c new file mode 100644 index 0000000000..a3fed75423 --- /dev/null +++ b/challenge-089/abigail/c/ch-2.c @@ -0,0 +1,13 @@ +# include +# include + +/* + * See ../perl/ch-2.pl for challenge and notes + */ + +int main (void) { + printf ("8 1 6\n"); + printf ("3 5 7\n"); + printf ("4 9 2\n"); + return (0); +} -- cgit From ac8d5ef269002a40b6e1dfa931bc73b601a438a3 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 30 Nov 2020 13:48:33 +0100 Subject: Node.js solution for week 89/part 2 --- challenge-089/abigail/node/ch-2.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 challenge-089/abigail/node/ch-2.js diff --git a/challenge-089/abigail/node/ch-2.js b/challenge-089/abigail/node/ch-2.js new file mode 100644 index 0000000000..ddc63f0b6e --- /dev/null +++ b/challenge-089/abigail/node/ch-2.js @@ -0,0 +1,7 @@ +// +// For challenge and notes, see ../perl/ch-2.pl +// + +process . stdout . write ("8 1 6\n" + + "3 5 7\n" + + "4 9 2\n"); -- cgit From f57745d7d001edf53bbbe4cd7996a8d7891dba3b Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 30 Nov 2020 14:21:41 +0100 Subject: Deal with compound SQL statements. --- challenge-089/abigail/test.pl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/challenge-089/abigail/test.pl b/challenge-089/abigail/test.pl index 5f6950ed3c..5b9279313a 100755 --- a/challenge-089/abigail/test.pl +++ b/challenge-089/abigail/test.pl @@ -273,10 +273,12 @@ sub test_sql ($dbh, $query, $tables_info, $input) { # Run the query. If we have multiple results, join columns # by spaces, and rows by newlines. # - my $result = $dbh -> selectall_arrayref ($real_query); + foreach my $query (split /^\s*;\s*$/m => $real_query) { + my $result = $dbh -> selectall_arrayref ($query); + $output .= join "\n" => map {join " " => @$_} @$result; + $output .= "\n"; + } - $output .= join "\n" => map {join " " => @$_} @$result; - $output .= "\n"; last unless @input; } -- cgit From 2eb5915064d9a6c22be678d45fb4f5f592b678b9 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 30 Nov 2020 14:35:43 +0100 Subject: SQL solution for week 89/part 2 --- challenge-089/abigail/sql/ch-2.sql | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 challenge-089/abigail/sql/ch-2.sql diff --git a/challenge-089/abigail/sql/ch-2.sql b/challenge-089/abigail/sql/ch-2.sql new file mode 100644 index 0000000000..8b4cad84e6 --- /dev/null +++ b/challenge-089/abigail/sql/ch-2.sql @@ -0,0 +1,5 @@ +SELECT '8 1 6' +; +SELECT '3 5 7' +; +SELECT '4 9 2' -- cgit From c6aa28238ea453e68b0c17a428e5558b4d9b6d3d Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 30 Nov 2020 14:43:26 +0100 Subject: Befunge-93 solution for week 89/part 2 --- challenge-089/abigail/befunge-93/ch-2.bf | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 challenge-089/abigail/befunge-93/ch-2.bf diff --git a/challenge-089/abigail/befunge-93/ch-2.bf b/challenge-089/abigail/befunge-93/ch-2.bf new file mode 100644 index 0000000000..5a308181ff --- /dev/null +++ b/challenge-089/abigail/befunge-93/ch-2.bf @@ -0,0 +1,3 @@ +52* "2 9 4" 55+ "7 5 3" 64+ "6 1 8" v + > , v + ^ _@# : < -- cgit From 5fba711ed3dc0bca50558b12f703fc1ef9cc878d Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 30 Nov 2020 15:10:43 +0100 Subject: Allow testing of Befunge-93 programs. --- challenge-089/abigail/test.pl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/challenge-089/abigail/test.pl b/challenge-089/abigail/test.pl index 5b9279313a..28c350501f 100755 --- a/challenge-089/abigail/test.pl +++ b/challenge-089/abigail/test.pl @@ -24,6 +24,7 @@ GetOptions 'slow' => \my $run_slow_tests, 'lang|language=s' => \my @languages, ; +my $HOME = $ENV {HOME}; my %languages = ( Perl => { @@ -53,6 +54,11 @@ my %languages = ( SQL => { ext => "sql", }, + 'Befunge-93' => { + ext => "bf", + dir => "befunge-93", + exe => "$HOME/Bin/bf", + }, ); my $perl_exe = $languages {Perl} {exe}; -- cgit From 60ef923c52c99c07bd236a969d1fff4b6f8077a3 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 30 Nov 2020 15:12:10 +0100 Subject: Expected output of week 89/part 2 --- challenge-089/abigail/t/output-2-1.exp | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 challenge-089/abigail/t/output-2-1.exp diff --git a/challenge-089/abigail/t/output-2-1.exp b/challenge-089/abigail/t/output-2-1.exp new file mode 100644 index 0000000000..c3121c14a2 --- /dev/null +++ b/challenge-089/abigail/t/output-2-1.exp @@ -0,0 +1,4 @@ +# There can only be one. +8 1 6 +3 5 7 +4 9 2 -- cgit From 6c8f673692217b5e5077043f5e2be45709d8541c Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 30 Nov 2020 16:18:31 +0100 Subject: Test bash programs --- challenge-089/abigail/test.pl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/challenge-089/abigail/test.pl b/challenge-089/abigail/test.pl index 28c350501f..5f3518eac8 100755 --- a/challenge-089/abigail/test.pl +++ b/challenge-089/abigail/test.pl @@ -58,7 +58,12 @@ my %languages = ( ext => "bf", dir => "befunge-93", exe => "$HOME/Bin/bf", - }, + }, + Bash => { + ext => "sh", + dir => "bash", + exe => "/bin/sh", + }, ); my $perl_exe = $languages {Perl} {exe}; -- cgit From f3280d502288129b5dfbfa2cfe0d064c1e4ae295 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 30 Nov 2020 16:18:55 +0100 Subject: Bash solution for week 89/part 2 --- challenge-089/abigail/bash/ch-2.sh | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 challenge-089/abigail/bash/ch-2.sh diff --git a/challenge-089/abigail/bash/ch-2.sh b/challenge-089/abigail/bash/ch-2.sh new file mode 100644 index 0000000000..5a4b6f1877 --- /dev/null +++ b/challenge-089/abigail/bash/ch-2.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +# +# For challenge and notes, see ../perl/ch-2.pl +# + +echo "8 1 6"; +echo "3 5 7"; +echo "4 9 2"; -- cgit From bd7eff64655ee42121f12dec385d6e3920e48ff4 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 30 Nov 2020 16:23:49 +0100 Subject: Test Python programs --- challenge-089/abigail/test.pl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/challenge-089/abigail/test.pl b/challenge-089/abigail/test.pl index 5f3518eac8..8d2807528e 100755 --- a/challenge-089/abigail/test.pl +++ b/challenge-089/abigail/test.pl @@ -64,6 +64,11 @@ my %languages = ( dir => "bash", exe => "/bin/sh", }, + Python => { + ext => "py", + dir => "python", + exe => "/opt/local/bin/python", + }, ); my $perl_exe = $languages {Perl} {exe}; -- cgit From ad1715dbf74a320b8ac63cff5d2e57761713378d Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 30 Nov 2020 16:24:13 +0100 Subject: Python solution for week 89/part 2 --- challenge-089/abigail/python/ch-2.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100755 challenge-089/abigail/python/ch-2.py diff --git a/challenge-089/abigail/python/ch-2.py b/challenge-089/abigail/python/ch-2.py new file mode 100755 index 0000000000..6e6ab53b2d --- /dev/null +++ b/challenge-089/abigail/python/ch-2.py @@ -0,0 +1,6 @@ +#!/opt/local/bin/python +# +# +print "8 1 6" +print "3 5 7" +print "4 9 2" -- cgit From 0a618444b5e4ae8beea531111a693ae1dbff53e1 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 30 Nov 2020 16:30:54 +0100 Subject: AWK solution for week 89/part 2 --- challenge-089/abigail/awk/ch-2.awk | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 challenge-089/abigail/awk/ch-2.awk diff --git a/challenge-089/abigail/awk/ch-2.awk b/challenge-089/abigail/awk/ch-2.awk new file mode 100644 index 0000000000..f45f20e40e --- /dev/null +++ b/challenge-089/abigail/awk/ch-2.awk @@ -0,0 +1,6 @@ +#!/usr/bin/awk +END { + print "8 1 6"; + print "3 5 7"; + print "4 9 2"; +} -- cgit From 9d627e5e3188b572833cc203603c17275642b3f1 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 30 Nov 2020 16:37:19 +0100 Subject: Test Ruby programs --- challenge-089/abigail/test.pl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/challenge-089/abigail/test.pl b/challenge-089/abigail/test.pl index 8d2807528e..b36faadf0c 100755 --- a/challenge-089/abigail/test.pl +++ b/challenge-089/abigail/test.pl @@ -69,6 +69,11 @@ my %languages = ( dir => "python", exe => "/opt/local/bin/python", }, + Ruby => { + ext => "rb", + dir => "ruby", + exe => "/usr/bin/ruby", + }, ); my $perl_exe = $languages {Perl} {exe}; -- cgit From a324a02253d19205b99ab8f8477a9a460c0ba4ff Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 30 Nov 2020 16:37:38 +0100 Subject: Ruby solution for week 89/part 2 --- challenge-089/abigail/ruby/ch-2.rb | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 challenge-089/abigail/ruby/ch-2.rb diff --git a/challenge-089/abigail/ruby/ch-2.rb b/challenge-089/abigail/ruby/ch-2.rb new file mode 100644 index 0000000000..c4bc2d5bee --- /dev/null +++ b/challenge-089/abigail/ruby/ch-2.rb @@ -0,0 +1,9 @@ +#!/usr/bin/ruby + +# +# For challenge and notes, see ../perl/ch-2.pl +# + +puts "8 1 6"; +puts "3 5 7"; +puts "4 9 2"; -- cgit From e2c6d197d6bc5ce417ded9318d71536d39599e76 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 30 Nov 2020 16:40:38 +0100 Subject: Test Csh programs --- challenge-089/abigail/test.pl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/challenge-089/abigail/test.pl b/challenge-089/abigail/test.pl index b36faadf0c..13345e3eaa 100755 --- a/challenge-089/abigail/test.pl +++ b/challenge-089/abigail/test.pl @@ -74,6 +74,12 @@ my %languages = ( dir => "ruby", exe => "/usr/bin/ruby", }, + Csh => { + ext => "csh", + dir => "csh", + exe => "/bin/csh", + }, + ); my $perl_exe = $languages {Perl} {exe}; -- cgit From cf105cfea5a011d0a4bc2cf20e32018a3194c40b Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 30 Nov 2020 16:40:58 +0100 Subject: Csh solution for week-89/part 2 --- challenge-089/abigail/csh/ch-2.csh | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100755 challenge-089/abigail/csh/ch-2.csh diff --git a/challenge-089/abigail/csh/ch-2.csh b/challenge-089/abigail/csh/ch-2.csh new file mode 100755 index 0000000000..844a882725 --- /dev/null +++ b/challenge-089/abigail/csh/ch-2.csh @@ -0,0 +1,9 @@ +#!/bin/csh + +# +# For challenge and notes, see ../perl/ch-2.pl +# + +echo "8 1 6"; +echo "3 5 7"; +echo "4 9 2"; -- cgit From 9115d53d1bb66833381e6f5b64a0122f01a7ce37 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 30 Nov 2020 16:46:26 +0100 Subject: BC solution for week 89/part 2 --- challenge-089/abigail/bc/ch-2.bc | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 challenge-089/abigail/bc/ch-2.bc diff --git a/challenge-089/abigail/bc/ch-2.bc b/challenge-089/abigail/bc/ch-2.bc new file mode 100644 index 0000000000..e31cf76f70 --- /dev/null +++ b/challenge-089/abigail/bc/ch-2.bc @@ -0,0 +1,4 @@ +"8 1 6 +3 5 7 +4 9 2 +" -- cgit From 69a1d6dfbfc218f4ff4a05b74dabc56bc386ab92 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 30 Nov 2020 18:50:01 +0100 Subject: Test Fortran programs. This introduced a little improvement of handling compiled languages. --- challenge-089/abigail/test.pl | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/challenge-089/abigail/test.pl b/challenge-089/abigail/test.pl index 13345e3eaa..da7e32d32a 100755 --- a/challenge-089/abigail/test.pl +++ b/challenge-089/abigail/test.pl @@ -47,7 +47,7 @@ my %languages = ( args => ["-f"], }, C => { - exe => "/usr/bin/cc", + comp => "/usr/bin/cc", ext => "c", dir => "c", }, @@ -79,6 +79,11 @@ my %languages = ( dir => "csh", exe => "/bin/csh", }, + Fortran => { + ext => "f90", + dir => "fortran", + comp => "/opt/local/bin/gfortran-mp-4.4", + } ); @@ -96,6 +101,7 @@ foreach my $challenge (@challenges) { my $info = $languages {$language}; my $exe = $$info {exe}; my $ext = $$info {ext}; + my $comp = $$info {comp}; my $dir = $$info {dir} // lc $language; my @args = @{$$info {args} // []}; my $filter = $$info {filter} // ''; @@ -105,11 +111,11 @@ foreach my $challenge (@challenges) { next unless -r $source; # - # C requires special handling. The source needs to be compiled. + # Some languages first need to be compiled. # - if ($language eq "C") { + if ($comp) { $compiled = $source =~ s/\.$ext$/.$ext_out/r; - system $exe, "-o", $compiled, $source; + system $comp, "-o", $compiled, $source; } # -- cgit From 999a3718f5b523c96725aeaa6847923054dde5db Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 30 Nov 2020 19:14:37 +0100 Subject: Fortran solution for week 89/part 2 --- challenge-089/abigail/fortran/ch-2.f90 | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 challenge-089/abigail/fortran/ch-2.f90 diff --git a/challenge-089/abigail/fortran/ch-2.f90 b/challenge-089/abigail/fortran/ch-2.f90 new file mode 100644 index 0000000000..401b6e8f34 --- /dev/null +++ b/challenge-089/abigail/fortran/ch-2.f90 @@ -0,0 +1,10 @@ +! +! For the challenge and notes, see ../perl/ch-2.pl +! + +program magic + implicit none + print *, "8 1 6" + print *, "3 5 7" + print *, "4 9 2" +end -- cgit From 085f72eaf34267b605532f5f347b261a50083279 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 30 Nov 2020 19:21:33 +0100 Subject: Option to trim leading whitespace. Since Fortran seems to emit leading whitespace. --- challenge-089/abigail/t/output-2-1.exp | 1 + challenge-089/abigail/test.pl | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/challenge-089/abigail/t/output-2-1.exp b/challenge-089/abigail/t/output-2-1.exp index c3121c14a2..ae726c3fc6 100644 --- a/challenge-089/abigail/t/output-2-1.exp +++ b/challenge-089/abigail/t/output-2-1.exp @@ -1,3 +1,4 @@ +#% Trim # There can only be one. 8 1 6 3 5 7 diff --git a/challenge-089/abigail/test.pl b/challenge-089/abigail/test.pl index da7e32d32a..1fdf80fdd6 100755 --- a/challenge-089/abigail/test.pl +++ b/challenge-089/abigail/test.pl @@ -148,8 +148,8 @@ foreach my $challenge (@challenges) { while ($exp =~ s/^\s*#%\s*(.*)\n//) { my $pragma = $1; $pragma =~ s/\s+$//; - if (lc $pragma eq "slow") { - $pragma {slow} = 1; + if ($pragma =~ /^\w+$/) { + $pragma {lc $pragma} = 1; next; } if ($pragma =~ /^\s*(\w+):\s*(.*)/) { @@ -181,6 +181,9 @@ foreach my $challenge (@challenges) { } s/\h+$//gm for $exp, $got; + if ($pragma {trim}) { + s/^\h+//gm for $exp, $got; + } is $got, $exp, $name; }} }; -- cgit From 88290aaf4f89316cecf0d2bfdfc99c4a0e8bf6f7 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 30 Nov 2020 20:07:22 +0100 Subject: Test Brainfuck programs --- challenge-089/abigail/test.pl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/challenge-089/abigail/test.pl b/challenge-089/abigail/test.pl index 1fdf80fdd6..4deecc0872 100755 --- a/challenge-089/abigail/test.pl +++ b/challenge-089/abigail/test.pl @@ -83,7 +83,12 @@ my %languages = ( ext => "f90", dir => "fortran", comp => "/opt/local/bin/gfortran-mp-4.4", - } + }, + 'Brainfuck' => { + ext => "bf", + dir => "brainfuck", + exe => "$HOME/Bin/brf", + }, ); -- cgit From 95fa7d75be438bd9d589b6477b9b6bf9db8aac51 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 30 Nov 2020 20:07:45 +0100 Subject: Brainfuck solution for week 89/part 2 --- challenge-089/abigail/brainfuck/ch-2.bf | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 challenge-089/abigail/brainfuck/ch-2.bf diff --git a/challenge-089/abigail/brainfuck/ch-2.bf b/challenge-089/abigail/brainfuck/ch-2.bf new file mode 100644 index 0000000000..77a4f771a6 --- /dev/null +++ b/challenge-089/abigail/brainfuck/ch-2.bf @@ -0,0 +1,12 @@ +++[>+++++<-] # Cell 1 contains 10 ("\n") +>>++++++++[>++++<-] # Cell 3 contains 32 (' ') +>>+++++++[>+++++++<-] # Cell 5 contains 49 ('1') +>+++++++ . << . > # Print 8 +>------- . << . > # Print 1 +>+++++ . <<<< . >>> # Print 6 +>--- . << . > # Print 3 +>++ . << . > # Print 5 +>++ . <<<< . >>> # Print 7 +>--- . << . > # Print 4 +>+++++ . << . > # Print 9 +>------- . <<<< . >>> # Print 2 -- cgit From 4004d67b3a49558555690b491dbf8922845c347e Mon Sep 17 00:00:00 2001 From: chirvasitua Date: Mon, 30 Nov 2020 17:13:43 -0500 Subject: 1st commit on 012 --- challenge-012/stuart-little/README | 1 + challenge-012/stuart-little/raku/ch-1.p6 | 6 ++++++ challenge-012/stuart-little/raku/ch-2.p6 | 11 +++++++++++ 3 files changed, 18 insertions(+) create mode 100644 challenge-012/stuart-little/README create mode 100755 challenge-012/stuart-little/raku/ch-1.p6 create mode 100755 challenge-012/stuart-little/raku/ch-2.p6 diff --git a/challenge-012/stuart-little/README b/challenge-012/stuart-little/README new file mode 100644 index 0000000000..78439907de --- /dev/null +++ b/challenge-012/stuart-little/README @@ -0,0 +1 @@ +Solutions by Stuart Little diff --git a/challenge-012/stuart-little/raku/ch-1.p6 b/challenge-012/stuart-little/raku/ch-1.p6 new file mode 100755 index 0000000000..cf9e37c40e --- /dev/null +++ b/challenge-012/stuart-little/raku/ch-1.p6 @@ -0,0 +1,6 @@ +#!/usr/bin/env perl6 +use v6; + +([\*] (2..*).grep(*.is-prime)).map(*+1).first(! *.is-prime).say + +# run as