From 4db69a63e0d326b573a9eae976504f0636fa3898 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 8 Feb 2021 10:00:33 +0100 Subject: Link to Lua solution --- challenge-098/abigail/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/challenge-098/abigail/README.md b/challenge-098/abigail/README.md index 56e481bb08..c4862967c8 100644 --- a/challenge-098/abigail/README.md +++ b/challenge-098/abigail/README.md @@ -56,6 +56,7 @@ Output: * [AWK](awk/ch-1.awk) * [Bash](bash/ch-1.sh) * [C](c/ch-1.ch) +* [Lua](lua/ch-1.lua) * [Perl](perl/ch-1.pl) ### Blog -- cgit From 27fe1354da313c53aa35aff5149585fd57085dec Mon Sep 17 00:00:00 2001 From: E7-87-83 Date: Mon, 1 Mar 2021 10:11:54 +0800 Subject: directory --- challenge-100/adam-russell/ch-1.dat | 1 + challenge-100/duncan-c-white/perl/mkTypes | 200 ++++++++++++++++++++++++++++++ challenge-101/cheok-yin-fung/perl/ch-1.pl | 147 ++++++++++++++++++++++ 3 files changed, 348 insertions(+) create mode 100644 challenge-100/adam-russell/ch-1.dat create mode 100644 challenge-100/duncan-c-white/perl/mkTypes create mode 100644 challenge-101/cheok-yin-fung/perl/ch-1.pl diff --git a/challenge-100/adam-russell/ch-1.dat b/challenge-100/adam-russell/ch-1.dat new file mode 100644 index 0000000000..a32a4347a4 --- /dev/null +++ b/challenge-100/adam-russell/ch-1.dat @@ -0,0 +1 @@ +1234567890 diff --git a/challenge-100/duncan-c-white/perl/mkTypes b/challenge-100/duncan-c-white/perl/mkTypes new file mode 100644 index 0000000000..c15c733c43 --- /dev/null +++ b/challenge-100/duncan-c-white/perl/mkTypes @@ -0,0 +1,200 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use lib qw(/homes/dcw/lib/perl5/DCW); +use Datadec; + +my $posexpr = q( +PosExpr = I( int n ) "$1" + or N( string name ) "$1" + or NO( string name, char op, int n ) "$1$2$3" +); + +my $extra = q! + +my $debug = 0; +sub setdebug { my($d) = @_; $debug = $d; } + +# +# my($pe,$leftover) = parse($input); +# Parse $input, a string starting with a position expression, +# delivering the position expression in $pe and the leftover +# input in $leftover. Die screaming if no well formed pos expr +# can be found at the start of $input. +# A position expression is either \d+ or name or name '+'|'-' \d+ +# The internal form of a posexpr is ['I', int const] or ['N', name] +# or ['NO', name, +-, offset] +# +sub parse ($) +{ + my( $input ) = @_; + if( $input =~ s/^(\d+)\s*// ) + { + return ( PosExpr->I($1), $input ); + } + $input =~ s/^(\w+)\s*// || + die "bad input in pos expr $input, name expected\n"; + my $name = $1; + if( $input =~ s/^([\+-])\s*(\d+)\s*// ) + { + return ( PosExpr->NO($name,$1,$2), $input ); + } + return ( PosExpr->N($name), $input ); +} + +# +# my $pos = $pe->eval($poshash); +# Evaluate the given PosExpr $pe, using %$poshash +# for name lookup. Returns the actual position (a number). +# +sub eval ($$) +{ + my( $self, $poshash ) = @_; + if( $self->kind eq 'I' ) + { + return $self->I; + } elsif( $self->kind eq 'N' ) + { + my $name = $self->N; + die "error in PosExpr::eval($self): ". + "no such name $name in poshash ". Dumper($poshash) + unless exists $poshash->{$name}; + return $poshash->{$name}; + } else # if( $self->kind eq 'NO' ) + { + my ($name, $op, $n) = $self->NO; + die "error in PosExpr::eval($self): ". + "no such name $name in poshash ". Dumper($poshash) + unless exists $poshash->{$name}; + die "error in PosExpr::eval($self): bad op $op\n" unless + $op eq '+' || $op eq '-'; + $n = - $n if $op eq '-'; + return $poshash->{$name} + $n; + } +} + + + +!; + +open( my $fh, '>', "PosExpr.pm" ) || die; +say $fh gen_datatype( $posexpr, $extra ); + +close($fh); + +my $api = q( +API = F( string lit, string name ) "F '$1' -> $2" + or L( string lit, string name ) "L '$1' -> $2" + or M( string lit, posexpr atorafter, string name ) "M '$1' $2 -> $3" + or T( posexpr pe1, string op, posexpr pe2 ) "T $1$2$3" + or C( int mn, posexpr pe1, posexpr pe2) "C $1 $2 $3" +); + +$extra = q% + +my $debug = 0; +sub setdebug { my($d) = @_; $debug = $d; } + +# +# my @api = parse( $input ); +# Parse $input, a string containing a comma-separated sequence +# of Abstract Pattern Instructions, return the list of apis. +# Die screaming if parsing fails. +# For example, matching the pattern a*e is represented by the +# following api string: +# F'a'->pa,L'e'->plast,Tplast>pa-1,C0 pa+1 plast-1 +# The individual api forms are: +# F'str'->name +# L'str'->name +# M'str' posexpr->name +# Tposexpr ('>'|'=') posexpr +# C\d+ posexpr [posexpr] +# where posexpr = \d+ or name or name '+'|'-' \d+ +# +sub parse ($) +{ + my( $input ) = @_; + my @result; + while( $input ) + { + # F'str'->name + if( $input =~ s/^F\s*// ) + { + $input =~ s/^'([^']+)'\s*->\s*(\w+)// || + die "bad input $input in F..\n"; + my $api = API->F($1, $2); + say "debug: parsed api $api, rest input $input" + if $debug; + push @result, $api; + } + # L'str'->name + elsif( $input =~ s/^L\s*// ) + { + $input =~ s/^'([^']+)'\s*->\s*(\w+)// || + die "bad input $input in L..\n"; + my $api = API->L($1, $2); + say "debug: parsed api $api, rest input $input" + if $debug; + push @result, $api; + } + # M'str' posexpr->name + elsif( $input =~ s/^M\s*// ) + { + $input =~ s/^'([^']+)'\s+// || + die "bad input $input in M..\n"; + my $str = $1; + (my $pe,$input) = PosExpr::parse($input); + die "bad input $input in M$str $pe...\n" + unless $input =~ s/^\s*->\s*(\w+)//; + my $pname = $1; + my $api = API->M($str, $pe, $pname); + say "debug: parsed api $api, rest input $input" + if $debug; + push @result, $api; + } + # Tposexpr ('>'|'=') posexpr + elsif( $input =~ s/^T\s*// ) + { + (my $pe,$input) = PosExpr::parse($input); + $input =~ s/^(>|=)// || + die "bad input $input in T$pe, > or = expected\n"; + my $op = $1; + (my $pe2,$input) = PosExpr::parse($input); + my $api = API->T($pe, $op, $pe2); + say "debug: parsed api $api, rest input $input" + if $debug; + push @result, $api; + } + # C\d+ posexpr [posexpr] + elsif( $input =~ s/^C\s*// ) + { + $input =~ s/^(\d+)\s*// || + die "bad input $input in C.. integer expected\n"; + my $mn = $1; + (my $pe,$input) = PosExpr::parse($input); + $input =~ s/^\s*//; + + # second posexpr is optional: + # present if next ch is not ',' + my $pe2 = $pe; + if( $input ne '' && $input !~ /^,/ ) + { + ($pe2,$input) = PosExpr::parse($input); + } + my $api = API->C($mn, $pe, $pe2); + say "debug: parsed api $api, rest input $input" + if $debug; + push @result, $api; + } + $input =~ s/^\s*,\s*//; + } + die "bad input $input, non empty but not F|L|M|T|C..\n" if $input; + return @result; +} +%; + + +open( $fh, '>', "API.pm" ) || die; +say $fh gen_datatype( $api, $extra ); +close($fh); diff --git a/challenge-101/cheok-yin-fung/perl/ch-1.pl b/challenge-101/cheok-yin-fung/perl/ch-1.pl new file mode 100644 index 0000000000..50af192610 --- /dev/null +++ b/challenge-101/cheok-yin-fung/perl/ch-1.pl @@ -0,0 +1,147 @@ +#!/usr/bin/perl +use strict; +use warnings; +# The Weekly Challenge #101 Task 1 Pack a Spiral +# Usage: ch-1.pl [items] +# modify from my code for challenge #088 "Spiral Matrix" + +use List::Util qw/max/; + + +sub my_printf { + print " " x ( $_[1] - (length $_[0]) ); + print $_[0]; +} + +sub closest_factorization { + my $num = $_[0]; + my $factor1 = 1; + my $factor2 = 1; + for my $int ( 1 .. $num ) { + if ($num % $int == 0) { + $factor1 = $factor2; + $factor2 = $int; + } + last if $factor1 * $factor2 >= $num; + } + + if ($factor1*$factor1 != $num) { + return ($factor1, $factor2); + } else + { + return ($factor1, $factor1); + } +} + + +sub print_matrix_ad { + my @mat = @{$_[0]}; + my $M = scalar @mat; + my $N = scalar @{$mat[0]}; + + my @columnlength; + for my $i (0..$N-1) {$columnlength[$i] = 1;} + for my $i (0..$N-1) { + for my $j (0..$M-1) { + $columnlength[$i] = max($columnlength[$i], 1+ (length $mat[$j]->[$i])); + } + } + + for my $j (0..$M-1) { + for my $i (0..$N-1) { + my_printf($mat[$j]->[$i], $columnlength[$i]); + } + print "\n"; + } + +} + + +sub matrixize_anticlockwise { + my @list = @{$_[0]}; + my $M = $_[1]; + my $N = $_[2]; + my @mat; + my @helper_mat; + +#BEGIN: special case handling: the numbers of entries is prime + if ($M == 1) {return \@list;} +#END: special case handling + + + my @row_dir = ( 0, -1, 0, +1 ); + my @col_dir = ( +1, 0, -1, 0 ); + + my ($r, $c) = ( $M-1 , 0); + ${$mat[$r]}[$c] = $list[0]; + ${$helper_mat[$r]}[$c] = 1; + + my @numbering = ( + [1..$N-1], + [$N..$N+$M-2], + [$N+$M-1..$N+$M+$N-3], + [$N+$M+$N-2..($M-1)*2+($N-1)*2-1] + ); + + my $count = 1; + for my $q (0..3) { + for (@{$numbering[$q]}) { + $r += $row_dir[$q]; + $c += $col_dir[$q]; + + ${$mat[$r]}[$c] = $list[$count]; + ${$helper_mat[$r]}[$c] = 1; + + $count++; + } + } + + my $time_now = 3; + my $success_click = undef; + while ($count < $M*$N) { + if ($success_click) { + $r += $row_dir[$time_now]; + $c += $col_dir[$time_now]; + if (!defined ${$helper_mat[$r]}[$c] ) + { + ${$mat[$r]}[$c] = $list[$count]; + ${$helper_mat[$r]}[$c] = 1; + $success_click = 1; + $count++; + } else + { + $success_click = undef; + $r -= $row_dir[$time_now]; + $c -= $col_dir[$time_now]; + } + } else + { + $time_now = ($time_now+1) % 4; + $success_click = 1; + } + } + return @mat; +} + + +# MAIN BODY +if ($ARGV[0]) { + my @items = @ARGV; + my $num_of_items = scalar @items; + my @test = matrixize_anticlockwise( \@items, closest_factorization($num_of_items) ); + print_matrix_ad([@test]); +} + + +=pod + +@items = (1..60); + + 24 23 22 21 20 19 18 17 16 15 + 25 46 45 44 43 42 41 40 39 14 + 26 47 60 59 58 57 56 55 38 13 + 27 48 49 50 51 52 53 54 37 12 + 28 29 30 31 32 33 34 35 36 11 + 1 2 3 4 5 6 7 8 9 10 + +=cut -- cgit From 161b46493925498e77ce338d04e505642ef746ec Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 1 Mar 2021 10:49:48 +0100 Subject: README for week 102 --- challenge-102/abigail/README.md | 127 ++++++++-------------------------------- 1 file changed, 24 insertions(+), 103 deletions(-) diff --git a/challenge-102/abigail/README.md b/challenge-102/abigail/README.md index caf1448381..4fc611621d 100644 --- a/challenge-102/abigail/README.md +++ b/challenge-102/abigail/README.md @@ -1,122 +1,43 @@ # Solution by Abigail -## [Pack a Spiral](https://perlweeklychallenge.org/blog/perl-weekly-challenge-101/#TASK1) +## [Rare Numbers](https://perlweeklychallenge.org/blog/perl-weekly-challenge-102/#TASK1) -You are given an array `@A` of items (integers say, but they can be anything). -Your task is to pack that array into an `MxN` matrix spirally -counterclockwise, as tightly as possible. +You are given a positive integer `$N`. -'Tightly' means the absolute value `|M-N|` of the difference has to be as -small as possible +Write a script to generate all Rare numbers of size `$N` if exists. +Please checkout [the page](http://www.shyamsundergupta.com/rare.htm) +for more information about it. ### Examples -#### Example 1 ~~~~ -Input: @A = (1,2,3,4) - -Output: - - 4 3 - 1 2 +(a) 2 digits: 65 +(b) 6 digits: 621770 +(c) 9 digits: 281089082 ~~~~ -Since the given array is already a `1x4` matrix on its own, but that's -not as tight as possible. Instead, you'd spiral it counterclockwise into - -~~~~ - 4 3 - 1 2 -~~~~ -#### Example 2 -~~~~ -Input: @A = (1..6) -Output: - 6 5 4 - 1 2 3 -~~~~ -or -~~~~ - 5 4 - 6 3 - 1 2 -~~~~ -Either will do as an answer, because they're equally tight. - -#### Example 3 -~~~~ -Input: @A = (1..12) - -Output: - 9 8 7 6 - 10 11 12 5 - 1 2 3 4 -~~~~ -or -~~~~ - 8 7 6 - 9 12 5 - 10 11 4 - 1 2 3 -~~~~ +## [Hash-counting String](https://perlweeklychallenge.org/blog/perl-weekly-challenge-102/#TASK2) -### Solutions -* [AWK](awk/ch-1.awk) -* [Bash](bash/ch-1.sh) -* [C](c/ch-1.c) -* [Lua](lua/ch-1.lua) -* [Node.js](node/ch-1.js) -* [Perl](perl/ch-1.pl) -* [Python](python/ch-1.py) -* [Ruby](ruby/ch-1.rb) +You are given a positive integer `$N`. -### Blog -[Perl Weekly Challenge 101: Pack a Spiral](https://wp.me/pcxd30-r7) +Write a script to produce Hash-counting string of that length. +The definition of a hash-counting string is as follows: +- the string consists only of digits 0-9 and hashes, `'#'`. +- there are no two consecutive hashes: `"##"z does not appear in your string +- the last character is a hash +- the number immediately preceding each hash (if it exists) is the position + of that hash in the string, with the position being counted up from 1 -## [Origin-containing Triangle](https://perlweeklychallenge.org/blog/perl-weekly-challenge-101/#TASK2) - -You are given three points in the plane, as a list of six co-ordinates: -`A=(x1,y1)`, `B=(x2,y2)` and `C=(x3,y3)`. - -Write a script to find out if the triangle formed by the given three -co-ordinates contain origin `(0,0)`. - -Print `1` if found otherwise `0`. +It can be shown that for every positive integer `N` there is exactly one +such length-`N` string. ### Examples -#### Example 1 -~~~~ -Input: A=(0,1), B=(1,0) and C=(2,2) - -Output: 0 because that triangle does not contain (0,0). -~~~~ - -#### Example 2 ~~~~ -Input: A=(1,1), B=(-1,1) and C=(0,-3) - -Output: 1 because that triangle contains (0,0) in its interior. -~~~~ - -#### Example 3 +(a) "#" is the counting string of length 1 +(b) "2#" is the counting string of length 2 +(c) "#3#" is the string of length 3 +(d) "#3#5#7#10#" is the string of length 10 +(e) "2#4#6#8#11#14#" is the string of length 14 ~~~~ -Input: A=(0,1), B=(2,0) and C=(-6,0) - -Output: 1 because (0,0) is on the edge connecting B and C. -~~~~ - -### Solutions -* [AWK](awk/ch-2.awk) -* [Bash](bash/ch-2.sh) -* [Befunge-93](befunge-93/ch-2.bf93) -* [C](c/ch-2.c) -* [Lua](lua/ch-2.lua) -* [Node.js](node/ch-2.js) -* [Perl](perl/ch-2.pl) -* [Python](python/ch-2.py) -* [Ruby](ruby/ch-2.rb) - -### Blog -[Perl Weekly Challenge 101: Origin-containing Triangle](https://wp.me/pcxd30-s8) -- cgit From 8446cba67eb78e4ca446a0426593259a99761a38 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 1 Mar 2021 10:53:11 +0100 Subject: Test cases for week 102 --- challenge-102/abigail/t/ctest.ini | 5 +++++ challenge-102/abigail/t/input-1-1 | 1 + challenge-102/abigail/t/input-1-2 | 1 + challenge-102/abigail/t/input-1-3 | 1 + challenge-102/abigail/t/input-2-1 | 5 +++++ challenge-102/abigail/t/output-1-1.exp | 1 + challenge-102/abigail/t/output-1-2.exp | 1 + challenge-102/abigail/t/output-1-3.exp | 1 + challenge-102/abigail/t/output-2-1.exp | 5 +++++ 9 files changed, 21 insertions(+) create mode 100644 challenge-102/abigail/t/ctest.ini create mode 100644 challenge-102/abigail/t/input-1-1 create mode 100644 challenge-102/abigail/t/input-1-2 create mode 100644 challenge-102/abigail/t/input-1-3 create mode 100644 challenge-102/abigail/t/input-2-1 create mode 100644 challenge-102/abigail/t/output-1-1.exp create mode 100644 challenge-102/abigail/t/output-1-2.exp create mode 100644 challenge-102/abigail/t/output-1-3.exp create mode 100644 challenge-102/abigail/t/output-2-1.exp diff --git a/challenge-102/abigail/t/ctest.ini b/challenge-102/abigail/t/ctest.ini new file mode 100644 index 0000000000..36c4cb3bde --- /dev/null +++ b/challenge-102/abigail/t/ctest.ini @@ -0,0 +1,5 @@ +[names] +1-1 = Given example 1 +1-2 = Given example 2 +1-3 = Given example 3 +2-1 = Given examples diff --git a/challenge-102/abigail/t/input-1-1 b/challenge-102/abigail/t/input-1-1 new file mode 100644 index 0000000000..0cfbf08886 --- /dev/null +++ b/challenge-102/abigail/t/input-1-1 @@ -0,0 +1 @@ +2 diff --git a/challenge-102/abigail/t/input-1-2 b/challenge-102/abigail/t/input-1-2 new file mode 100644 index 0000000000..1e8b314962 --- /dev/null +++ b/challenge-102/abigail/t/input-1-2 @@ -0,0 +1 @@ +6 diff --git a/challenge-102/abigail/t/input-1-3 b/challenge-102/abigail/t/input-1-3 new file mode 100644 index 0000000000..ec635144f6 --- /dev/null +++ b/challenge-102/abigail/t/input-1-3 @@ -0,0 +1 @@ +9 diff --git a/challenge-102/abigail/t/input-2-1 b/challenge-102/abigail/t/input-2-1 new file mode 100644 index 0000000000..9807d3e74e --- /dev/null +++ b/challenge-102/abigail/t/input-2-1 @@ -0,0 +1,5 @@ +1 +2 +3 +10 +14 diff --git a/challenge-102/abigail/t/output-1-1.exp b/challenge-102/abigail/t/output-1-1.exp new file mode 100644 index 0000000000..1479e19b5f --- /dev/null +++ b/challenge-102/abigail/t/output-1-1.exp @@ -0,0 +1 @@ +65 diff --git a/challenge-102/abigail/t/output-1-2.exp b/challenge-102/abigail/t/output-1-2.exp new file mode 100644 index 0000000000..ce4706285e --- /dev/null +++ b/challenge-102/abigail/t/output-1-2.exp @@ -0,0 +1 @@ +621770 diff --git a/challenge-102/abigail/t/output-1-3.exp b/challenge-102/abigail/t/output-1-3.exp new file mode 100644 index 0000000000..72de9be064 --- /dev/null +++ b/challenge-102/abigail/t/output-1-3.exp @@ -0,0 +1 @@ +281089082 diff --git a/challenge-102/abigail/t/output-2-1.exp b/challenge-102/abigail/t/output-2-1.exp new file mode 100644 index 0000000000..18aec0ff0f --- /dev/null +++ b/challenge-102/abigail/t/output-2-1.exp @@ -0,0 +1,5 @@ +# +2# +#3# +#3#5#7#10# +2#4#6#8#11#14# -- cgit From c40234a802aa02a23ec76d615edb7a86824d86e4 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 1 Mar 2021 11:08:29 +0100 Subject: More test cases for week 102, part 1 --- challenge-102/abigail/t/ctest.ini | 3 +++ challenge-102/abigail/t/input-1-4 | 1 + challenge-102/abigail/t/input-1-5 | 1 + challenge-102/abigail/t/input-1-6 | 5 +++++ challenge-102/abigail/t/output-1-4.exp | 5 +++++ challenge-102/abigail/t/output-1-5.exp | 0 challenge-102/abigail/t/output-1-6.exp | 8 ++++++++ 7 files changed, 23 insertions(+) create mode 100644 challenge-102/abigail/t/input-1-4 create mode 100644 challenge-102/abigail/t/input-1-5 create mode 100644 challenge-102/abigail/t/input-1-6 create mode 100644 challenge-102/abigail/t/output-1-4.exp create mode 100644 challenge-102/abigail/t/output-1-5.exp create mode 100644 challenge-102/abigail/t/output-1-6.exp diff --git a/challenge-102/abigail/t/ctest.ini b/challenge-102/abigail/t/ctest.ini index 36c4cb3bde..6daf69e9fe 100644 --- a/challenge-102/abigail/t/ctest.ini +++ b/challenge-102/abigail/t/ctest.ini @@ -2,4 +2,7 @@ 1-1 = Given example 1 1-2 = Given example 2 1-3 = Given example 3 +1-4 = Multiple numbers of given length +1-5 = No numbers of given length +1-6 = Multiple inputs 2-1 = Given examples diff --git a/challenge-102/abigail/t/input-1-4 b/challenge-102/abigail/t/input-1-4 new file mode 100644 index 0000000000..aabe6ec390 --- /dev/null +++ b/challenge-102/abigail/t/input-1-4 @@ -0,0 +1 @@ +21 diff --git a/challenge-102/abigail/t/input-1-5 b/challenge-102/abigail/t/input-1-5 new file mode 100644 index 0000000000..00750edc07 --- /dev/null +++ b/challenge-102/abigail/t/input-1-5 @@ -0,0 +1 @@ +3 diff --git a/challenge-102/abigail/t/input-1-6 b/challenge-102/abigail/t/input-1-6 new file mode 100644 index 0000000000..a391388ef2 --- /dev/null +++ b/challenge-102/abigail/t/input-1-6 @@ -0,0 +1,5 @@ +2 +6 +9 +21 +3 diff --git a/challenge-102/abigail/t/output-1-4.exp b/challenge-102/abigail/t/output-1-4.exp new file mode 100644 index 0000000000..c0d94917bf --- /dev/null +++ b/challenge-102/abigail/t/output-1-4.exp @@ -0,0 +1,5 @@ +208393425242000083802 +219518549668074815912 +257661195832219326752 +286694688797362186682 +837982875780054779738 diff --git a/challenge-102/abigail/t/output-1-5.exp b/challenge-102/abigail/t/output-1-5.exp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/challenge-102/abigail/t/output-1-6.exp b/challenge-102/abigail/t/output-1-6.exp new file mode 100644 index 0000000000..0f093449c7 --- /dev/null +++ b/challenge-102/abigail/t/output-1-6.exp @@ -0,0 +1,8 @@ +65 +621770 +281089082 +208393425242000083802 +219518549668074815912 +257661195832219326752 +286694688797362186682 +837982875780054779738 -- cgit From 99c1a145ab1f4e5fe3aebb504fddd56e1fde1916 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 1 Mar 2021 11:55:09 +0100 Subject: Perl solution for week 102, part 1 --- challenge-102/abigail/README.md | 2 + challenge-102/abigail/perl/ch-1.pl | 190 +++++++++++++++++++++++++++++++++++++ 2 files changed, 192 insertions(+) create mode 100644 challenge-102/abigail/perl/ch-1.pl diff --git a/challenge-102/abigail/README.md b/challenge-102/abigail/README.md index 4fc611621d..c5c709480e 100644 --- a/challenge-102/abigail/README.md +++ b/challenge-102/abigail/README.md @@ -15,6 +15,8 @@ for more information about it. (c) 9 digits: 281089082 ~~~~ +### Solutions +* [Perl](perl/ch-1.pl) ## [Hash-counting String](https://perlweeklychallenge.org/blog/perl-weekly-challenge-102/#TASK2) diff --git a/challenge-102/abigail/perl/ch-1.pl b/challenge-102/abigail/perl/ch-1.pl new file mode 100644 index 0000000000..a72efddd50 --- /dev/null +++ b/challenge-102/abigail/perl/ch-1.pl @@ -0,0 +1,190 @@ +#!/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 +# + +# +# There is no simple efficient algorithm for spitting out rare numbers; +# at least not one which can be easily found online. +# +# The code fragments in the OEIS only give code to check whether a +# number is a rare number, and they don't suggest anything other +# than "try all numbers" if you want to find all of the numbers of a +# certain length. +# +# Shyam writes: "I have developed a computer program in Fortran to +# calculate Rare numbers. In fact with refinement of the code over +# the years, the program has been made so powerful that all numbers +# up to 10^14 can be just checked for Rare numbers in less than a +# minute on Pentium III PC. In few hours I have been able to check +# up to 10^18." (https://www.primepuzzles.net/conjectures/conj_023.htm) +# but he does not publish his code. +# +# Richard Guy writes "Here are three problems that have come to light +# recently, each of which can consume unlimited amounts of computer time, +# perhaps without revealing anything significant". [2] +# The rare numbers are one of the three problems. +# + +# +# So, we just include a list of all know rare numbers, up to 10^22 [3], +# and preprocess them so they're bucketed to length. Then it's just +# a matter of reading the desired length, and printing the appropriate +# entry (or the empty string if no rare numbers of that length exist). +# There are only 124 known rare numbers, so preprocessing is very +# feasible. +# + +# +# [1] https://www.primepuzzles.net/conjectures/conj_023.htm +# [2] Guy, Richard K. "Conway's RATS and Other Reversals." The American +# Mathematical Monthly 96, no. 5 (1989): 425-28. Accessed March 1, 2021. +# doi:10.2307/2325149. (https://www.jstor.org/stable/2325149?seq=1) +# [3] https://oeis.org/A035519/b035519.txt +# + +my @rare_numbers; +$rare_numbers [ 2] = "65\n"; +$rare_numbers [ 6] = "621770\n"; +$rare_numbers [ 9] = "281089082\n"; +$rare_numbers [10] = "2022652202\n" . + "2042832002\n"; +$rare_numbers [12] = "868591084757\n" . + "872546974178\n" . + "872568754178\n"; +$rare_numbers [13] = "6979302951885\n"; +$rare_numbers [14] = "20313693904202\n" . + "20313839704202\n" . + "20331657922202\n" . + "20331875722202\n" . + "20333875702202\n" . + "40313893704200\n" . + "40351893720200\n"; +$rare_numbers [15] = "200142385731002\n" . + "204238494066002\n" . + "221462345754122\n" . + "244062891224042\n" . + "245518996076442\n" . + "248359494187442\n" . + "403058392434500\n" . + "441054594034340\n" . + "816984566129618\n"; +$rare_numbers [16] = "2078311262161202\n" . + "2133786945766212\n" . + "2135568943984212\n" . + "2135764587964212\n" . + "2135786765764212\n" . + "4135786945764210\n" . + "6157577986646405\n" . + "6889765708183410\n" . + "8052956026592517\n" . + "8052956206592517\n" . + "8191154686620818\n" . + "8191156864620818\n" . + "8191376864400818\n" . + "8650327689541457\n" . + "8650349867341457\n"; +$rare_numbers [17] = "22542040692914522\n" . + "67725910561765640\n" . + "86965750494756968\n"; +$rare_numbers [18] = "225342456863243522\n" . + "225342458663243522\n" . + "225342478643243522\n" . + "284684666566486482\n" . + "284684868364486482\n" . + "297128548234950692\n" . + "297128722852950692\n" . + "297148324656930692\n" . + "297148546434930692\n" . + "497168548234910690\n" . + "619431353040136925\n" . + "619631153042134925\n" . + "631688638047992345\n" . + "633288858025996145\n" . + "633488632647994145\n" . + "653488856225994125\n" . + "811865096390477018\n" . + "865721270017296468\n" . + "871975098681469178\n" . + "898907259301737498\n"; +$rare_numbers [19] = "2042401829204402402\n" . + "2060303819041450202\n" . + "2420424089100600242\n" . + "2551755006254571552\n" . + "2702373360882732072\n" . + "2825378427312735282\n" . + "6531727101458000045\n" . + "6988066446726832640\n" . + "8066308349502036608\n" . + "8197906905009010818\n" . + "8200756128308135597\n" . + "8320411466598809138\n"; +$rare_numbers [20] = "22134434735752443122\n" . + "22134434753752443122\n" . + "22134436953532443122\n" . + "22136414517954423122\n" . + "22136414971554423122\n" . + "22136456771730423122\n" . + "61952807156239928885\n" . + "61999171315484316965\n" . + "65459144877856561700\n"; +$rare_numbers [21] = "208393425242000083802\n" . + "219518549668074815912\n" . + "257661195832219326752\n" . + "286694688797362186682\n" . + "837982875780054779738\n"; +$rare_numbers [22] = "2414924301133245383042\n" . + "2414924323311045383042\n" . + "2414946523311023183042\n" . + "2576494891793995836752\n" . + "2576494893971995836752\n" . + "2620937863931054483162\n" . + "2620937863931054483162\n" . + "2620955641393276283162\n" . + "2622935621573476481162\n" . + "2622935643751276481162\n" . + "2622937641933274481162\n" . + "2622955841933256281162\n" . + "2622957843751254281162\n" . + "2727651947516658327272\n" . + "2747736918335953517072\n" . + "2788047668617596408872\n" . + "2788047848617776408872\n" . + "2788047868437576408872\n" . + "2788047888617376408872\n" . + "2939501759705522349392\n" . + "2939503375709360349392\n" . + "2939503537707740349392\n" . + "2939521359525562149392\n" . + "2939521557527542149392\n" . + "2939523577527340149392\n" . + "2939523779525320149392\n" . + "2959503377707360349192\n" . + "6344828989519887483525\n" . + "8045841652464561594308\n" . + "8045841654642561594308\n" . + "8655059576513659814468\n" . + "8655059772157639814468\n" . + "8655079374155679614468\n" . + "8655079574515659614468\n" . + "8888070771864228883913\n"; + + +print $rare_numbers [$_] // "" while <>; + + +__END__ -- cgit From 4c85d863d087d0ad6ece8d2982bbd719ca4c818b Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 1 Mar 2021 12:27:09 +0100 Subject: AWK solution for week 102, part 1 --- challenge-102/abigail/README.md | 1 + challenge-102/abigail/awk/ch-1.awk | 151 +++++++++++++++++++++++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 challenge-102/abigail/awk/ch-1.awk diff --git a/challenge-102/abigail/README.md b/challenge-102/abigail/README.md index c5c709480e..d196562cbb 100644 --- a/challenge-102/abigail/README.md +++ b/challenge-102/abigail/README.md @@ -16,6 +16,7 @@ for more information about it. ~~~~ ### Solutions +* [AWK](awk/ch-1.awk) * [Perl](perl/ch-1.pl) diff --git a/challenge-102/abigail/awk/ch-1.awk b/challenge-102/abigail/awk/ch-1.awk new file mode 100644 index 0000000000..ccfb3cd023 --- /dev/null +++ b/challenge-102/abigail/awk/ch-1.awk @@ -0,0 +1,151 @@ +#!/usr/bin/awk + +# +# See ../README.md +# + +# +# Run as: awk -f ch-1.awk < input-file +# + +# +# Load the list of all known rare numbers. Note that we're using +# strings instead of numbers, since the largest number exceed +# the largest integer AWK stores losslessly. +# +BEGIN { + rare_numbers [ 2] = "65\n" + rare_numbers [ 6] = "621770\n" + rare_numbers [ 9] = "281089082\n" + rare_numbers [10] = "2022652202\n" \ + "2042832002\n" + rare_numbers [12] = "868591084757\n" \ + "872546974178\n" \ + "872568754178\n" + rare_numbers [13] = "6979302951885\n" + rare_numbers [14] = "20313693904202\n" \ + "20313839704202\n" \ + "20331657922202\n" \ + "20331875722202\n" \ + "20333875702202\n" \ + "40313893704200\n" \ + "40351893720200\n" + rare_numbers [15] = "200142385731002\n" \ + "204238494066002\n" \ + "221462345754122\n" \ + "244062891224042\n" \ + "245518996076442\n" \ + "248359494187442\n" \ + "403058392434500\n" \ + "441054594034340\n" \ + "816984566129618\n" + rare_numbers [16] = "2078311262161202\n" \ + "2133786945766212\n" \ + "2135568943984212\n" \ + "2135764587964212\n" \ + "2135786765764212\n" \ + "4135786945764210\n" \ + "6157577986646405\n" \ + "6889765708183410\n" \ + "8052956026592517\n" \ + "8052956206592517\n" \ + "8191154686620818\n" \ + "8191156864620818\n" \ + "8191376864400818\n" \ + "8650327689541457\n" \ + "8650349867341457\n" + rare_numbers [17] = "22542040692914522\n" \ + "67725910561765640\n" \ + "86965750494756968\n" + rare_numbers [18] = "225342456863243522\n" \ + "225342458663243522\n" \ + "225342478643243522\n" \ + "284684666566486482\n" \ + "284684868364486482\n" \ + "297128548234950692\n" \ + "297128722852950692\n" \ + "297148324656930692\n" \ + "297148546434930692\n" \ + "497168548234910690\n" \ + "619431353040136925\n" \ + "619631153042134925\n" \ + "631688638047992345\n" \ + "633288858025996145\n" \ + "633488632647994145\n" \ + "653488856225994125\n" \ + "811865096390477018\n" \ + "865721270017296468\n" \ + "871975098681469178\n" \ + "898907259301737498\n" + rare_numbers [19] = "2042401829204402402\n" \ + "2060303819041450202\n" \ + "2420424089100600242\n" \ + "2551755006254571552\n" \ + "2702373360882732072\n" \ + "2825378427312735282\n" \ + "6531727101458000045\n" \ + "6988066446726832640\n" \ + "8066308349502036608\n" \ + "8197906905009010818\n" \ + "8200756128308135597\n" \ + "8320411466598809138\n" + rare_numbers [20] = "22134434735752443122\n" \ + "22134434753752443122\n" \ + "22134436953532443122\n" \ + "22136414517954423122\n" \ + "22136414971554423122\n" \ + "22136456771730423122\n" \ + "61952807156239928885\n" \ + "61999171315484316965\n" \ + "65459144877856561700\n" + rare_numbers [21] = "208393425242000083802\n" \ + "219518549668074815912\n" \ + "257661195832219326752\n" \ + "286694688797362186682\n" \ + "837982875780054779738\n" + rare_numbers [22] = "2414924301133245383042\n" \ + "2414924323311045383042\n" \ + "2414946523311023183042\n" \ + "2576494891793995836752\n" \ + "2576494893971995836752\n" \ + "2620937863931054483162\n" \ + "2620937863931054483162\n" \ + "2620955641393276283162\n" \ + "2622935621573476481162\n" \ + "2622935643751276481162\n" \ + "2622937641933274481162\n" \ + "2622955841933256281162\n" \ + "2622957843751254281162\n" \ + "2727651947516658327272\n" \ + "2747736918335953517072\n" \ + "2788047668617596408872\n" \ + "2788047848617776408872\n" \ + "2788047868437576408872\n" \ + "2788047888617376408872\n" \ + "2939501759705522349392\n" \ + "2939503375709360349392\n" \ + "2939503537707740349392\n" \ + "2939521359525562149392\n" \ + "2939521557527542149392\n" \ + "2939523577527340149392\n" \ + "2939523779525320149392\n" \ + "2959503377707360349192\n" \ + "6344828989519887483525\n" \ + "8045841652464561594308\n" \ + "8045841654642561594308\n" \ + "8655059576513659814468\n" \ + "8655059772157639814468\n" \ + "8655079374155679614468\n" \ + "8655079574515659614468\n" \ + "8888070771864228883913\n" +} + + +# +# Print the numbers of the appropriate length. +# +{ + if ($1 in rare_numbers) { + printf "%s", rare_numbers [$1] + } +} -- cgit From 19fbb299b0373513cfb92bf1faa8f65e3e7a315f Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 1 Mar 2021 12:40:53 +0100 Subject: Bash solution for week 102, part 1 --- challenge-102/abigail/README.md | 1 + challenge-102/abigail/bash/ch-1.sh | 146 +++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 challenge-102/abigail/bash/ch-1.sh diff --git a/challenge-102/abigail/README.md b/challenge-102/abigail/README.md index d196562cbb..1d139c2f94 100644 --- a/challenge-102/abigail/README.md +++ b/challenge-102/abigail/README.md @@ -17,6 +17,7 @@ for more information about it. ### Solutions * [AWK](awk/ch-1.awk) +* [Bash](bash/ch-1.sh) * [Perl](perl/ch-1.pl) diff --git a/challenge-102/abigail/bash/ch-1.sh b/challenge-102/abigail/bash/ch-1.sh new file mode 100644 index 0000000000..874ae78998 --- /dev/null +++ b/challenge-102/abigail/bash/ch-1.sh @@ -0,0 +1,146 @@ +#!/bin/sh + +# +# See ../README.md +# + +# +# Run as: bash ch-1.sh < input-file +# + +# +# Put the known rare numbers into an array +# +declare -a rare_numbers + +rare_numbers[ 2]="65\n" +rare_numbers[ 6]="621770\n" +rare_numbers[ 9]="281089082\n" +rare_numbers[10]="2022652202\n"\ +"2042832002\n" +rare_numbers[12]="868591084757\n"\ +"872546974178\n"\ +"872568754178\n" +rare_numbers[13]="6979302951885\n" +rare_numbers[14]="20313693904202\n"\ +"20313839704202\n"\ +"20331657922202\n"\ +"20331875722202\n"\ +"20333875702202\n"\ +"40313893704200\n"\ +"40351893720200\n" +rare_numbers[15]="200142385731002\n"\ +"204238494066002\n"\ +"221462345754122\n"\ +"244062891224042\n"\ +"245518996076442\n"\ +"248359494187442\n"\ +"403058392434500\n"\ +"441054594034340\n"\ +"816984566129618\n" +rare_numbers[16]="2078311262161202\n"\ +"2133786945766212\n"\ +"2135568943984212\n"\ +"2135764587964212\n"\ +"2135786765764212\n"\ +"4135786945764210\n"\ +"6157577986646405\n"\ +"6889765708183410\n"\ +"8052956026592517\n"\ +"8052956206592517\n"\ +"8191154686620818\n"\ +"8191156864620818\n"\ +"8191376864400818\n"\ +"8650327689541457\n"\ +"8650349867341457\n" +rare_numbers[17]="22542040692914522\n"\ +"67725910561765640\n"\ +"86965750494756968\n" +rare_numbers[18]="225342456863243522\n"\ +"225342458663243522\n"\ +"225342478643243522\n"\ +"284684666566486482\n"\ +"284684868364486482\n"\ +"297128548234950692\n"\ +"297128722852950692\n"\ +"297148324656930692\n"\ +"297148546434930692\n"\ +"497168548234910690\n"\ +"619431353040136925\n"\ +"619631153042134925\n"\ +"631688638047992345\n"\ +"633288858025996145\n"\ +"633488632647994145\n"\ +"653488856225994125\n"\ +"811865096390477018\n"\ +"865721270017296468\n"\ +"871975098681469178\n"\ +"898907259301737498\n" +rare_numbers[19]="2042401829204402402\n"\ +"2060303819041450202\n"\ +"2420424089100600242\n"\ +"2551755006254571552\n"\ +"2702373360882732072\n"\ +"2825378427312735282\n"\ +"6531727101458000045\n"\ +"6988066446726832640\n"\ +"8066308349502036608\n"\ +"8197906905009010818\n"\ +"8200756128308135597\n"\ +"8320411466598809138\n" +rare_numbers[20]="22134434735752443122\n"\ +"22134434753752443122\n"\ +"22134436953532443122\n"\ +"22136414517954423122\n"\ +"22136414971554423122\n"\ +"22136456771730423122\n"\ +"61952807156239928885\n"\ +"61999171315484316965\n"\ +"65459144877856561700\n" +rare_numbers[21]="208393425242000083802\n"\ +"219518549668074815912\n"\ +"257661195832219326752\n"\ +"286694688797362186682\n"\ +"837982875780054779738\n" +rare_numbers[22]="2414924301133245383042\n"\ +"2414924323311045383042\n"\ +"2414946523311023183042\n"\ +"2576494891793995836752\n"\ +"2576494893971995836752\n"\ +"2620937863931054483162\n"\ +"2620937863931054483162\n"\ +"2620955641393276283162\n"\ +"2622935621573476481162\n"\ +"2622935643751276481162\n"\ +"2622937641933274481162\n"\ +"2622955841933256281162\n"\ +"2622957843751254281162\n"\ +"2727651947516658327272\n"\ +"2747736918335953517072\n"\ +"2788047668617596408872\n"\ +"2788047848617776408872\n"\ +"2788047868437576408872\n"\ +"2788047888617376408872\n"\ +"2939501759705522349392\n"\ +"2939503375709360349392\n"\ +"2939503537707740349392\n"\ +"2939521359525562149392\n"\ +"2939521557527542149392\n"\ +"2939523577527340149392\n"\ +"2939523779525320149392\n"\ +"2959503377707360349192\n"\ +"6344828989519887483525\n"\ +"8045841652464561594308\n"\ +"8045841654642561594308\n"\ +"8655059576513659814468\n"\ +"8655059772157639814468\n"\ +"8655079374155679614468\n"\ +"8655079574515659614468\n"\ +"8888070771864228883913\n" + +# +# Read a length, and print the rare numbers of that length +# +while read length +do printf "${rare_numbers[$length]}" +done -- cgit From 3581c89b20bf6a99be20949bc0f71b8be7aba8a2 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 1 Mar 2021 13:00:09 +0100 Subject: C solution for week 102, part 1 --- challenge-102/abigail/README.md | 1 + challenge-102/abigail/c/ch-1.c | 164 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 165 insertions(+) create mode 100644 challenge-102/abigail/c/ch-1.c diff --git a/challenge-102/abigail/README.md b/challenge-102/abigail/README.md index 1d139c2f94..bea8dec9d5 100644 --- a/challenge-102/abigail/README.md +++ b/challenge-102/abigail/README.md @@ -18,6 +18,7 @@ for more information about it. ### Solutions * [AWK](awk/ch-1.awk) * [Bash](bash/ch-1.sh) +* [C](c/ch-1.c) * [Perl](perl/ch-1.pl) diff --git a/challenge-102/abigail/c/ch-1.c b/challenge-102/abigail/c/ch-1.c new file mode 100644 index 0000000000..564ffc732a --- /dev/null +++ b/challenge-102/abigail/c/ch-1.c @@ -0,0 +1,164 @@ +# include +# include +# include + +/* + * See ../README.md + */ + +/* + * Run as: cc -o ch-1.o ch-1.c; ./ch-1.o < input-file + */ + +# define NR_OF_KNOWN_RARE_NUMBERS 124 +# define MAX_RARE_NUMBER_LENGTH 22 + +/* + * Create a list of all known rare numbers. + */ +char * rare_numbers [23]; + +int main () { + rare_numbers [ 0] = NULL; + rare_numbers [ 1] = NULL; + rare_numbers [ 2] = "65\n"; + rare_numbers [ 3] = NULL; + rare_numbers [ 4] = NULL; + rare_numbers [ 5] = NULL; + rare_numbers [ 6] = "621770\n"; + rare_numbers [ 7] = NULL; + rare_numbers [ 8] = NULL; + rare_numbers [ 9] = "281089082\n"; + rare_numbers [10] = "2022652202\n" \ + "2042832002\n"; + rare_numbers [11] = NULL; + rare_numbers [12] = "868591084757\n" \ + "872546974178\n" \ + "872568754178\n"; + rare_numbers [13] = "6979302951885\n"; + rare_numbers [14] = "20313693904202\n" \ + "20313839704202\n" \ + "20331657922202\n" \ + "20331875722202\n" \ + "20333875702202\n" \ + "40313893704200\n" \ + "40351893720200\n"; + rare_numbers [15] = "200142385731002\n" \ + "204238494066002\n" \ + "221462345754122\n" \ + "244062891224042\n" \ + "245518996076442\n" \ + "248359494187442\n" \ + "403058392434500\n" \ + "441054594034340\n" \ + "816984566129618\n"; + rare_numbers [16] = "2078311262161202\n" \ + "2133786945766212\n" \ + "2135568943984212\n" \ + "2135764587964212\n" \ + "2135786765764212\n" \ + "4135786945764210\n" \ + "6157577986646405\n" \ + "6889765708183410\n" \ + "8052956026592517\n" \ + "8052956206592517\n" \ + "8191154686620818\n" \ + "8191156864620818\n" \ + "8191376864400818\n" \ + "8650327689541457\n" \ + "8650349867341457\n"; + rare_numbers [17] = "22542040692914522\n" \ + "67725910561765640\n" \ + "86965750494756968\n"; + rare_numbers [18] = "225342456863243522\n" \ + "225342458663243522\n" \ + "225342478643243522\n" \ + "284684666566486482\n" \ + "284684868364486482\n" \ + "297128548234950692\n" \ + "297128722852950692\n" \ + "297148324656930692\n" \ + "297148546434930692\n" \ + "497168548234910690\n" \ + "619431353040136925\n" \ + "619631153042134925\n" \ + "631688638047992345\n" \ + "633288858025996145\n" \ + "633488632647994145\n" \ + "653488856225994125\n" \ + "811865096390477018\n" \ + "865721270017296468\n" \ + "871975098681469178\n" \ + "898907259301737498\n"; + rare_numbers [19] = "2042401829204402402\n" \ + "2060303819041450202\n" \ + "2420424089100600242\n" \ + "2551755006254571552\n" \ + "2702373360882732072\n" \ + "2825378427312735282\n" \ + "6531727101458000045\n" \ + "6988066446726832640\n" \ + "8066308349502036608\n" \ + "8197906905009010818\n" \ + "8200756128308135597\n" \ + "8320411466598809138\n"; + rare_numbers [20] = "22134434735752443122\n" \ + "22134434753752443122\n" \ + "22134436953532443122\n" \ + "22136414517954423122\n" \ + "22136414971554423122\n" \ + "22136456771730423122\n" \ + "61952807156239928885\n" \ + "61999171315484316965\n" \ + "65459144877856561700\n"; + rare_numbers [21] = "208393425242000083802\n" \ + "219518549668074815912\n" \ + "257661195832219326752\n" \ + "286694688797362186682\n" \ + "837982875780054779738\n"; + rare_numbers [22] = "2414924301133245383042\n" \ + "2414924323311045383042\n" \ + "2414946523311023183042\n" \ + "2576494891793995836752\n" \ + "2576494893971995836752\n" \ + "2620937863931054483162\n" \ + "2620937863931054483162\n" \ + "2620955641393276283162\n" \ + "2622935621573476481162\n" \ + "2622935643751276481162\n" \ + "2622937641933274481162\n" \ + "2622955841933256281162\n" \ + "2622957843751254281162\n" \ + "2727651947516658327272\n" \ + "2747736918335953517072\n" \ + "2788047668617596408872\n" \ + "2788047848617776408872\n" \ + "2788047868437576408872\n" \ + "2788047888617376408872\n" \ + "2939501759705522349392\n" \ + "2939503375709360349392\n" \ + "2939503537707740349392\n" \ + "2939521359525562149392\n" \ + "2939521557527542149392\n" \ + "2939523577527340149392\n" \ + "2939523779525320149392\n" \ + "2959503377707360349192\n" \ + "6344828989519887483525\n" \ + "8045841652464561594308\n" \ + "8045841654642561594308\n" \ + "8655059576513659814468\n" \ + "8655059772157639814468\n" \ + "8655079374155679614468\n" \ + "8655079574515659614468\n" \ + "8888070771864228883913\n"; + + int length; + + while (scanf ("%d", &length) > 0) { + if (length >= 0 && length <= MAX_RARE_NUMBER_LENGTH && + rare_numbers [length] != NULL) { + printf ("%s", rare_numbers [length]); + } + } + return (0); +} -- cgit From 76e80dfbab5a04e6eb9849b0c878af4f5cb4d025 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 1 Mar 2021 17:48:28 +0100 Subject: Tests for largest input --- challenge-102/abigail/t/ctest.ini | 1 + challenge-102/abigail/t/input-1-7 | 2 ++ challenge-102/abigail/t/output-1-7.exp | 0 3 files changed, 3 insertions(+) create mode 100644 challenge-102/abigail/t/input-1-7 create mode 100644 challenge-102/abigail/t/output-1-7.exp diff --git a/challenge-102/abigail/t/ctest.ini b/challenge-102/abigail/t/ctest.ini index 6daf69e9fe..9138922364 100644 --- a/challenge-102/abigail/t/ctest.ini +++ b/challenge-102/abigail/t/ctest.ini @@ -5,4 +5,5 @@ 1-4 = Multiple numbers of given length 1-5 = No numbers of given length 1-6 = Multiple inputs +1-7 = Exceed size of largest known rare number 2-1 = Given examples diff --git a/challenge-102/abigail/t/input-1-7 b/challenge-102/abigail/t/input-1-7 new file mode 100644 index 0000000000..725eaa89cc --- /dev/null +++ b/challenge-102/abigail/t/input-1-7 @@ -0,0 +1,2 @@ +23 +100 diff --git a/challenge-102/abigail/t/output-1-7.exp b/challenge-102/abigail/t/output-1-7.exp new file mode 100644 index 0000000000..e69de29bb2 -- cgit From 02aa5118161656e1d8627843fbbb8f4041ea4015 Mon Sep 17 00:00:00 2001 From: Abigail Date: Tue, 2 Mar 2021 01:21:09 +0100 Subject: Lua solution for week 102, part 1 --- challenge-102/abigail/lua/ch-1.lua | 149 +++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 challenge-102/abigail/lua/ch-1.lua diff --git a/challenge-102/abigail/lua/ch-1.lua b/challenge-102/abigail/lua/ch-1.lua new file mode 100644 index 0000000000..b36b2dd81b --- /dev/null +++ b/challenge-102/abigail/lua/ch-1.lua @@ -0,0 +1,149 @@ +#!/opt/local/bin/lua + +-- +-- See ../README.md +-- + +-- +-- Run as: lua ch-1.lua < input-file +-- + +-- +-- Load the known rare numbers into an array, bucketed by length. +-- + +rare_numbers = {} +rare_numbers [ 2] = "65\n" +rare_numbers [ 6] = "621770\n" +rare_numbers [ 9] = "281089082\n" +rare_numbers [10] = "2022652202\n" .. + "2042832002\n" +rare_numbers [12] = "868591084757\n" .. + "872546974178\n" .. + "872568754178\n" +rare_numbers [13] = "6979302951885\n" +rare_numbers [14] = "20313693904202\n" .. + "20313839704202\n" .. + "20331657922202\n" .. + "20331875722202\n" .. + "20333875702202\n" .. + "40313893704200\n" .. + "40351893720200\n" +rare_numbers [15] = "200142385731002\n" .. + "204238494066002\n" .. + "221462345754122\n" .. + "244062891224042\n" .. + "245518996076442\n" .. + "248359494187442\n" .. + "403058392434500\n" .. + "441054594034340\n" .. + "816984566129618\n" +rare_numbers [16] = "2078311262161202\n" .. + "2133786945766212\n" .. + "2135568943984212\n" .. + "2135764587964212\n" .. + "2135786765764212\n" .. + "4135786945764210\n" .. + "6157577986646405\n" .. + "6889765708183410\n" .. + "8052956026592517\n" .. + "8052956206592517\n" .. + "8191154686620818\n" .. + "8191156864620818\n" .. + "8191376864400818\n" .. + "8650327689541457\n" .. + "8650349867341457\n" +rare_numbers [17] = "22542040692914522\n" .. + "67725910561765640\n" .. + "86965750494756968\n" +rare_numbers [18] = "225342456863243522\n" .. + "225342458663243522\n" .. + "225342478643243522\n" .. + "284684666566486482\n" .. + "284684868364486482\n" .. + "297128548234950692\n" .. + "297128722852950692\n" .. + "297148324656930692\n" .. + "297148546434930692\n" .. + "497168548234910690\n" .. + "619431353040136925\n" .. + "619631153042134925\n" .. + "631688638047992345\n" .. + "633288858025996145\n" .. + "633488632647994145\n" .. + "653488856225994125\n" .. + "811865096390477018\n" .. + "865721270017296468\n" .. + "871975098681469178\n" .. + "898907259301737498\n" +rare_numbers [19] = "2042401829204402402\n" .. + "2060303819041450202\n" .. + "2420424089100600242\n" .. + "2551755006254571552\n" .. + "2702373360882732072\n" .. + "2825378427312735282\n" .. + "6531727101458000045\n" .. + "6988066446726832640\n" .. + "8066308349502036608\n" .. + "8197906905009010818\n" .. + "8200756128308135597\n" .. + "8320411466598809138\n" +rare_numbers [20] = "22134434735752443122\n" .. + "22134434753752443122\n" .. + "22134436953532443122\n" .. + "22136414517954423122\n" .. + "22136414971554423122\n" .. + "22136456771730423122\n" .. + "61952807156239928885\n" .. + "61999171315484316965\n" .. + "65459144877856561700\n" +rare_numbers [21] = "208393425242000083802\n" .. + "219518549668074815912\n" .. + "257661195832219326752\n" .. + "286694688797362186682\n" .. + "837982875780054779738\n" +rare_numbers [22] = "2414924301133245383042\n" .. + "2414924323311045383042\n" .. + "2414946523311023183042\n" .. + "2576494891793995836752\n" .. + "2576494893971995836752\n" .. + "2620937863931054483162\n" .. + "2620937863931054483162\n" .. + "2620955641393276283162\n" .. + "2622935621573476481162\n" .. + "2622935643751276481162\n" .. + "2622937641933274481162\n" .. + "2622955841933256281162\n" .. + "2622957843751254281162\n" .. + "2727651947516658327272\n" .. + "2747736918335953517072\n" .. + "2788047668617596408872\n" .. + "2788047848617776408872\n" .. + "2788047868437576408872\n" .. + "2788047888617376408872\n" .. + "2939501759705522349392\n" .. + "2939503375709360349392\n" .. + "2939503537707740349392\n" .. + "2939521359525562149392\n" .. + "2939521557527542149392\n" .. + "2939523577527340149392\n" .. + "2939523779525320149392\n" .. + "2959503377707360349192\n" .. + "6344828989519887483525\n" .. + "8045841652464561594308\n" .. + "8045841654642561594308\n" .. + "8655059576513659814468\n" .. + "8655059772157639814468\n" .. + "8655079374155679614468\n" .. + "8655079574515659614468\n" .. + "8888070771864228883913\n" + +-- +-- Print the wanted rare numbers, if they exist. +-- +for length in io . lines () do + length = tonumber (length) + if rare_numbers [length] + then io . write (rare_numbers [length]) + end +end -- cgit From 9545037ae529b08ae3eb97e297c5d5a43a62e25b Mon Sep 17 00:00:00 2001 From: Abigail Date: Tue, 2 Mar 2021 01:57:17 +0100 Subject: Node.js solution for week 102, part 1 --- challenge-102/abigail/README.md | 2 + challenge-102/abigail/node/ch-1.js | 148 +++++++++++++++++++++++++++++++++++++ 2 files changed, 150 insertions(+) create mode 100644 challenge-102/abigail/node/ch-1.js diff --git a/challenge-102/abigail/README.md b/challenge-102/abigail/README.md index bea8dec9d5..f9c2bb3b98 100644 --- a/challenge-102/abigail/README.md +++ b/challenge-102/abigail/README.md @@ -19,6 +19,8 @@ for more information about it. * [AWK](awk/ch-1.awk) * [Bash](bash/ch-1.sh) * [C](c/ch-1.c) +* [Lua](lua/ch-1.lua) +* [Node.js](node/ch-1.js) * [Perl](perl/ch-1.pl) diff --git a/challenge-102/abigail/node/ch-1.js b/challenge-102/abigail/node/ch-1.js new file mode 100644 index 0000000000..0fe6a25165 --- /dev/null +++ b/challenge-102/abigail/node/ch-1.js @@ -0,0 +1,148 @@ +#!/usr/local/bin/node + +// +// See ../README.md +// + +// +// Run as: node ch-1.js < input-file +// + +// +// Create a list of know rare numbers, bucketed by their lengths. +// + +let rare_numbers = [] + +rare_numbers [ 2] = "65\n" +rare_numbers [ 6] = "621770\n" +rare_numbers [ 9] = "281089082\n" +rare_numbers [10] = "2022652202\n" + + "2042832002\n" +rare_numbers [12] = "868591084757\n" + + "872546974178\n" + + "872568754178\n" +rare_numbers [13] = "6979302951885\n" +rare_numbers [14] = "20313693904202\n" + + "20313839704202\n" + + "20331657922202\n" + + "20331875722202\n" + + "20333875702202\n" + + "40313893704200\n" + + "40351893720200\n" +rare_numbers [15] = "200142385731002\n" + + "204238494066002\n" + + "221462345754122\n" + + "244062891224042\n" + + "245518996076442\n" + + "248359494187442\n" + + "403058392434500\n" + + "441054594034340\n" + + "816984566129618\n" +rare_numbers [16] = "2078311262161202\n" + + "2133786945766212\n" + + "2135568943984212\n" + + "2135764587964212\n" + + "2135786765764212\n" + + "4135786945764210\n" + + "6157577986646405\n" + + "6889765708183410\n" + + "8052956026592517\n" + + "8052956206592517\n" + + "8191154686620818\n" + + "8191156864620818\n" + + "8191376864400818\n" + + "8650327689541457\n" + + "8650349867341457\n" +rare_numbers [17] = "22542040692914522\n" + + "67725910561765640\n" + + "86965750494756968\n" +rare_numbers [18] = "225342456863243522\n" + + "225342458663243522\n" + + "225342478643243522\n" + + "284684666566486482\n" + + "284684868364486482\n" + + "297128548234950692\n" + + "297128722852950692\n" + + "297148324656930692\n" + + "297148546434930692\n" + + "497168548234910690\n" + + "619431353040136925\n" + + "619631153042134925\n" + + "631688638047992345\n" + + "633288858025996145\n" + + "633488632647994145\n" + + "653488856225994125\n" + + "811865096390477018\n" + + "865721270017296468\n" + + "871975098681469178\n" + + "898907259301737498\n" +rare_numbers [19] = "2042401829204402402\n" + + "2060303819041450202\n" + + "2420424089100600242\n" + + "2551755006254571552\n" + + "2702373360882732072\n" + + "2825378427312735282\n" + + "6531727101458000045\n" + + "6988066446726832640\n" + + "8066308349502036608\n" + + "8197906905009010818\n" + + "8200756128308135597\n" + + "8320411466598809138\n" +rare_numbers [20] = "22134434735752443122\n" + + "22134434753752443122\n" + + "22134436953532443122\n" + + "22136414517954423122\n" + + "22136414971554423122\n" + +