June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
22
Task/Roman-numerals-Encode/Perl-6/roman-numerals-encode.pl6
Normal file
22
Task/Roman-numerals-Encode/Perl-6/roman-numerals-encode.pl6
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
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 sub roman (0) { '' }
|
||||
multi sub roman (Int $n) {
|
||||
for @subtractors -> $cut, $minus {
|
||||
$n >= $cut
|
||||
and return %symbols{$cut} ~ roman($n - $cut);
|
||||
$n >= $cut - $minus
|
||||
and return %symbols{$minus} ~ roman($n + $minus);
|
||||
}
|
||||
}
|
||||
|
||||
# Sample usage
|
||||
|
||||
for 1 .. 2_010 -> $x {
|
||||
say roman($x);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue