aboutsummaryrefslogtreecommitdiff
path: root/challenge-090/paulo-custodio/python/ch-2.py
blob: 29efd0d5073762c30864570a3549bd3f20b418a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python

# 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.

import sys

def mul(a,b):
    mul = 0
    while True:
        if (a & 1) != 0:
            mul += b
        if a <= 1:
            break
        a >>= 1
        b <<= 1
    return mul

print(mul(int(sys.argv[1]), int(sys.argv[2])))