{"id":156,"date":"2011-10-12T11:18:20","date_gmt":"2011-10-12T16:18:20","guid":{"rendered":"http:\/\/thenoyes.com\/littlenoise\/?p=156"},"modified":"2011-10-12T11:18:20","modified_gmt":"2011-10-12T16:18:20","slug":"roman-numerals","status":"publish","type":"post","link":"https:\/\/thenoyes.com\/littlenoise\/?p=156","title":{"rendered":"Roman numerals"},"content":{"rendered":"<p>Convert an integer in the range 0 to 3999 to Roman numerals.<\/p>\n<pre>CREATE FUNCTION `toRoman`(inArabic int unsigned) RETURNS varchar(15) CHARSET latin1 DETERMINISTIC\r\nBEGIN\r\n    DECLARE numeral CHAR(7) DEFAULT 'IVXLCDM';\r\n\r\n    DECLARE stringInUse CHAR(3);\r\n    DECLARE position tinyint DEFAULT 1;\r\n    DECLARE currentDigit tinyint;\r\n\r\n    DECLARE returnValue VARCHAR(15) DEFAULT '';\r\n\r\n    IF(inArabic > 3999) THEN RETURN 'overflow'; END IF;\r\n    IF(inArabic = 0) THEN RETURN 'N'; END IF;\r\n\r\n    WHILE position <= CEIL(LOG10(inArabic + .1)) DO\r\n        SET currentDigit := MOD(FLOOR(inArabic \/ POW(10, position - 1)), 10);\r\n\r\n        SET returnValue := CONCAT(\r\n            CASE currentDigit \r\n                WHEN 4 THEN CONCAT(SUBSTRING(numeral, position * 2 - 1, 1), SUBSTRING(numeral, position * 2, 1))\r\n                WHEN 9 THEN CONCAT(SUBSTRING(numeral, position * 2 - 1, 1), SUBSTRING(numeral, position * 2 + 1, 1))\r\n                ELSE CONCAT(\r\n                    REPEAT(SUBSTRING(numeral, position * 2, 1), currentDigit >= 5),\r\n                    REPEAT(SUBSTRING(numeral, position * 2 - 1, 1), MOD(currentDigit, 5))\r\n                )\r\n            END,\r\n            returnValue);\r\n\r\n        SET position := position + 1;\r\n    END WHILE;\r\n    RETURN returnValue;\r\nEND<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Convert an integer in the range 0 to 3999 to Roman numerals. CREATE FUNCTION `toRoman`(inArabic int unsigned) RETURNS varchar(15) CHARSET latin1 DETERMINISTIC BEGIN DECLARE numeral CHAR(7) DEFAULT &#8216;IVXLCDM&#8217;; DECLARE stringInUse CHAR(3); DECLARE position tinyint DEFAULT 1; DECLARE currentDigit tinyint; DECLARE returnValue VARCHAR(15) DEFAULT &#8221;; IF(inArabic > 3999) THEN RETURN &#8216;overflow&#8217;; END IF; IF(inArabic = 0) [&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-156","post","type-post","status-publish","format-standard","hentry","category-mysql"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2IBF1-2w","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/156","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=156"}],"version-history":[{"count":1,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/156\/revisions"}],"predecessor-version":[{"id":157,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/156\/revisions\/157"}],"wp:attachment":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}