Skip to content

Commit

Permalink
Replace regexes with pairvalues in atbash-cipher (exercism#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Mita authored Sep 30, 2019
1 parent 8528522 commit 91627ac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion exercises/atbash-cipher/.meta/exercise-data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ tests: |-
}
example: |-
use List::Util qw(pairvalues);
my %dict;
@dict{'a'..'z'} = reverse('a'..'z');
sub encode_atbash {
join( ' ', split( /(\w{5})/, decode_atbash(@_) ) ) =~ s/\s+/ /gr =~ s/^\s//r;
join( ' ', pairvalues split( /(\w{1,5})/, decode_atbash(@_) ) );
}
sub decode_atbash {
Expand Down
5 changes: 3 additions & 2 deletions exercises/atbash-cipher/.meta/solutions/AtbashCipher.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ use warnings;
use Exporter 'import';
our @EXPORT_OK = qw(encode_atbash decode_atbash);

use List::Util qw(pairvalues);

my %dict;
@dict{ 'a' .. 'z' } = reverse( 'a' .. 'z' );

sub encode_atbash {
join( ' ', split( /(\w{5})/, decode_atbash(@_) ) ) =~ s/\s+/ /gr
=~ s/^\s//r;
join( ' ', pairvalues split( /(\w{1,5})/, decode_atbash(@_) ) );
}

sub decode_atbash {
Expand Down

0 comments on commit 91627ac

Please sign in to comment.