Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,26 @@
#!/usr/bin/perl
use warnings;
use strict;
sub can_make_word {
my ($word, @blocks) = @_;
$_ = uc join q(), sort split // for @blocks;
my %blocks;
$blocks{$_}++ for @blocks;
return _can_make_word(uc $word, %blocks)
}
sub _can_make_word {
my ($word, %blocks) = @_;
my $char = substr $word, 0, 1, q();
my @candidates = grep 0 <= index($_, $char), keys %blocks;
for my $candidate (@candidates) {
next if $blocks{$candidate} <= 0;
local $blocks{$candidate} = $blocks{$candidate} - 1;
return 1 if q() eq $word or _can_make_word($word, %blocks);
}
return
}

View file

@ -0,0 +1,13 @@
use Test::More tests => 8;
my @blocks1 = qw(BO XK DQ CP NA GT RE TG QD FS JW HU VI AN OB ER FS LY PC ZM);
is(can_make_word("A", @blocks1), 1);
is(can_make_word("BARK", @blocks1), 1);
is(can_make_word("BOOK", @blocks1), undef);
is(can_make_word("TREAT", @blocks1), 1);
is(can_make_word("COMMON", @blocks1), undef);
is(can_make_word("SQUAD", @blocks1), 1);
is(can_make_word("CONFUSE", @blocks1), 1);
my @blocks2 = qw(US TZ AO QA);
is(can_make_word('auto', @blocks2), 1);

View file

@ -0,0 +1,17 @@
#!/usr/bin/perl
use strict; # https://rosettacode.org/wiki/ABC_Problem
use warnings;
printf "%30s %s\n", $_, can_make_word( $_,
'BO XK DQ CP NA GT RE TG QD FS JW HU VI AN OB ER FS LY PC ZM' )
for qw( A BARK BOOK TREAT COMMON SQUAD CONFUSE );
sub can_make_word
{
my ($word, $blocks) = @_;
my $letter = chop $word or return 'True';
can_make_word( $word, $` . $' ) eq 'True' and return 'True'
while $blocks =~ /\w?$letter\w?/gi;
return 'False';
}