diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-11-18 11:46:53 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-18 11:46:53 +0000 |
| commit | f4e288167212b2311c3c7873183b66c261551402 (patch) | |
| tree | 914158c4523ead7b9fa1f2683a4a3b165ee1f8c8 | |
| parent | 537bac36695b717e5c9d2c19b0610b2227dc64a1 (diff) | |
| parent | fadbf095d9f9af297f6f84e32ca6be7cb85ba9c3 (diff) | |
| download | perlweeklychallenge-club-f4e288167212b2311c3c7873183b66c261551402.tar.gz perlweeklychallenge-club-f4e288167212b2311c3c7873183b66c261551402.tar.bz2 perlweeklychallenge-club-f4e288167212b2311c3c7873183b66c261551402.zip | |
Merge pull request #945 from Firedrake/rogerbw-challenge-035
Solutions for challenge #35.
| -rwxr-xr-x | challenge-035/roger-bell-west/perl5/ch-1.pl | 78 | ||||
| -rwxr-xr-x | challenge-035/roger-bell-west/perl5/ch-2.pl | 74 | ||||
| -rwxr-xr-x | challenge-035/roger-bell-west/perl5/corrupt.pl | 16 | ||||
| -rwxr-xr-x | challenge-035/roger-bell-west/perl6/ch-1.p6 | 70 | ||||
| -rwxr-xr-x | challenge-035/roger-bell-west/perl6/ch-2.p6 | 66 |
5 files changed, 304 insertions, 0 deletions
diff --git a/challenge-035/roger-bell-west/perl5/ch-1.pl b/challenge-035/roger-bell-west/perl5/ch-1.pl new file mode 100755 index 0000000000..dc7dc40f83 --- /dev/null +++ b/challenge-035/roger-bell-west/perl5/ch-1.pl @@ -0,0 +1,78 @@ +#! /usr/bin/perl + +use strict; +use warnings; + +my %t; +while (<DATA>) { + chomp; + /^(.) (.*)$/; + $t{$1}=$2; +} + +my %e; +foreach my $char (keys %t) { + $e{$char}=join('0',map {{'.' => '1', + '_' => '111'}->{$_}} + split '',$t{$char}); +} + +my $chars=join('',keys %t); + +my @in; +while (<>) { + chomp; + my $t=uc($_); + $t =~ s/[^ $chars]//g; + push @in,$t; +} + +my $m=join(' ',@in); + +my @l; +foreach my $word (split ' ',$m) { + my @w; + foreach my $char (split '',$word) { + push @w,$e{$char}; + } + push @l,join('000',@w); +} +print join('000000',@l),"\n"; + +__DATA__ +E . +I .. +S ... +H .... +5 ..... +4 ...._ +V ..._ +3 ...__ +U .._ +F .._. +2 ..___ +A ._ +R ._. +L ._.. +W .__ +P .__. +J .___ +1 .____ +T _ +N _. +D _.. +B _... +6 _.... +X _.._ +K _._ +C _._. +Y _.__ +M __ +G __. +Z __.. +7 __... +Q __._ +O ___ +8 ___.. +9 ____. +0 _____ diff --git a/challenge-035/roger-bell-west/perl5/ch-2.pl b/challenge-035/roger-bell-west/perl5/ch-2.pl new file mode 100755 index 0000000000..635f1f598d --- /dev/null +++ b/challenge-035/roger-bell-west/perl5/ch-2.pl @@ -0,0 +1,74 @@ +#! /usr/bin/perl + +use strict; +use warnings; + +my %t; +while (<DATA>) { + chomp; + /^(.) (.*)$/; + $t{$1}=$2; +} + +my %d; +foreach my $char (keys %t) { + $d{join('0',map {{'.' => '1', + '_' => '111'}->{$_}} + split '',$t{$char})}=$char; +} + +my @in; +while (<>) { + chomp; + push @in,$_; +} + +my $m=join('',@in); + +my @m; +foreach my $word (split /000000+/,$m) { + my @w; + foreach my $char (split /000+/,$word) { + push @w,($d{$char} or '?'); + } + push @m,join('',@w); +} +print join(' ',@m),"\n"; + +__DATA__ +E . +I .. +S ... +H .... +5 ..... +4 ...._ +V ..._ +3 ...__ +U .._ +F .._. +2 ..___ +A ._ +R ._. +L ._.. +W .__ +P .__. +J .___ +1 .____ +T _ +N _. +D _.. +B _... +6 _.... +X _.._ +K _._ +C _._. +Y _.__ +M __ +G __. +Z __.. +7 __... +Q __._ +O ___ +8 ___.. +9 ____. +0 _____ diff --git a/challenge-035/roger-bell-west/perl5/corrupt.pl b/challenge-035/roger-bell-west/perl5/corrupt.pl new file mode 100755 index 0000000000..9712f951b4 --- /dev/null +++ b/challenge-035/roger-bell-west/perl5/corrupt.pl @@ -0,0 +1,16 @@ +#! /usr/bin/perl + +use strict; +use warnings; + +while (<>) { + chomp; + my $t=$_; + foreach (0..int(rand()*length($t)/2)) { + substr($t, + int(rand()*length($t)), + 1, + (rand()<0.5)?'0':'1'); + } + print "$t\n"; +} diff --git a/challenge-035/roger-bell-west/perl6/ch-1.p6 b/challenge-035/roger-bell-west/perl6/ch-1.p6 new file mode 100755 index 0000000000..cc976f2f63 --- /dev/null +++ b/challenge-035/roger-bell-west/perl6/ch-1.p6 @@ -0,0 +1,70 @@ +#! /usr/bin/perl6 + +my %t=( + E => '.', + I => '..', + S => '...', + H => '....', + 5 => '.....', + 4 => '...._', + V => '..._', + 3 => '...__', + U => '.._', + F => '.._.', + 2 => '..___', + A => '._', + R => '._.', + L => '._..', + W => '.__', + P => '.__.', + J => '.___', + 1 => '.____', + T => '_', + N => '_.', + D => '_..', + B => '_...', + 6 => '_....', + X => '_.._', + K => '_._', + C => '_._.', + Y => '_.__', + M => '__', + G => '__.', + Z => '__..', + 7 => '__...', + Q => '__._', + O => '___', + 8 => '___..', + 9 => '____.', + 0 => '_____', +); + +my %e; +for keys %t -> $char { + %e{$char}=join('0',map {{'.' => '1', + '_' => '111'}.{$_}}, + grep /./, + split '',%t{$char}); +} + +my $chars=join('',keys %t); + +my @in; +for lines() { + .chomp; + my $t=uc($_); + $t ~~ s:g/[^ $chars]//; + push @in,$t; +} + +my $m=join(' ',@in); + +my @l; +for grep /./,split ' ',$m -> $word { + my @w; + for grep /./,split '',$word -> $char { + push @w,%e{$char}; + } + push @l,join('000',@w); +} +print join('000000',@l),"\n"; diff --git a/challenge-035/roger-bell-west/perl6/ch-2.p6 b/challenge-035/roger-bell-west/perl6/ch-2.p6 new file mode 100755 index 0000000000..f78f91fbbd --- /dev/null +++ b/challenge-035/roger-bell-west/perl6/ch-2.p6 @@ -0,0 +1,66 @@ +#! /usr/bin/perl6 + +my %t=( + E => '.', + I => '..', + S => '...', + H => '....', + 5 => '.....', + 4 => '...._', + V => '..._', + 3 => '...__', + U => '.._', + F => '.._.', + 2 => '..___', + A => '._', + R => '._.', + L => '._..', + W => '.__', + P => '.__.', + J => '.___', + 1 => '.____', + T => '_', + N => '_.', + D => '_..', + B => '_...', + 6 => '_....', + X => '_.._', + K => '_._', + C => '_._.', + Y => '_.__', + M => '__', + G => '__.', + Z => '__..', + 7 => '__...', + Q => '__._', + O => '___', + 8 => '___..', + 9 => '____.', + 0 => '_____', +); + +my %d; +for keys %t -> $char { + %d{join('0',map {{'.' => '1', + '_' => '111'}.{$_}}, + grep /./, + split '',%t{$char})}=$char; +} + +my @in; +for lines() { + .chomp; + push @in,$_; +} + +my $m=join('',@in); + +my @m; +for grep /./,split /000000+/,$m -> $word { + my @w; + for grep /./,split /000+/,$word -> $char { + push @w,(%d{$char} or '?'); + } + push @m,join('',@w); +} +print join(' ',@m),"\n"; |
