June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -0,0 +1,11 @@
|
|||
Private Function lngHalve(Nb As Long) As Long
|
||||
lngHalve = Nb / 2
|
||||
End Function
|
||||
|
||||
Private Function lngDouble(Nb As Long) As Long
|
||||
lngDouble = Nb * 2
|
||||
End Function
|
||||
|
||||
Private Function IsEven(Nb As Long) As Boolean
|
||||
IsEven = (Nb Mod 2 = 0)
|
||||
End Function
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
Private Function Ethiopian_Multiplication_Non_Optimized(First As Long, Second As Long) As Long
|
||||
Dim Left_Hand_Column As New Collection, Right_Hand_Column As New Collection, i As Long, temp As Long
|
||||
|
||||
'Take two numbers to be multiplied and write them down at the top of two columns.
|
||||
Left_Hand_Column.Add First, CStr(First)
|
||||
Right_Hand_Column.Add Second, CStr(Second)
|
||||
'In the left-hand column repeatedly halve the last number, discarding any remainders,
|
||||
'and write the result below the last in the same column, until you write a value of 1.
|
||||
Do
|
||||
First = lngHalve(First)
|
||||
Left_Hand_Column.Add First, CStr(First)
|
||||
Loop While First > 1
|
||||
'In the right-hand column repeatedly double the last number and write the result below.
|
||||
'stop when you add a result in the same row as where the left hand column shows 1.
|
||||
For i = 2 To Left_Hand_Column.Count
|
||||
Second = lngDouble(Second)
|
||||
Right_Hand_Column.Add Second, CStr(Second)
|
||||
Next
|
||||
|
||||
'Examine the table produced and discard any row where the value in the left column is even.
|
||||
For i = Left_Hand_Column.Count To 1 Step -1
|
||||
If IsEven(Left_Hand_Column(i)) Then Right_Hand_Column.Remove CStr(Right_Hand_Column(i))
|
||||
Next
|
||||
'Sum the values in the right-hand column that remain to produce the result of multiplying
|
||||
'the original two numbers together
|
||||
For i = 1 To Right_Hand_Column.Count
|
||||
temp = temp + Right_Hand_Column(i)
|
||||
Next
|
||||
Ethiopian_Multiplication_Non_Optimized = temp
|
||||
End Function
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
Private Function Ethiopian_Multiplication(First As Long, Second As Long) As Long
|
||||
Do
|
||||
If Not IsEven(First) Then Mult_Eth = Mult_Eth + Second
|
||||
First = lngHalve(First)
|
||||
Second = lngDouble(Second)
|
||||
Loop While First >= 1
|
||||
End Function
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
Sub Main_Ethiopian()
|
||||
Dim result As Long
|
||||
result = Ethiopian_Multiplication(17, 34)
|
||||
' or :
|
||||
'result = Ethiopian_Multiplication_Non_Optimized(17, 34)
|
||||
Debug.Print result
|
||||
End Sub
|
||||
Loading…
Add table
Add a link
Reference in a new issue