The weekly challenge 227 - Task 2: Roman Maths
1 #!/usr/bin/perl
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 use strict;
32 use warnings;
33 use Roman;
34
35 roman_maths("IV", "+", "V");
36 roman_maths("M", "-", "I");
37 roman_maths("X", "/", "II");
38 roman_maths("XI", "*", "VI");
39 roman_maths("VII", "**", "III");
40 roman_maths("V", "-", "V");
41 roman_maths("V", "/", "II");
42 roman_maths("MMM", "+", "M");
43 roman_maths("V", "-", "X");
44
45 sub roman_maths {
46 my ($num1, $oper, $num2) = @_;
47 print "Input: $num1 $oper $num2\n";
48 $num1 = arabic($num1);
49 $num2 = arabic($num2);
50 my $result;
51 eval "\$result = $num1 $oper $num2;";
52 die "eval error $@" if $@;
53 if($result != int($result)) {
54 print "Output: non potest\n";
55 } elsif ( $result < 0 ) {
56 print "Output: non potest\n";
57 } elsif ( $result > 3999 ) {
58 print "Output: non potest\n";
59 } elsif ( $result == 0) {
60 print "Output: nulla\n";
61 } else {
62 print "Output: " . uc(roman($result)) . "\n";
63 }
64 }