From 95a6164a37f9efe6e211384485b8e1df34fc7995 Mon Sep 17 00:00:00 2001 From: Kivanc Yazan Date: Sun, 26 May 2019 23:40:39 -0700 Subject: Kivanc Week 10 Challenge 1 solution --- challenge-010/kivanc-yazan/perl5/ch-1.pl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 challenge-010/kivanc-yazan/perl5/ch-1.pl diff --git a/challenge-010/kivanc-yazan/perl5/ch-1.pl b/challenge-010/kivanc-yazan/perl5/ch-1.pl new file mode 100644 index 0000000000..474e736b38 --- /dev/null +++ b/challenge-010/kivanc-yazan/perl5/ch-1.pl @@ -0,0 +1,22 @@ +use warnings; +use strict; + +my $input = int($ARGV[0] // 0); +die "Expecting an integer between 1 and 3999" + unless $input && ($input >= 1) && ($input <= 3999); +my $output = ''; + +# Basic mapping includes 1000 500 100 50 10 5 1. +# To avoid extra calculation, I have also added 900 400 90 40 9 4. +my @decimal = qw/ 1000 900 500 400 100 90 50 40 10 9 5 4 1/; +my @roman = qw/ M CM D CD C XC L XL X IX V IV I/; + +for my $i (0..12){ + my $dec = $decimal[$i]; + my $rom = $roman[$i]; + my $times = int($input / $dec); + $output .= ($rom x $times); + $input -= $dec * $times ; +} + +print "$output\n"; -- cgit