Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another solution to challenge 004 #83

Merged
merged 1 commit into from Apr 21, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -0,0 +1,27 @@
#!/usr/bin/env perl

# You are given a file containing a list of words (case insensitive 1 word per
# line) and a list of letters. Print each word from the file than can be made
# using only letters from the list. You can use each letter only once (though
# there can be duplicates and you can use each of them once), you don’t have to
# use all the letters. (Disclaimer: The challenge was proposed by Scimon
# Proctor)

use 5.026;
use strict;
use autodie;
use warnings;
use List::Util 'all';

my $letters = shift or die "usage: $0 <letters> [<wordsfile>...]\n";

# Construct a hash mapping each letter to its count number
my %letters;
++$letters{$_} foreach split //, lc $letters;

say foreach grep {
chomp;
my %letters = %letters;
--$letters{$_} foreach split //, lc $_;
all {$_ >= 0} values %letters;
} <>;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.