aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Smith <js5@sanger.ac.uk>2022-12-09 00:29:56 +0000
committerGitHub <noreply@github.com>2022-12-09 00:29:56 +0000
commit0a90986281b28beb73de5b63f935dd6ee9670d73 (patch)
treeed296ab2fb455aedeaf83bb6cb9e5faf749c6af0
parente0dd4b5e72551ca1412554f0b9d11c62a3b08af0 (diff)
parent14e3c6a41685893e9a7a830d98fabe069bc4d0b5 (diff)
downloadperlweeklychallenge-club-0a90986281b28beb73de5b63f935dd6ee9670d73.tar.gz
perlweeklychallenge-club-0a90986281b28beb73de5b63f935dd6ee9670d73.tar.bz2
perlweeklychallenge-club-0a90986281b28beb73de5b63f935dd6ee9670d73.zip
Merge branch 'manwar:master' into master
-rw-r--r--challenge-193/duncan-c-white/C/.cbuild2
-rw-r--r--challenge-193/duncan-c-white/C/Makefile4
-rw-r--r--challenge-193/duncan-c-white/C/README8
-rw-r--r--challenge-193/duncan-c-white/C/ch-2.c200
-rwxr-xr-xchallenge-193/duncan-c-white/perl/ch-2.pl6
-rwxr-xr-xchallenge-194/LoneWolfiNTj/perl/ch-1.pl62
-rwxr-xr-xchallenge-194/LoneWolfiNTj/perl/ch-2.pl52
-rw-r--r--challenge-194/dave-jacoby/perl/ch-1.pl35
-rw-r--r--challenge-194/dave-jacoby/perl/ch-2.pl42
-rwxr-xr-xchallenge-194/eric-cheung/python/ch-1.py34
-rwxr-xr-xchallenge-194/eric-cheung/python/ch-2.py24
-rwxr-xr-xchallenge-194/feng-chang/raku/ch-1.raku8
-rwxr-xr-xchallenge-194/feng-chang/raku/ch-2.raku8
-rwxr-xr-xchallenge-194/jeanluc2020/perl/ch-1.pl43
-rwxr-xr-xchallenge-194/jeanluc2020/perl/ch-2.pl43
-rw-r--r--challenge-194/luca-ferrari/blog-1.txt1
-rw-r--r--challenge-194/luca-ferrari/blog-2.txt1
-rw-r--r--challenge-194/luca-ferrari/blog-3.txt1
-rw-r--r--challenge-194/luca-ferrari/blog-4.txt1
-rw-r--r--challenge-194/luca-ferrari/blog-5.txt1
-rw-r--r--challenge-194/luca-ferrari/blog-6.txt1
-rw-r--r--challenge-194/luca-ferrari/postgresql/ch-1.plperl31
-rw-r--r--challenge-194/luca-ferrari/postgresql/ch-1.sql39
-rw-r--r--challenge-194/luca-ferrari/postgresql/ch-2.plperl26
-rw-r--r--challenge-194/luca-ferrari/postgresql/ch-2.sql46
-rw-r--r--challenge-194/luca-ferrari/raku/ch-1.p614
-rw-r--r--challenge-194/luca-ferrari/raku/ch-2.p615
-rw-r--r--challenge-194/mark-anderson/raku/ch-1.raku24
-rw-r--r--challenge-194/mark-anderson/raku/ch-2.raku14
-rwxr-xr-xchallenge-194/perlboy1967/perl/ch-1.pl50
-rwxr-xr-xchallenge-194/perlboy1967/perl/ch-2.pl40
-rw-r--r--challenge-194/polettix/blog.txt1
-rw-r--r--challenge-194/polettix/blog1.txt1
-rw-r--r--challenge-194/polettix/perl/ch-1.pl16
-rw-r--r--challenge-194/polettix/perl/ch-2.pl19
-rw-r--r--challenge-194/polettix/raku/ch-1.raku14
-rw-r--r--challenge-194/polettix/raku/ch-2.raku17
-rw-r--r--challenge-194/robert-dicicco/julia/ch-1.jl109
-rw-r--r--challenge-194/robert-dicicco/julia/ch-2.jl75
-rw-r--r--challenge-194/robert-dicicco/perl/ch-1.pl129
-rw-r--r--challenge-194/robert-dicicco/perl/ch-2.pl87
-rw-r--r--challenge-194/robert-dicicco/python/ch-1.py97
-rw-r--r--challenge-194/robert-dicicco/python/ch-2.py81
-rw-r--r--challenge-194/robert-dicicco/raku/ch-1.raku119
-rw-r--r--challenge-194/robert-dicicco/raku/ch-2.raku81
-rw-r--r--challenge-194/robert-dicicco/ruby/ch-1.rb101
-rw-r--r--challenge-194/robert-dicicco/ruby/ch-2.rb85
-rwxr-xr-xchallenge-194/roger-bell-west/javascript/ch-1.js65
-rwxr-xr-xchallenge-194/roger-bell-west/javascript/ch-2.js41
-rw-r--r--challenge-194/roger-bell-west/kotlin/ch-1.kt58
-rw-r--r--challenge-194/roger-bell-west/kotlin/ch-2.kt34
-rwxr-xr-xchallenge-194/roger-bell-west/lua/ch-1.lua58
-rwxr-xr-xchallenge-194/roger-bell-west/lua/ch-2.lua43
-rwxr-xr-xchallenge-194/roger-bell-west/perl/ch-1.pl34
-rwxr-xr-xchallenge-194/roger-bell-west/perl/ch-2.pl24
-rw-r--r--challenge-194/roger-bell-west/postscript/ch-1.ps84
-rw-r--r--challenge-194/roger-bell-west/postscript/ch-2.ps141
-rwxr-xr-xchallenge-194/roger-bell-west/python/ch-1.py41
-rwxr-xr-xchallenge-194/roger-bell-west/python/ch-2.py27
-rwxr-xr-xchallenge-194/roger-bell-west/raku/ch-1.p632
-rwxr-xr-xchallenge-194/roger-bell-west/raku/ch-2.p622
-rwxr-xr-xchallenge-194/roger-bell-west/ruby/ch-1.rb51
-rwxr-xr-xchallenge-194/roger-bell-west/ruby/ch-2.rb34
-rwxr-xr-xchallenge-194/roger-bell-west/rust/ch-1.rs53
-rwxr-xr-xchallenge-194/roger-bell-west/rust/ch-2.rs34
-rw-r--r--challenge-194/vamsi-meenavilli/perl/ch-1.pl57
-rw-r--r--challenge-194/vamsi-meenavilli/perl/ch-2.pl42
-rw-r--r--challenge-194/vamsi-meenavilli/python/ch-1.py51
-rw-r--r--challenge-194/vamsi-meenavilli/python/ch-2.py41
-rw-r--r--challenge-194/wlmb/blog.txt1
-rwxr-xr-xchallenge-194/wlmb/perl/ch-1.pl17
-rwxr-xr-xchallenge-194/wlmb/perl/ch-2.pl17
-rwxr-xr-xchallenge-194/wlmb/perl/ch-2a.pl17
-rwxr-xr-xchallenge-194/zapwai/perl/ch-1.pl27
-rwxr-xr-xchallenge-194/zapwai/perl/ch-2.pl48
-rw-r--r--challenge-194/ziameraj16/java/DigitalClock.java33
-rw-r--r--stats/pwc-challenge-193.json695
-rw-r--r--stats/pwc-current.json510
-rw-r--r--stats/pwc-language-breakdown-summary.json78
-rw-r--r--stats/pwc-language-breakdown.json2721
-rw-r--r--stats/pwc-leaders.json444
-rw-r--r--stats/pwc-summary-1-30.json46
-rw-r--r--stats/pwc-summary-121-150.json38
-rw-r--r--stats/pwc-summary-151-180.json60
-rw-r--r--stats/pwc-summary-181-210.json98
-rw-r--r--stats/pwc-summary-211-240.json58
-rw-r--r--stats/pwc-summary-241-270.json108
-rw-r--r--stats/pwc-summary-271-300.json58
-rw-r--r--stats/pwc-summary-31-60.json114
-rw-r--r--stats/pwc-summary-61-90.json52
-rw-r--r--stats/pwc-summary-91-120.json120
-rw-r--r--stats/pwc-summary.json84
92 files changed, 5932 insertions, 2487 deletions
diff --git a/challenge-193/duncan-c-white/C/.cbuild b/challenge-193/duncan-c-white/C/.cbuild
index 624a95ebfb..a14ec76520 100644
--- a/challenge-193/duncan-c-white/C/.cbuild
+++ b/challenge-193/duncan-c-white/C/.cbuild
@@ -1,4 +1,4 @@
-BUILD = ch-1
+BUILD = ch-1 ch-2
CFLAGS = -Wall -g
#LDFLAGS = -lm
#CFLAGS = -g
diff --git a/challenge-193/duncan-c-white/C/Makefile b/challenge-193/duncan-c-white/C/Makefile
index e9ebaeaa96..8d85c7d16d 100644
--- a/challenge-193/duncan-c-white/C/Makefile
+++ b/challenge-193/duncan-c-white/C/Makefile
@@ -1,7 +1,7 @@
# Makefile rules generated by CB
CC = gcc
CFLAGS = -Wall -g
-BUILD = ch-1
+BUILD = ch-1 ch-2
all: $(BUILD)
@@ -11,4 +11,6 @@ clean:
args.o: args.c
ch-1: ch-1.o args.o
ch-1.o: ch-1.c args.h
+ch-2: ch-2.o args.o
+ch-2.o: ch-2.c args.h
diff --git a/challenge-193/duncan-c-white/C/README b/challenge-193/duncan-c-white/C/README
index 6664968152..a5adc6cda7 100644
--- a/challenge-193/duncan-c-white/C/README
+++ b/challenge-193/duncan-c-white/C/README
@@ -1,7 +1,7 @@
-Thought I'd also have a go at translating ch-1.pl into C..
+Thought I'd also have a go at translating ch-1.pl and ch-2.pl into C..
-It produces near-identical (non-debugging and even debugging) output to the
-Perl original.
+Both C versions produce near-identical (non-debugging and even debugging)
+output to the Perl originals.
-It uses one of my regular support modules:
+They use one of my regular support modules:
- a command-line argument processing module args.[ch]
diff --git a/challenge-193/duncan-c-white/C/ch-2.c b/challenge-193/duncan-c-white/C/ch-2.c
new file mode 100644
index 0000000000..2a525f28ec
--- /dev/null
+++ b/challenge-193/duncan-c-white/C/ch-2.c
@@ -0,0 +1,200 @@
+//
+// Task 2: Odd Strings
+//
+// C version.
+//
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+#include <ctype.h>
+#include <assert.h>
+
+#include "args.h"
+
+
+//
+// char *diffsig = diffsig(str);
+//
+// Given an alphabetic string $str, form and return the difference signature.
+// (a malloc()d string, the caller is responsible for freeing it later).
+//
+char * diffsig( char *str )
+{
+ int len = strlen(str);
+ assert( len > 1 );
+ char *result = malloc( 4 * len + 2 ); // 4 * len: optional -, 1 or 2
+ // digits and a comma:
+ // then add a bit:-)
+ assert( result != NULL );
+
+ char *rp = result; // rp will walk the result, appending chars
+ *rp = '\0'; // let's keep it nul-terminated always
+
+ // foreach char *p that is not the last
+ for( char *p=str; *(p+1) != '\0'; p++ )
+ {
+ if( p>str ) *rp++ = ',';
+ sprintf( rp, "%d", *(p+1)-*p );
+ while( *rp != '\0' ) rp++;
+ }
+
+ //printf( "debug: diffstr(%s) = %s\n", str, result );
+ return result;
+}
+
+
+//
+// lowercase(str);
+// lowercase str in place.
+//
+void lowercase( char *str )
+{
+ for( char *p=str; *p; p++ )
+ {
+ *p = tolower(*p);
+ }
+}
+
+
+// a (string, diffsig) pair
+typedef struct
+{
+ char *str;
+ char *sig;
+} pair;
+
+
+// qsort comparator for a pair.. couldn't resist the name..
+static int compair( const void *a, const void *b )
+{
+ pair *p = (pair *)a;
+ pair *q = (pair *)b;
+ return strcmp( p->sig, q->sig );
+}
+
+
+// a ptr to a function taking a signature and list[from]..list[to]
+// comprising all the strings with that signature.
+typedef void (*sigcallback)( char *sig, pair *list, int from, int to );
+
+
+//
+// find_freq_sigs( list, nel, cb );
+// given a sorted list of nel pairs, locate each set of strings
+// with distinct signatures, and call the cb function for each
+// set found.
+//
+void find_freq_sigs( pair *list, int nel, sigcallback cb )
+{
+ char *sig = "";
+ int from = -1;
+ int to = -1;
+ for( int i=0; i<nel; i++ )
+ {
+ if( strcmp( sig, list[i].sig ) != 0 )
+ {
+ // found different signature list[i].sig
+ // deal with previous set
+ if( *sig != '\0' )
+ {
+ (*cb)( sig, list, from, to );
+ }
+
+ from = i;
+ to = i;
+ sig = list[i].sig;
+ } else
+ {
+ to++;
+ }
+ }
+ // deal with final set
+ if( *sig != '\0' )
+ {
+ (*cb)( sig, list, from, to );
+ }
+}
+
+
+static void printsigset( char *sig, pair *list, int from, int to )
+{
+ int freq = to-from+1;
+ //printf( "sig %s: list[%d]=%s..list[%d]=%s, freq %d\n",
+ // sig, from, list[from].str, to, list[to].str, freq );
+ if( freq == 1 )
+ {
+ if( debug )
+ {
+ printf( "unique sig %s: %s\n", sig, list[from].str );
+ } else
+ {
+ printf( "%s\n", list[from].str );
+ }
+ }
+}
+
+
+int main( int argc, char **argv )
+{
+ int argno = process_flag_n_m_args( "odd-strings", argc, argv,
+ 1, 100, "strlist" );
+
+ if( debug )
+ {
+ printf( "debug: argno=%d, argc=%d\n", argno, argc );
+ }
+
+ pair list[argc-argno]; // list[i-argno].str : argv[i],
+ // list[i-argno].sig : diffsig(lc(argv[i]))
+
+ // build list.. indexes 0..argc-argno-1
+ int nel=0;
+ for( int i=argno; i<argc; i++ )
+ {
+ list[nel].str = strdup(argv[i]);
+ lowercase(list[nel].str);
+ list[nel].sig = diffsig(list[nel].str);
+ if( debug )
+ {
+ printf( "debug: unsorted list[%d].str=%s, "
+ "list[%d].sig=%s\n",
+ nel, list[nel].str,
+ nel, list[nel].sig );
+ }
+ nel++;
+ }
+
+ if( debug )
+ {
+ printf( "debug: nel=%d\n", nel );
+ }
+
+ // sort list by signature
+ qsort( list, nel, sizeof(pair), &compair );
+
+ // show sorted list
+ if( debug )
+ {
+ for( int i=0; i<nel; i++ )
+ {
+ printf( "debug: sorted list[%d].str=%s, "
+ "list[%d].sig=%s\n",
+ i, list[i].str, i, list[i].sig );
+
+ }
+ }
+
+ if( debug ) putchar( '\n' );
+ find_freq_sigs( list, nel, &printsigset );
+
+ // tidy up.. free everything we malloc()d
+ for( int i=0; i<nel; i++ )
+ {
+ free( list[i].sig );
+ free( list[i].str );
+ }
+
+ return 0;
+}
diff --git a/challenge-193/duncan-c-white/perl/ch-2.pl b/challenge-193/duncan-c-white/perl/ch-2.pl
index 988f4819cf..4fb47aa330 100755
--- a/challenge-193/duncan-c-white/perl/ch-2.pl
+++ b/challenge-193/duncan-c-white/perl/ch-2.pl
@@ -106,11 +106,7 @@ map { $freq{$_}++ } @diffsig;
foreach my $k (keys %freq)
{
- delete $freq{$k} if $freq{$k}>1;
-}
-
-foreach my $k (keys %freq)
-{
+ next if $freq{$k}>1;
my $ref = $d2l{$k};
say join(',', @$ref);
}
diff --git a/challenge-194/LoneWolfiNTj/perl/ch-1.pl b/challenge-194/LoneWolfiNTj/perl/ch-1.pl
new file mode 100755
index 0000000000..beb9e259c6
--- /dev/null
+++ b/challenge-194/LoneWolfiNTj/perl/ch-1.pl
@@ -0,0 +1,62 @@
+#! /usr/bin/env perl
+# PWCC Challenge 194 Task 1 Perl solution by Robbie Hatley
+
+=pod
+
+Task 1: Digital Clock
+Submitted by: Mohammad S Anwar
+
+You are given time in the format hh:mm with one missing digit.
+Write a script to find the highest digit between 0-9 that makes it
+valid time.
+
+Example 1: Input: '?5:00' Output: 1
+Example 2: Input: '?3:00' Output: 2
+Example 3: Input: '1?:00' Output: 9
+Example 4: Input: '2?:00' Output: 3
+Example 5: Input: '12:?5' Output: 5
+Example 6: Input: '12:5?' Output: 9
+
+=cut
+
+# NOTE: Input is by either default array or CL args. If inputting
+# by CL args, input must be a space-separated sequence of
+# one-or-more strings of the form '2?:17' which are capable
+# of becoming valid times if the '?' is replaced with an
+# appropriate digit.
+
+# NOTE: Output is to stdout and will be each input string
+# followed by the highest-valued replacement for '?'
+# which makes the string a valid time.
+
+use v5.32;
+
+sub valid
+{
+ return 1 if $_[0] =~ m/^\?[0-9]:[0-5][0-9]$/;
+ return 1 if $_[0] =~ m/^[0-2]\?:[0-5][0-9]$/;
+ return 1 if $_[0] =~ m/^(?:(?:[0-1][0-9])|(?:2[0-3])):\?[0-9]$/;
+ return 1 if $_[0] =~ m/^(?:(?:[0-1][0-9])|(?:2[0-3])):[0-5]\?$/;
+ return 0;
+}
+
+my %sub =
+(
+ 0 => sub {if (substr($_[0], 1, 1) <= 3) {return 2} else {return 1}},
+ 1 => sub {if (substr($_[0], 0, 1) <= 1) {return 9} else {return