aboutsummaryrefslogtreecommitdiff
path: root/challenge-100
diff options
context:
space:
mode:
authorboblied <boblied@gmail.com>2021-03-09 07:52:31 -0600
committerboblied <boblied@gmail.com>2021-03-09 07:52:31 -0600
commitc897ab614e0a35455865bfe930df300bb854a03b (patch)
treea6a3527b8364196045a94ab49661bd2eb9c8fea6 /challenge-100
parent199d363b79e769bf8dc150bf37228395bfbb4d16 (diff)
parentda7e149ecb3abdf29d3fb4f712427217d02f2fe1 (diff)
downloadperlweeklychallenge-club-c897ab614e0a35455865bfe930df300bb854a03b.tar.gz
perlweeklychallenge-club-c897ab614e0a35455865bfe930df300bb854a03b.tar.bz2
perlweeklychallenge-club-c897ab614e0a35455865bfe930df300bb854a03b.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-100')
-rw-r--r--challenge-100/adam-russell/ch-1.dat1
-rw-r--r--challenge-100/duncan-c-white/perl/mkTypes200
-rw-r--r--challenge-100/paulo-custodio/ada/ch_1.adb2
-rw-r--r--challenge-100/paulo-custodio/ada/ch_2.adb2
-rw-r--r--challenge-100/paulo-custodio/awk/ch-1.awk2
-rw-r--r--challenge-100/paulo-custodio/awk/ch-2.awk2
-rw-r--r--challenge-100/paulo-custodio/basic/ch-2.bas2
-rw-r--r--challenge-100/paulo-custodio/c/ch-1.c2
-rw-r--r--challenge-100/paulo-custodio/c/ch-2.c2
-rw-r--r--challenge-100/paulo-custodio/cpp/ch-1.cpp2
-rw-r--r--challenge-100/paulo-custodio/cpp/ch-2.cpp2
-rw-r--r--challenge-100/paulo-custodio/forth/ch-1.fs2
-rw-r--r--challenge-100/paulo-custodio/forth/ch-2.fs2
-rw-r--r--challenge-100/paulo-custodio/lua/ch-2.lua2
-rw-r--r--challenge-100/paulo-custodio/perl/ch-1.pl2
-rw-r--r--challenge-100/paulo-custodio/perl/ch-2.pl2
-rw-r--r--challenge-100/paulo-custodio/python/ch-1.py2
-rw-r--r--challenge-100/paulo-custodio/python/ch-2.py2
18 files changed, 233 insertions, 0 deletions
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-100/paulo-custodio/ada/ch_1.adb b/challenge-100/paulo-custodio/ada/ch_1.adb
index e5f362c639..c2bd973b79 100644
--- a/challenge-100/paulo-custodio/ada/ch_1.adb
+++ b/challenge-100/paulo-custodio/ada/ch_1.adb
@@ -1,3 +1,5 @@
+-- Challenge 100
+--
-- TASK #1 > Fun Time
-- Submitted by: Mohammad S Anwar
-- You are given a time (12 hour / 24 hour).
diff --git a/challenge-100/paulo-custodio/ada/ch_2.adb b/challenge-100/paulo-custodio/ada/ch_2.adb
index 36d95ef473..b54340b46f 100644
--- a/challenge-100/paulo-custodio/ada/ch_2.adb
+++ b/challenge-100/paulo-custodio/ada/ch_2.adb
@@ -1,3 +1,5 @@
+-- Challenge 100
+--
-- TASK #2 > Triangle Sum
-- Submitted by: Mohammad S Anwar
-- You are given triangle array.
diff --git a/challenge-100/paulo-custodio/awk/ch-1.awk b/challenge-100/paulo-custodio/awk/ch-1.awk
index 83c0caffe6..9f99dbf8d1 100644
--- a/challenge-100/paulo-custodio/awk/ch-1.awk
+++ b/challenge-100/paulo-custodio/awk/ch-1.awk
@@ -1,5 +1,7 @@
#!/usr/bin/gawk
+# Challenge 100
+#
# TASK #1 > Fun Time
# Submitted by: Mohammad S Anwar
# You are given a time (12 hour / 24 hour).
diff --git a/challenge-100/paulo-custodio/awk/ch-2.awk b/challenge-100/paulo-custodio/awk/ch-2.awk
index 77fac41676..e063082aca 100644
--- a/challenge-100/paulo-custodio/awk/ch-2.awk
+++ b/challenge-100/paulo-custodio/awk/ch-2.awk
@@ -1,5 +1,7 @@
#!/usr/bin/gawk
+# Challenge 100
+#
# TASK #2 > Triangle Sum
# Submitted by: Mohammad S Anwar
# You are given triangle array.
diff --git a/challenge-100/paulo-custodio/basic/ch-2.bas b/challenge-100/paulo-custodio/basic/ch-2.bas
index 6ba0800802..407b0f24ea 100644
--- a/challenge-100/paulo-custodio/basic/ch-2.bas
+++ b/challenge-100/paulo-custodio/basic/ch-2.bas
@@ -1,3 +1,5 @@
+' Challenge 100
+'
' TASK #2 > Triangle Sum
' Submitted by: Mohammad S Anwar
' You are given triangle array.
diff --git a/challenge-100/paulo-custodio/c/ch-1.c b/challenge-100/paulo-custodio/c/ch-1.c
index d0a33a1f36..9638b7d656 100644
--- a/challenge-100/paulo-custodio/c/ch-1.c
+++ b/challenge-100/paulo-custodio/c/ch-1.c
@@ -1,4 +1,6 @@
/*
+Challenge 100
+
TASK #1 > Fun Time
Submitted by: Mohammad S Anwar
You are given a time (12 hour / 24 hour).
diff --git a/challenge-100/paulo-custodio/c/ch-2.c b/challenge-100/paulo-custodio/c/ch-2.c
index 1d68e1d2d6..6a772d3a01 100644
--- a/challenge-100/paulo-custodio/c/ch-2.c
+++ b/challenge-100/paulo-custodio/c/ch-2.c
@@ -1,4 +1,6 @@
/*
+Challenge 100
+
TASK #2 > Triangle Sum
Submitted by: Mohammad S Anwar
You are given triangle array.
diff --git a/challenge-100/paulo-custodio/cpp/ch-1.cpp b/challenge-100/paulo-custodio/cpp/ch-1.cpp
index 0516a4bd31..115f577c53 100644
--- a/challenge-100/paulo-custodio/cpp/ch-1.cpp
+++ b/challenge-100/paulo-custodio/cpp/ch-1.cpp
@@ -1,4 +1,6 @@
/*
+Challenge 100
+
TASK #1 > Fun Time
Submitted by: Mohammad S Anwar
You are given a time (12 hour / 24 hour).
diff --git a/challenge-100/paulo-custodio/cpp/ch-2.cpp b/challenge-100/paulo-custodio/cpp/ch-2.cpp
index b672a5cffe..c94b0355a3 100644
--- a/challenge-100/paulo-custodio/cpp/ch-2.cpp
+++ b/challenge-100/paulo-custodio/cpp/ch-2.cpp
@@ -1,4 +1,6 @@
/*
+Challenge 100
+
TASK #2 > Triangle Sum
Submitted by: Mohammad S Anwar
You are given triangle array.
diff --git a/challenge-100/paulo-custodio/forth/ch-1.fs b/challenge-100/paulo-custodio/forth/ch-1.fs
index a4008e5be2..6289a61a34 100644
--- a/challenge-100/paulo-custodio/forth/ch-1.fs
+++ b/challenge-100/paulo-custodio/forth/ch-1.fs
@@ -1,5 +1,7 @@
#! /usr/bin/env gforth
+\ Challenge 100
+\
\ TASK #1 > Fun Time
\ Submitted by: Mohammad S Anwar
\ You are given a time (12 hour / 24 hour).
diff --git a/challenge-100/paulo-custodio/forth/ch-2.fs b/challenge-100/paulo-custodio/forth/ch-2.fs
index 7592af483c..e792301d4e 100644
--- a/challenge-100/paulo-custodio/forth/ch-2.fs
+++ b/challenge-100/paulo-custodio/forth/ch-2.fs
@@ -1,5 +1,7 @@
#! /usr/bin/env gforth
+\ Challenge 100
+\
\ TASK #2 > Triangle Sum
\ Submitted by: Mohammad S Anwar
\ You are given triangle array.
diff --git a/challenge-100/paulo-custodio/lua/ch-2.lua b/challenge-100/paulo-custodio/lua/ch-2.lua
index 9f917fe53a..2c73edb907 100644
--- a/challenge-100/paulo-custodio/lua/ch-2.lua
+++ b/challenge-100/paulo-custodio/lua/ch-2.lua
@@ -1,6 +1,8 @@
#!/usr/bin/env lua
--[[
+Challenge 100
+
TASK #2 > Triangle Sum
Submitted by: Mohammad S Anwar
You are given triangle array.
diff --git a/challenge-100/paulo-custodio/perl/ch-1.pl b/challenge-100/paulo-custodio/perl/ch-1.pl
index c45d44b567..baade5121c 100644
--- a/challenge-100/paulo-custodio/perl/ch-1.pl
+++ b/challenge-100/paulo-custodio/perl/ch-1.pl
@@ -1,5 +1,7 @@
#!/usr/bin/perl
+# Challenge 100
+#
# TASK #1 > Fun Time
# Submitted by: Mohammad S Anwar
# You are given a time (12 hour / 24 hour).
diff --git a/challenge-100/paulo-custodio/perl/ch-2.pl b/challenge-100/paulo-custodio/perl/ch-2.pl
index 7221ce2880..9f78a241ba 100644
--- a/challenge-100/paulo-custodio/perl/ch-2.pl
+++ b/challenge-100/paulo-custodio/perl/ch-2.pl
@@ -1,5 +1,7 @@
#!/usr/bin/perl
+# Challenge 100
+#
# TASK #2 > Triangle Sum
# Submitted by: Mohammad S Anwar
# You are given triangle array.
diff --git a/challenge-100/paulo-custodio/python/ch-1.py b/challenge-100/paulo-custodio/python/ch-1.py
index 818624d76b..7cabc2f1a7 100644
--- a/challenge-100/paulo-custodio/python/ch-1.py
+++ b/challenge-100/paulo-custodio/python/ch-1.py
@@ -1,5 +1,7 @@
#!/usr/bin/env python
+# Challenge 100
+#
# TASK #1 > Fun Time
# Submitted by: Mohammad S Anwar
# You are given a time (12 hour / 24 hour).
diff --git a/challenge-100/paulo-custodio/python/ch-2.py b/challenge-100/paulo-custodio/python/ch-2.py
index 9491b675e0..1f27d99c01 100644
--- a/challenge-100/paulo-custodio/python/ch-2.py
+++ b/challenge-100/paulo-custodio/python/ch-2.py
@@ -1,5 +1,7 @@
#!/usr/bin/env python
+# Challenge 100
+#
# TASK #2 > Triangle Sum
# Submitted by: Mohammad S Anwar
# You are given triangle array.