Update all new Tasks

This commit is contained in:
Ingy döt Net 2015-02-20 09:02:09 -05:00
parent 00a190b0a6
commit 91df62d461
5697 changed files with 93386 additions and 804 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);