diff options
| author | dcw <d.white@imperial.ac.uk> | 2022-02-13 21:25:06 +0000 |
|---|---|---|
| committer | dcw <d.white@imperial.ac.uk> | 2022-02-13 21:25:06 +0000 |
| commit | 6b0e661e19aa6a283d65e4ba2ef3e093b92acd3e (patch) | |
| tree | 4ba92dc8f430ba87dbbfac36638429f58170683b /challenge-025 | |
| parent | a97d4e09626ce448a589af9e783d48cd7622e823 (diff) | |
| download | perlweeklychallenge-club-6b0e661e19aa6a283d65e4ba2ef3e093b92acd3e.tar.gz perlweeklychallenge-club-6b0e661e19aa6a283d65e4ba2ef3e093b92acd3e.tar.bz2 perlweeklychallenge-club-6b0e661e19aa6a283d65e4ba2ef3e093b92acd3e.zip | |
imported my solutions to this week's tasks (and imported a few historic improvements to code comments in earlier solutions of mine)
Diffstat (limited to 'challenge-025')
| -rwxr-xr-x | challenge-025/duncan-c-white/perl5/ch-1.pl | 2 | ||||
| -rwxr-xr-x | challenge-025/duncan-c-white/perl5/v16.pl | 95 |
2 files changed, 45 insertions, 52 deletions
diff --git a/challenge-025/duncan-c-white/perl5/ch-1.pl b/challenge-025/duncan-c-white/perl5/ch-1.pl index a8dc4aa651..072eef9794 100755 --- a/challenge-025/duncan-c-white/perl5/ch-1.pl +++ b/challenge-025/duncan-c-white/perl5/ch-1.pl @@ -151,7 +151,7 @@ fun findall() # extend path s by each unused word no in the inwords push @$newpaths, map { - # word no $_ no longer available. + # mark $wno no longer available. my $newavail = $avail; substr( $newavail, $_, 1 ) = 0; diff --git a/challenge-025/duncan-c-white/perl5/v16.pl b/challenge-025/duncan-c-white/perl5/v16.pl index 24bc7e03b5..bfea5a873e 100755 --- a/challenge-025/duncan-c-white/perl5/v16.pl +++ b/challenge-025/duncan-c-white/perl5/v16.pl @@ -37,15 +37,11 @@ my @words = qw(audino bagon baltoy banette bidoof braviary bronzor carracosta wartortle whismur wingull yamask); #@words = qw(hello ollie excellent thanks shelter runaround set to); -#die scalar(@words); - my %sw; # hash from letter L to list of word nos of words STARTING with L -my @outword; # array from word no N to array of wordnos of words going "out" - # from word N, i.e. starting with the last letter of word N - # if there are no such words, then [] - -my @stopword;# list of stop word nos (word nos of words with no outwords) +my @stopword;# list of stop word nos (word nos of words with no words going + # "out" from them onto another word, ie. word numbers N where + # no other word starts with the last letter of word N) my %ew; # hash from letter L to list of word nos of words ENDING with L @@ -75,17 +71,15 @@ foreach my $wn (0..$#words) } #die Dumper \%ew; -# build @outword and @stopword, using %sw +# build @stopword, using %sw foreach my $wn (0..$#words) { my $word = $words[$wn]; $word =~ /(.)$/; my $lastletter = $1; my $aref = $sw{$lastletter} // []; - $outword[$wn]= $aref; push @stopword, $wn if @$aref==0; } -#die Dumper \@outword; #die Dumper [ map { $words[$_] } @stopword ]; # build @inword, using %ew @@ -109,6 +103,46 @@ exit 0; # +# my @suset = suset( $wno ); +# Form a SUset in which all word nos are unused, except $wno. +# +fun suset( $wno ) +{ + my @suset = (0) x scalar(@words); + $suset[$wno] = 1; + return @suset; +} + + +# +# show_seqs( @seqs ); +# Show the sequences (as words, not word nos) +# +fun show_seqs( @seqs ) +{ + foreach my $s (@seqs) + { + my $str = join( ',', map { $words[$_] } split(/,/,$s) ); + print "$str\n"; + } +} + + +# +# show_sus( @sus ); +# Show the sequences (as words, not word nos) contained in SUlist @sus +# +fun show_sus( @sus ) +{ + foreach my $s (@sus) + { + my $str = $s->[1]; + print "$str\n"; + } +} + + +# # my @seqs = findall(); # Find all sequences, starting with sequences of length 1 (stop words), # then working back, i.e. prepending words onto the front of existing @@ -184,44 +218,3 @@ fun findall( ) my $currsus = $sus[$curr]; return map { $_->[1] } @$currsus; } - - - -# -# my @suset = suset( $wno ); -# Form a SUset in which all word nos are unused, except $wno. -# -fun suset( $wno ) -{ - my @suset = (0) x scalar(@words); - $suset[$wno] = 1; - return @suset; -} - - -# -# show_sus( @sus ); -# Show the sequences (as words, not word nos) contained in SUlist @sus -# -fun show_sus( @sus ) -{ - foreach my $s (@sus) - { - my $str = $s->[1]; - print "$str\n"; - } -} - - -# -# show_seqs( @seqs ); -# Show the sequences (as words, not word nos) -# -fun show_seqs( @seqs ) -{ - foreach my $s (@seqs) - { - my $str = join( ',', map { $words[$_] } split(/,/,$s) ); - print "$str\n"; - } -} |
