aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-05-27 10:28:03 +0100
committerGitHub <noreply@github.com>2019-05-27 10:28:03 +0100
commitf10a6079413b1fda0e8daf87713d049ee1acfad5 (patch)
tree72bfed8b7a1181a309ad777c0c80aa0e7ce01fab
parent7cf2d69fd8c709348230142b236805f83a8bfb6b (diff)
parentb482a376f6fb50ade494afd9be16770c150799ed (diff)
downloadperlweeklychallenge-club-f10a6079413b1fda0e8daf87713d049ee1acfad5.tar.gz
perlweeklychallenge-club-f10a6079413b1fda0e8daf87713d049ee1acfad5.tar.bz2
perlweeklychallenge-club-f10a6079413b1fda0e8daf87713d049ee1acfad5.zip
Merge pull request #185 from paveljurca/patch-2
draft
-rw-r--r--challenge-010/pavel-jurca/ch-1.pl37
1 files changed, 37 insertions, 0 deletions
diff --git a/challenge-010/pavel-jurca/ch-1.pl b/challenge-010/pavel-jurca/ch-1.pl
new file mode 100644
index 0000000000..1b8f0220c1
--- /dev/null
+++ b/challenge-010/pavel-jurca/ch-1.pl
@@ -0,0 +1,37 @@
+use 5.010.1;
+
+use strict;
+use warnings;
+
+my %roman = reverse qw/
+ I 1
+ V 5
+ X 10
+ L 50
+ C 100
+ D 500
+ M 1000
+/;
+
+# === MAIN ===
+say encode(2019);
+# ============
+
+sub encode {
+ # "additive" notation
+ # https://en.wikipedia.org/wiki/Roman_numerals#Use_of_additive_notation
+
+ my $integer = shift;
+ my @r;
+
+ ROMAN:
+ for ( sort { $b <=> $a } keys %roman ) {
+ push @r, $roman{$_} x int $integer / $_;
+
+ $integer %= $_;
+ }
+
+ join '', @r;
+}
+
+sub decode {}