# # Lenny Conundrum Round 285 # http://www.neopets.com/games/conundrum_feature.phtml?round=285 # # We shall apply the following rules to words. These rules are to be applied # in order. # # Rule 1: All consonants are worth 1 point, and all vowels are worth two # points. # Rule 2: The letters "W" and "Y", being either a vowel or consonant # depending on usage, are worth three points. # Rule 3: Any letter that is also a Roman numeral is worth five additional # points # Rule 4: If there is any letter that appears more than once in a word, the # second instance of the letter is worth double the first instance; # the third instance of the letter is worth double the second, and so # on. # Rule 5: The first letter of the word is worth double points. # Rule 6: The last letter of the word should be multiplied by -1, unless # total length of the word is only three letters. # Rule 7: If the position of a letter is a square number (e.g. the first # letter, fourth letter, etc), square the number of points. # Rule 8: Any letter that appears in the word "NEOPETS" is worth one extra # point. # Rule 9: Any letter that is worth five points is instead worth six. # Rule 10: If the total number of points for the word is an odd number, add # three points to the second letter. # Rule 11: The letter with the highest point value should instead be worth one # point. If there is more than one letter with this point value, only # the first instance should be changed. # # Of all the Neopets species, which species name has the most points? # use strict; use warnings; use List::Util qw( sum max ); my %consonants = map { $_ => 1 } qw( b c d f g h j k l m n p q r s t v x z ); my %vowels = map { $_ => 1 } qw( a e i o u ); my %ambiguous = map { $_ => 1 } qw( w y ); my %numerals = map { $_ => 1 } qw( i v x l c d m ); # According to Wikipedia. my %neopets = map { $_ => 1 } qw( n e o p e t s ); my @species = qw( Nimmo Scorchio JubJub Grarrl Skeith Korbat Lenny Wocky Bruce Kiko Kau Usul Aisha Chia Eyrie Tuskaninny Flotsam Jetsam Kacheek Uni Buzz Lupe Elephante Gelert Mynci Kyrii Peophin Quiggle Shoyru Acara Zafara Blumaroo Techo Moehog Cybunny Poogle Kougra Grundo Koi Meerca Chomby Pteri Krawk Tonu Draik Ixi Yurble Ruki Bori Hissi Lutari Xweetok Ogrin Gnorbu ); my %totals; for my $species (@species) { my $name = lc($species); my @name = $name =~ /./g; my @vals; # RULE 1 and 2 for my $i (0..$#name) { my $l = $name[$i]; $vals[$i] = 1 if $consonants{$l} && !$vowels{$l} && !$ambiguous{$l}; $vals[$i] = 2 if !$consonants{$l} && $vowels{$l} && !$ambiguous{$l}; $vals[$i] = 3 if !$consonants{$l} && !$vowels{$l} && $ambiguous{$l}; die if !defined($vals[$i]); } # RULE 3 for my $i (0..$#name) { my $l = $name[$i]; $vals[$i] += 5 if $numerals{$l}; } # RULE 4 { my %prev_vals; for my $i (0..$#name) { my $l = $name[$i]; $vals[$i] = 2 * $prev_vals{$l} if exists($prev_vals{$l}); $prev_vals{$l} = $vals[$i]; } } # RULE 5 $vals[0] *= 2; # RULE 6 $vals[-1] *= -1 unless @name == 3; # RULE 7 { my $n = 1; for (;;) { my $i = $n*$n - 1; last if $i >= @name; $vals[$i] *= $vals[$i]; $n++; } } # RULE 8 for my $i (0..$#name) { my $l = $name[$i]; $vals[$i] += 1 if $neopets{$l}; } # RULE 9 for my $i (0..$#name) { $vals[$i] = 6 if $vals[$i] == 5; } # RULE 10 if (sum(@vals) % 2 == 1) { die if @name < 2; $vals[1] += 3; } # RULE 11 { my $max_i = 0; for my $i (0..$#name) { $max_i = $i if $vals[$max_i] < $vals[$i]; } $vals[$max_i] = 1; } $totals{$species} = sum(@vals); } { my $max_length_p1 = ( max map length, @species ) + 1; for my $name (sort { $totals{$b} <=> $totals{$a} } keys %totals) { printf("%-${max_length_p1}s %d\n", "$name:", $totals{$name}); } } __END__ Draik: 55 Elephante: 42 Chomby: 39 Mynci: 35 Xweetok: 31 Tuskaninny: 26 Scorchio: 25 Usul: 23 Eyrie: 22 Ixi: 21 Peophin: 20 Ogrin: 20 Nimmo: 19 Poogle: 19 Blumaroo: 19 Quiggle: 18 Gelert: 18 Meerca: 15 Kacheek: 15 Tonu: 13 Moehog: 13 Kiko: 13 Techo: 13 Uni: 13 Yurble: 13 Chia: 13 Bori: 12 Skeith: 12 JubJub: 12 Cybunny: 11 Lupe: 11 Wocky: 11 Shoyru: 10 Buzz: 10 Grarrl: 9 Grundo: 9 Korbat: 9 Lenny: 9 Ruki: 8 Koi: 8 Gnorbu: 8 Flotsam: 8 Bruce: 7 Aisha: 7 Acara: 7 Kougra: 7 Krawk: 6 Kau: 5 Jetsam: 5 Pteri: 3 Lutari: 3 Zafara: 1 Hissi: -1 Kyrii: -2