Last active
December 20, 2015 14:18
-
-
Save evincarofautumn/6145097 to your computer and use it in GitHub Desktop.
Finding the best Scrabble word that could appear in a YubiKey password.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# | |
# yubikey-scrabble.pl | |
# | |
# Finding the best Scrabble word that could appear in a YubiKey password. | |
# | |
# cpan List::UtilsBy | |
# chmod +x yubikey-scrabble.pl | |
# ./yubikey-scrabble.pl | |
# | |
use strict; | |
use warnings; | |
use List::Util 'sum'; | |
use List::UtilsBy 'max_by'; | |
my %VALUES = ( | |
a => 1, | |
b => 3, | |
c => 3, | |
d => 2, | |
e => 1, | |
f => 4, | |
g => 2, | |
h => 4, | |
i => 1, | |
j => 8, | |
k => 5, | |
l => 1, | |
m => 3, | |
n => 1, | |
o => 1, | |
p => 3, | |
q => 10, | |
r => 1, | |
s => 1, | |
t => 1, | |
u => 1, | |
v => 4, | |
w => 4, | |
x => 8, | |
y => 4, | |
z => 10, | |
); | |
my @dict = (); | |
open my $DICT, '<', '/usr/share/dict/words'; | |
while (<$DICT>) { push @dict, $_ if /^[bdeghijklnrtuv]+$/ } | |
chomp @dict; | |
sub score($) { sum map {$VALUES{$_}} split //, shift } | |
my $best_word = max_by \&score, @dict; | |
my $best_score = score($best_word); | |
print "Best word: '$best_word' with a score of $best_score.\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment