aboutsummaryrefslogtreecommitdiff
path: root/challenge-190
diff options
context:
space:
mode:
authorKUEPPO <tcheukueppo@tutanota.com>2022-11-11 22:02:26 +0100
committerGitHub <noreply@github.com>2022-11-11 22:02:26 +0100
commit68630ce60585dd02c630c7f1eb8e5927ed94dfd3 (patch)
treeb827722205c9748e5e6c3f90bf8721f22e204452 /challenge-190
parente99dd2b37f5df5097e5deb7389163e334ac368af (diff)
downloadperlweeklychallenge-club-68630ce60585dd02c630c7f1eb8e5927ed94dfd3.tar.gz
perlweeklychallenge-club-68630ce60585dd02c630c7f1eb8e5927ed94dfd3.tar.bz2
perlweeklychallenge-club-68630ce60585dd02c630c7f1eb8e5927ed94dfd3.zip
Delete ch-2.pl
Diffstat (limited to 'challenge-190')
-rw-r--r--challenge-190/kueppo-wesley/ch-2.pl75
1 files changed, 0 insertions, 75 deletions
diff --git a/challenge-190/kueppo-wesley/ch-2.pl b/challenge-190/kueppo-wesley/ch-2.pl
deleted file mode 100644
index 2546e0dbdb..0000000000
--- a/challenge-190/kueppo-wesley/ch-2.pl
+++ /dev/null
@@ -1,75 +0,0 @@
-#!/usr/bin/env perl
-
-use strict;
-use warnings;
-use feature qw(state current_sub);
-
-use Test::More;
-use Test::Deep;
-
-=pod
-
-=head1 PROBLEM
-
-Given C<X> and C<Y>, words from different encodings and C<F>, a function
-which transliterates the alphabets between these encodings.
-The primary issue is that the results of composed alphabets are also alphabets.
-
-So, get all possible C<Y>s from C<X>.
-
-=head1 SOLUTION
-
-A possible solution to this problem can be to parse the encoded
-string to build a tree on which a prefix search generates all the
-possible C<Y>s.
-
-=cut
-
-sub decode_string {
- my ( $encoded, $decoded ) = @_;
-
- state @stack;
- state %maps = map { $_ => ( undef, 'A' .. 'Z' )[ $_ ] } 1 .. 26;
-
- # Mandatory
- $decoded = [] unless defined $decoded;
-
- foreach my $len ( 1 .. length $encoded ) {
- my ( $alpha, $rest ) = ( substr( $encoded, 0, $len ), substr( $encoded, $len ) );
-
- # Check if substr of length `$len' is an alphabet in the formal system
- # of the encoded string.
- if ( grep { $_ eq $alpha } keys %maps ) {
-
- next if length $rest == 1 and not exists $maps{$rest};
- if ( length $rest > 0 ) {
-
- # Instead of building a tree to later on perform a prefix search
- # on it, stack the values and print the final results when
- # length $rest == 0
- push @stack, $maps{$alpha};
- __SUB__->( $rest, $decoded );
- }
- else {
- push @$decoded, join '', @stack, $maps{$alpha};
- }
- }
- }
- pop @stack;
-
- return $decoded;
-}
-
-my $expected = [
- [ qw( AAAE AAO AKE KAE KO ) ],
- [ qw( AA K ) ],
- [ qw( ABG LG ) ],
-];
-
-cmp_deeply(
- [ map { decode_string( $_ ) } qw(1115 11 127) ],
- $expected,
- "Did you decode them correctly?"
-);
-
-done_testing( 1 );