diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-05-27 10:27:30 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-05-27 10:27:30 +0100 |
| commit | 7cf2d69fd8c709348230142b236805f83a8bfb6b (patch) | |
| tree | 408f0bac89153df626b0f2a40c7fd738b8be5d83 | |
| parent | 9cc31412f1e6fd2196501c042c8473e9cab1e9ca (diff) | |
| parent | 95a6164a37f9efe6e211384485b8e1df34fc7995 (diff) | |
| download | perlweeklychallenge-club-7cf2d69fd8c709348230142b236805f83a8bfb6b.tar.gz perlweeklychallenge-club-7cf2d69fd8c709348230142b236805f83a8bfb6b.tar.bz2 perlweeklychallenge-club-7cf2d69fd8c709348230142b236805f83a8bfb6b.zip | |
Merge pull request #183 from kyzn/kivanc.w10
Kivanc Week 10 Challenge 1 solution
| -rw-r--r-- | challenge-010/kivanc-yazan/perl5/ch-1.pl | 22 |
1 files changed, 22 insertions, 0 deletions
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"; |
