summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/Games/Word.pm29
1 files changed, 28 insertions, 1 deletions
diff --git a/lib/Games/Word.pm b/lib/Games/Word.pm
index ba3a03a..cd54cdb 100644
--- a/lib/Games/Word.pm
+++ b/lib/Games/Word.pm
@@ -4,7 +4,8 @@ require Exporter;
@ISA = qw/Exporter/;
@EXPORT_OK = qw/random_permutation is_permutation all_permutations
shared_letters shared_letters_by_position
- random_string_from/;
+ random_string_from
+ is_substring all_substrings/;
use strict;
use warnings;
@@ -110,6 +111,32 @@ sub random_string_from {
return $ret;
}
+sub is_substring {
+ my ($word, $substring) = @_;
+
+ return 1 unless $substring;
+ my $re = join('?', map { quotemeta } split(//, $substring)) . '?';
+ return $word =~ $re;
+}
+
+sub all_substrings {
+ my $string = shift;
+
+ return ('') unless $string;
+
+ my @substrings = ($string);
+ my $before = '';
+ my $current = substr $string, 0, 1, '';
+ while ($current) {
+ @substrings = (@substrings,
+ map { $before . $_ } all_substrings($string));
+ $before .= $current;
+ $current = substr $string, 0, 1, '';
+ }
+
+ return @substrings;
+}
+
=head1 NAME
Games::Word - ???