{"id":152,"date":"2011-10-12T11:16:54","date_gmt":"2011-10-12T16:16:54","guid":{"rendered":"http:\/\/thenoyes.com\/littlenoise\/?p=152"},"modified":"2011-10-12T11:16:54","modified_gmt":"2011-10-12T16:16:54","slug":"reverse-roman-numerals","status":"publish","type":"post","link":"https:\/\/thenoyes.com\/littlenoise\/?p=152","title":{"rendered":"Reverse Roman Numerals"},"content":{"rendered":"<p>Translate from Roman Numerals back to decimal. Legal range is 0 to 3999 (that is, N to MMMCMXCIX) You can use IV or IIII for 4. You could even use a string of twenty I&#8217;s for 20, but there&#8217;s a string limit of 15, since that&#8217;s the length of the biggest well-formed numeral below 3999.<\/p>\n<pre>CREATE FUNCTION fromRoman (inRoman varchar(15)) RETURNS integer DETERMINISTIC\r\nBEGIN\r\n\r\n    DECLARE numeral CHAR(7) DEFAULT 'IVXLCDM';\r\n\r\n    DECLARE digit TINYINT;\r\n    DECLARE previous INT DEFAULT 0;\r\n    DECLARE current INT;\r\n    DECLARE sum INT DEFAULT 0;\r\n\r\n    SET inRoman = UPPER(inRoman);\r\n\r\n    WHILE LENGTH(inRoman) > 0 DO\r\n        SET digit := LOCATE(RIGHT(inRoman, 1), numeral) - 1;\r\n        SET current := POW(10, FLOOR(digit \/ 2)) * POW(5, MOD(digit, 2));\r\n        SET sum := sum + POW(-1, current < previous) * current;\r\n        SET previous := current;\r\n        SET inRoman = LEFT(inRoman, LENGTH(inRoman) - 1);\r\n    END WHILE;\r\n\r\n    RETURN sum;\r\nEND<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Translate from Roman Numerals back to decimal. Legal range is 0 to 3999 (that is, N to MMMCMXCIX) You can use IV or IIII for 4. You could even use a string of twenty I&#8217;s for 20, but there&#8217;s a string limit of 15, since that&#8217;s the length of the biggest well-formed numeral below 3999. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4],"tags":[],"class_list":["post-152","post","type-post","status-publish","format-standard","hentry","category-mysql"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2IBF1-2s","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=152"}],"version-history":[{"count":1,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/152\/revisions"}],"predecessor-version":[{"id":153,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/152\/revisions\/153"}],"wp:attachment":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}