diff options
| author | Simon Proctor <simon.proctor@zpg.co.uk> | 2019-05-28 10:45:53 +0100 |
|---|---|---|
| committer | Simon Proctor <simon.proctor@zpg.co.uk> | 2019-05-28 10:45:53 +0100 |
| commit | fe4fa3ef2072abbd008bce478a203e47f5ad4b4f (patch) | |
| tree | 23614b52db1501781fbe607f9f4f80df6578aff5 /challenge-010/simon-proctor | |
| parent | c327c05644959602d275e3e24e90b662aedc804c (diff) | |
| download | perlweeklychallenge-club-fe4fa3ef2072abbd008bce478a203e47f5ad4b4f.tar.gz perlweeklychallenge-club-fe4fa3ef2072abbd008bce478a203e47f5ad4b4f.tar.bz2 perlweeklychallenge-club-fe4fa3ef2072abbd008bce478a203e47f5ad4b4f.zip | |
I'd done this before for Exercism but I've tweaked my result with a unicode option
Diffstat (limited to 'challenge-010/simon-proctor')
| -rwxr-xr-x | challenge-010/simon-proctor/perl6/ch-1.p6 | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/challenge-010/simon-proctor/perl6/ch-1.p6 b/challenge-010/simon-proctor/perl6/ch-1.p6 new file mode 100755 index 0000000000..5fe7597097 --- /dev/null +++ b/challenge-010/simon-proctor/perl6/ch-1.p6 @@ -0,0 +1,42 @@ +#!/usr/bin/env perl6 +use v6; + +my %*SUB-MAIN-OPTS = :named-anywhere; + +subset RomanInt of Int where 0 < * < 3001; + +sub to-roman (RomanInt $number is copy, @values) is export { + my $out = ""; + + for @values -> $pair { + my ( $sigil, $num ) = $pair.kv; + while ( $number >= $num ) { + $out ~= $sigil; + $number -= $num; + } + } + + $out; +} + +#| Help data +multi sub MAIN( :h(:$help) ) { + say $*USAGE; +} + +#| Print the Roman Numeral version of a number +multi sub MAIN( + RomanInt $i, #= Integer value to return as Roman Numeral + Bool :u(:$unicode) #= Return in Unicode + ) { + my @values = ( :1000M, :900CM, :500D, :400CD, :100C, :90XC, :50L, :40XL, :10X, :9IX, :5V, :4IV, :1I ); + if ( $unicode ) { + @values = ( + "Ⅿ" => Ⅿ, "ⅭⅯ" => 900, "Ⅾ" => Ⅾ, "ⅭⅮ" => 400, "Ⅽ" => Ⅽ, + "ⅩⅭ" => 90, "Ⅼ" => Ⅼ, "ⅩⅬ" => 40, "Ⅹ" => Ⅹ, "Ⅸ" => Ⅸ, + "Ⅴ" => Ⅴ, "Ⅳ" => Ⅳ, "Ⅰ" => Ⅰ + ); + } + + say to-roman( $i, @values ); +}
\ No newline at end of file |
