From 2bdf51703359ef35c7ec3829ee25be3e89c45490 Mon Sep 17 00:00:00 2001 From: Paulo Custodio Date: Tue, 9 Mar 2021 19:33:35 +0000 Subject: Add Lua and Python solutions to challenge 090 --- challenge-090/paulo-custodio/lua/ch-2.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 challenge-090/paulo-custodio/lua/ch-2.lua (limited to 'challenge-090/paulo-custodio/lua/ch-2.lua') 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..c93074b04f --- /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") -- cgit From c51f9bd979dbd79f20cb0abd543dc9b4df9f4e84 Mon Sep 17 00:00:00 2001 From: Paulo Custodio Date: Tue, 9 Mar 2021 20:01:18 +0000 Subject: Remove tabs --- challenge-090/paulo-custodio/lua/ch-2.lua | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'challenge-090/paulo-custodio/lua/ch-2.lua') diff --git a/challenge-090/paulo-custodio/lua/ch-2.lua b/challenge-090/paulo-custodio/lua/ch-2.lua index c93074b04f..d9e54b052f 100644 --- a/challenge-090/paulo-custodio/lua/ch-2.lua +++ b/challenge-090/paulo-custodio/lua/ch-2.lua @@ -11,18 +11,18 @@ 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 + 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") -- cgit