tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
|
|
@ -0,0 +1,3 @@
|
|||
per quisque in I tum C conscribementum sic
|
||||
hoc tum duos multiplicamentum comementum egresso scribe.
|
||||
cis
|
||||
25
Task/Roman-numerals-Encode/Perl/roman-numerals-encode-2.pl
Normal file
25
Task/Roman-numerals-Encode/Perl/roman-numerals-encode-2.pl
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
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);
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1 @@
|
|||
say roman($_) for 1..2_012;
|
||||
Loading…
Add table
Add a link
Reference in a new issue