Skip to content

Instantly share code, notes, and snippets.

@pjlsergeant
Created March 12, 2012 16:45
Show Gist options
  • Save pjlsergeant/2023260 to your computer and use it in GitHub Desktop.
Save pjlsergeant/2023260 to your computer and use it in GitHub Desktop.
package Roman;
use Moose;
sub AUTOLOAD {
our $AUTOLOAD;
(my $digits = $AUTOLOAD) =~ s/.+:://g;
$digits =~ s/$_->[0]/$_->[1]/
for
[ IV => 'IIII' ],
[ IX => 'VIIII' ],
[ XL => 'XXXX' ],
[ XC => 'LXXXX' ];
return $_[0]->_count(reverse split(//, $digits));
}
sub _count {
my ( $class, $head, @tail ) = @_;
return 0 unless defined $head;
return
{ I => 1, V => 5, X => 10, L => 50, C => 100 }->{ $head } +
$class->_count( @tail )
}
warn Roman->IX;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment