r/dailyprogrammer • u/rya11111 3 1 • Jun 18 '12
[6/18/2012] Challenge #66 [easy]
Write a function that takes two arguments, x and y, which are two strings containing Roman Numerals without prefix subtraction (so for instance, 14 is represented as XIIII, not XIV). The function must return true if and only if the number represented by x is less than the number represented by y. Do it without actually converting the Roman numerals into regular numbers.
Challenge: handle prefix subtraction as well.
- Thanks to cosmologicon for the challenge at /r/dailyprogrammer_ideas ! LINK .. If you think you got any challenge worthy for this sub submit it there!
27
Upvotes
3
u/ashashwat Jun 18 '12 edited Jun 18 '12
In Haskell,
Test here,
2
u/[deleted] Jun 18 '12
Ruby, the slightly obfuscated (and slightly cheaty) way!
2
u/huck_cussler 0 0 Jun 19 '12
Fun!
1
u/drb226 0 0 Jun 19 '12
Haskell, cheating a bit:
Testing:
1
u/[deleted] Jun 19 '12
Java:
1
u/SangriaSunrise Jun 21 '12 edited Jun 21 '12
J:
using nooodl's approach:
1
u/whodatcoder Jun 26 '12
This should cover the challenge as well
Python:
1
u/justanasiangirl Jun 28 '12 edited Jun 28 '12
PHP version. Took me a while, lol.
<?php function x_smaller_than_y($x_num,$y_num) { $evaluation= array("M","D","C","L","X","V","I"); $x_num_arr = str_split($x_num); $y_num_arr = str_split($y_num); for ($evaluate = 0; $evaluate<7;$evaluate++) { $counter = 0; while ( $counter < ((strlen($x_num)))&& $counter < ((strlen($y_num)))) {if ($x_num_arr[$counter]==$y_num_arr[$counter]) { $counter++; } elseif(($x_num_arr[$counter]!=$evaluation[$evaluate])&&($y_num_arr[$counter]==$evaluation[$evaluate])) {return true; $evaluate=8; break;} elseif(($x_num_arr[$counter]==$evaluation[$evaluate])&&( $y_num_arr[$counter]!=$evaluation[$evaluate])) {return false; $evaluate=8; break;} else {$counter++;} } } if ($evaluate<8&&(strlen($x_num) < strlen($y_num))) {return true;} elseif ($evaluate<8&&(strlen($x_num) > strlen($y_num))) {return false;} } ?>
1
u/paininthebass Jul 31 '12
In c++:
1
u/systemUp Jun 18 '12 edited Jun 20 '12
C++
1
u/loonybean 0 0 Jun 18 '12 edited Jun 18 '12
Python:
1
u/ZebbRa Jun 19 '12 edited Jun 19 '12
Python