diff options
| -rw-r--r-- | challenge-161/lubos-kolouch/perl/ch-1.pl | 29 | ||||
| -rw-r--r-- | challenge-161/lubos-kolouch/perl/ch-2.pl | 58 |
2 files changed, 87 insertions, 0 deletions
diff --git a/challenge-161/lubos-kolouch/perl/ch-1.pl b/challenge-161/lubos-kolouch/perl/ch-1.pl new file mode 100644 index 0000000000..5389c6dd2d --- /dev/null +++ b/challenge-161/lubos-kolouch/perl/ch-1.pl @@ -0,0 +1,29 @@ +package main; +use strict; +use warnings; + +# glory for best belly boy! + +sub is_abcd { + my $what = shift; + + return $what eq join( '', sort( split //, $what ) ); +} + +open my $file, '<', 'dictionary.txt'; + +while (<$file>) { + chomp; + + print "$_ is abcdrian \n" if is_abcd($_); +} +close $file; + +use Test::More; + +is( is_abcd('knotty'), 1 ); +is( is_abcd('knotts'), '' ); + +done_testing; + +1; diff --git a/challenge-161/lubos-kolouch/perl/ch-2.pl b/challenge-161/lubos-kolouch/perl/ch-2.pl new file mode 100644 index 0000000000..c813084ceb --- /dev/null +++ b/challenge-161/lubos-kolouch/perl/ch-2.pl @@ -0,0 +1,58 @@ +package main; +use strict; +use warnings; + +my %seen_letters; +my @output; + +sub is_abcd { + my $what = shift; + + return $what eq join( '', sort( split //, $what ) ); +} + +sub process_word { + my $what = shift; + + my %this_run_letters = %seen_letters; + + for my $i ( split //, $what ) { + $this_run_letters{$i} = 1; + } + my $letters_count = scalar keys %this_run_letters; + + if ( scalar keys %seen_letters == $letters_count - 1 ) { + + # we added a letter + push @output, $_; + %seen_letters = %this_run_letters; + } + + return; +} + +sub get_abcdrian_pangram { + + # only abecederian words solving exactly one letter + open my $file, '<', 'dictionary.txt'; + + while (<$file>) { + chomp; + process_word($_); + + # seen all letters? + return join( ' ', @output ) if scalar keys %seen_letters == 26; + } + close $file; + + return; +} +use Test::More; + +is( get_abcdrian_pangram(), + 'a ad added adds ado adobe adore adorn adverb adversaries adversary adversely adversest advertisement advertising advice aerospace aesthetic afar affix affluence afterward agonize ajar akin antiquate' +); + +done_testing; + +1; |
