aboutsummaryrefslogtreecommitdiff
path: root/challenge-090/paulo-custodio/lua/ch-2.lua
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-090/paulo-custodio/lua/ch-2.lua')
-rw-r--r--challenge-090/paulo-custodio/lua/ch-2.lua28
1 files changed, 28 insertions, 0 deletions
diff --git a/challenge-090/paulo-custodio/lua/ch-2.lua b/challenge-090/paulo-custodio/lua/ch-2.lua
new file mode 100644
index 0000000000..d9e54b052f
--- /dev/null
+++ b/challenge-090/paulo-custodio/lua/ch-2.lua
@@ -0,0 +1,28 @@
+#!/usr/bin/env lua
+
+--[[
+Challenge 090
+
+TASK #2 > Ethiopian Multiplication
+Submitted by: Mohammad S Anwar
+You are given two positive numbers $a and $b.
+
+Write a script to demonstrate Ethiopian Multiplication using the given numbers.
+--]]
+
+function mul(a, b)
+ local m = 0
+ while (true) do
+ if ((a & 1) ~= 0) then
+ m = m + b
+ end
+ if (a <= 1) then
+ break
+ end
+ a = a >> 1
+ b = b << 1
+ end
+ return m
+end
+
+io.write(mul(tonumber(arg[1]), tonumber(arg[2])), "\n")