Last active
August 29, 2015 14:14
-
-
Save zachwhalen/f29c38aaa667e1827c11 to your computer and use it in GitHub Desktop.
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/local/perl | |
# a quick and dirty numeric syllable counter | |
use Number::Spell; | |
@one = qw/one two three four five six eight nine ten twelve/; | |
@two = qw/seven thirteen fourteen fifteen sixteen eighteen nineteen twenty thirty forty fifty sixty eighty ninety hundred thousand million billion trillion/; | |
@three = qw/eleven seventeen seventy/; | |
%ones; | |
%twos; | |
%threes; | |
foreach (@one){ | |
$ones{$_} = 1; | |
} | |
foreach (@two){ | |
$twos{$_} = 2; | |
} | |
foreach (@three){ | |
$threes{$_} = 3; | |
} | |
$int = 0; | |
for ($int = 0; $int <= 1000000; $int++){ | |
$int += 1; | |
my $spelled = spell_number($int); | |
my $count = syll($spelled); | |
if ($count == 5){ | |
print "five!\n"; | |
open WRITE, ">>fives.txt"; | |
print WRITE "$int\t$spelled\n"; | |
close WRITE; | |
}elsif($count == 7){ | |
print "seven!\n"; | |
open WRITE, ">>sevens.txt"; | |
print WRITE "$int\t$spelled\n"; | |
close WRITE; | |
} | |
} | |
sub syll { | |
$string = @_[0]; | |
my $count = 0; | |
foreach (split(' ', $string)){ | |
if($ones{$_} == 1){ | |
$count += 1; | |
}elsif($twos{$_} == 2){ | |
$count += 2; | |
}elsif($threes{$_} == 3){ | |
$count += 3; | |
}else{ | |
die "Couldn't find a count for $_!!\n"; | |
} | |
} | |
return $count; | |
} | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment