{"id":297,"date":"2010-08-20T20:01:35","date_gmt":"2010-08-21T01:01:35","guid":{"rendered":"http:\/\/anvil-of-time.com\/wordpress\/?p=297"},"modified":"2021-03-09T08:04:58","modified_gmt":"2021-03-09T13:04:58","slug":"powerbuilder-ethiopian-multiplication","status":"publish","type":"post","link":"https:\/\/anvil-of-time.com\/powerbuilder\/powerbuilder-ethiopian-multiplication\/","title":{"rendered":"PowerBuilder &#8211; Ethiopian multiplication"},"content":{"rendered":"<p>I stumbled across this task on the Rosetta Code website. (<a href=\"http:\/\/rosettacode.org\/wiki\/Ethiopian_Multiplication\">Link here<\/a>) Of course I decided to do the task and, as a result, added Powerbuilder to the Rosetta Code website list of languages. There are plenty of other tasks to do so get crackin&#8217;.<\/p>\n<p>The process of this method of multiplication is to write down the numbers to be multiplied in two columns. Take the left number and halve it (dropping fractions) and put that number as a new entry in the column until you reach one (1). Then take the second (rightmost) number and double it for every row on the left. Cross out any rows where the left column number is even. Add the remaining numbers from the right column to obtain the answer. The link above to Rosetta Code shows this process in a concise manner.<\/p>\n<p>The task is to create four functions.<\/p>\n<p>Function one determines if a number is even.<br \/>\nFunction two halves a number.<br \/>\nFunction three doubles a number.<br \/>\nFunction four puts them all together to perform the process.<\/p>\n<p>Here are my answers:<\/p>\n<pre name=\"code\" class=\"VB\">public function boolean wf_iseven (long al_arg);\nreturn mod(al_arg, 2 ) = 0\nend function\n\npublic function long wf_halve (long al_arg);\nRETURN int(al_arg \/ 2)\nend function\n\npublic function long wf_double (long al_arg);\nRETURN al_arg + al_arg\nend function\n\npublic function long wf_ethiopianmultiplication (long al_multiplicand, long al_multiplier);\n\/\/ calculate result\nlong ll_product\n\nDO WHILE al_multiplicand &gt;= 1\n\tIF wf_iseven(al_multiplicand) THEN\n\t\t\/\/ do nothing\n\tELSE\n\t\tll_product += al_multiplier\n\tEND IF\n\tal_multiplicand = wf_halve(al_multiplicand)\n\tal_multiplier = wf_double(al_multiplier)\nLOOP\n\nreturn ll_product\nend function<\/pre>\n<p>I also wrote a simple app to show the process via a datawindow and to perform the function call. The datawindow example makes use of expressions to determine which rows to use to obtain the final answer.<br \/>\n<a href=\"http:\/\/anvil-of-time.com\/wordpress\/wp-content\/uploads\/2010\/08\/EthMultiply.png\"><img loading=\"lazy\" class=\"aligncenter wp-image-298 size-full\" title=\"Ethopian Multiplication\" src=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2010\/08\/EthMultiply.png\" alt=\"\" width=\"351\" height=\"345\" srcset=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2010\/08\/EthMultiply.png 351w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2010\/08\/EthMultiply-300x294.png 300w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2010\/08\/EthMultiply-150x147.png 150w\" sizes=\"(max-width: 351px) 100vw, 351px\" \/><\/a><br \/>\nThe example .pbl is written in pb11.5 but it includes exports of the objects so you can bring it back to whatever version you are using.<br \/>\n<a href=\"http:\/\/anvil-of-time.com\/wordpress\/wp-content\/uploads\/2010\/08\/eth_multiplication.zip\">eth_multiplication.zip file<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I stumbled across this task on the Rosetta Code website. (Link here) Of course I decided to do the task and, as a result, added Powerbuilder to the Rosetta Code website list of languages. There are plenty of other tasks to do so get crackin&#8217;. The process of this method of multiplication is to write&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,10],"tags":[12,16],"_links":{"self":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/297"}],"collection":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/comments?post=297"}],"version-history":[{"count":9,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/297\/revisions"}],"predecessor-version":[{"id":1800,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/297\/revisions\/1800"}],"wp:attachment":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/media?parent=297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/categories?post=297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/tags?post=297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}