Skip to content

Instantly share code, notes, and snippets.

@munky69rock
Created July 13, 2014 06:59
Show Gist options
  • Select an option

  • Save munky69rock/39cd4f42ad2ea2ca5242 to your computer and use it in GitHub Desktop.

Select an option

Save munky69rock/39cd4f42ad2ea2ca5242 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
my @ar = ('a' .. 'z');
my $input = lc(shift @ARGV);
die if !$input;
my $sum = 0;
while ($input =~ /^(.)/) {
my $last = length $input == 1 ? 1 : 0;
my $s = $1;
my $i = 0;
for my $c (@ar) {
if ($c eq $s) {
if ($last) {
$sum += $i;
} else {
$sum += int(@ar) * ($i + 1);
}
}
$i++;
}
$input =~ s/^.//;
}
print $sum;
print "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment