aboutsummaryrefslogtreecommitdiff
path: root/challenge-010/simon-proctor
diff options
context:
space:
mode:
authorSimon Proctor <simon.proctor@zpg.co.uk>2019-05-28 10:45:53 +0100
committerSimon Proctor <simon.proctor@zpg.co.uk>2019-05-28 10:45:53 +0100
commitfe4fa3ef2072abbd008bce478a203e47f5ad4b4f (patch)
tree23614b52db1501781fbe607f9f4f80df6578aff5 /challenge-010/simon-proctor
parentc327c05644959602d275e3e24e90b662aedc804c (diff)
downloadperlweeklychallenge-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-xchallenge-010/simon-proctor/perl6/ch-1.p642
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