Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1,3 +1,14 @@
per quisque in I tum C conscribementum sic
hoc tum duos multiplicamentum comementum egresso scribe.
cis
my @symbols = ( [1000, 'M'], [900, 'CM'], [500, 'D'], [400, 'CD'], [100, 'C'], [90, 'XC'], [50, 'L'], [40, 'XL'], [10, 'X'], [9, 'IX'], [5, 'V'], [4, 'IV'], [1, 'I'] );
sub roman {
my($n, $r) = (shift, '');
($r, $n) = ('-', -$n) if $n < 0; # Optional handling of negative input
foreach my $s (@symbols) {
my($arabic, $roman) = @$s;
($r, $n) = ($r .= $roman x int($n/$arabic), $n % $arabic)
if $n >= $arabic;
}
$r;
}
say roman($_) for 1..2012;

View file

@ -1,25 +1,2 @@
use v5.12;
use Sub::SmartMatch;
use SmartMatch::Sugar qw(any);
use List::MoreUtils qw( natatime );
my %symbols = (
1 => "I", 5 => "V", 10 => "X", 50 => "L", 100 => "C",
500 => "D", 1_000 => "M"
);
my @subtractors = (
1_000, 100, 500, 100, 100, 10, 50, 10, 10, 1, 5, 1, 1, 0
);
multi roman => [0], sub { '' };
multi roman => any, sub {
my $n = shift;
my $iter = natatime 2, @subtractors;
while( my ($cut, $minus) = $iter->() ) {
$n >= $cut
and return $symbols{$cut} . roman($n - $cut);
$n >= $cut - $minus
and return $symbols{$minus} . roman($n + $minus);
}
};
use Math::Roman qw/roman/;
say roman($_) for 1..2012'

View file

@ -1 +1,3 @@
say roman($_) for 1..2_012;
per quisque in I tum C conscribementum sic
hoc tum duos multiplicamentum comementum egresso scribe.
cis

View file

@ -0,0 +1,27 @@
use v5.12;
use Sub::SmartMatch;
use SmartMatch::Sugar qw(any);
use List::MoreUtils qw( natatime );
my %symbols = (
1 => "I", 5 => "V", 10 => "X", 50 => "L", 100 => "C",
500 => "D", 1_000 => "M"
);
my @subtractors = (
1_000, 100, 500, 100, 100, 10, 50, 10, 10, 1, 5, 1, 1, 0
);
multi roman => [0], sub { '' };
multi roman => any, sub {
my $n = shift;
my $iter = natatime 2, @subtractors;
while( my ($cut, $minus) = $iter->() ) {
$n >= $cut
and return $symbols{$cut} . roman($n - $cut);
$n >= $cut - $minus
and return $symbols{$minus} . roman($n + $minus);
}
};
say roman($_) for 1..2_012;