aboutsummaryrefslogtreecommitdiff
path: root/challenge-090/tyler-wardhaugh/lua/ch-2.lua
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-090/tyler-wardhaugh/lua/ch-2.lua')
-rwxr-xr-xchallenge-090/tyler-wardhaugh/lua/ch-2.lua27
1 files changed, 27 insertions, 0 deletions
diff --git a/challenge-090/tyler-wardhaugh/lua/ch-2.lua b/challenge-090/tyler-wardhaugh/lua/ch-2.lua
new file mode 100755
index 0000000000..85c69b7be8
--- /dev/null
+++ b/challenge-090/tyler-wardhaugh/lua/ch-2.lua
@@ -0,0 +1,27 @@
+#!/usr/bin/env lua
+
+local t2 = {}
+
+function t2.ethiopian_multiply(a, b)
+ local product = 0
+
+ while a > 0 do
+ if a % 2 ~= 0 then
+ product = product + b
+ end
+
+ a = a // 2
+ b = b * 2
+ end
+
+ return product
+end
+
+function t2.run(args)
+ local A = tonumber(args[1]) or 12
+ local B = tonumber(args[2]) or 14
+ local product = t2.ethiopian_multiply(A, B)
+ print(product)
+end
+
+return t2