Posts: 31
Threads: 5
Joined: Jan 2021
Jan-10-2021, 04:55 PM
(This post was last modified: Jan-10-2021, 05:04 PM by Kakha.)
'''
this formula is calculated from right to left, but only if a = c, for example: 11 * 15, 55 * 59, 97 * 92
who can change the formula so that it counts when a != c for example: 11 * 35, 55 * 19, 97 * 42
(a b c d < 10)
'''
a = 1
b = 2
c = a
d = 9
sum1 = b * d
D1=sum1 % 10
D1_Memo= sum1 // 10
sum2 =(b+d)*a + D1_Memo
D2=sum2 % 10
D2_Memo= sum2 // 10
D3 = a * c + D2_Memo
print(a,b,"*",c,d,"=",D3,D2,D1) Output: 1 2 * 1 9 = 2 2 8
Posts: 8,168
Threads: 160
Joined: Sep 2016
Jan-10-2021, 05:06 PM
(This post was last modified: Jan-10-2021, 05:06 PM by buran.)
Is there question here? It's completely unclear what your goal is.
Posts: 31
Threads: 5
Joined: Jan 2021
(Jan-10-2021, 05:05 PM)buran Wrote: Is there question here? Yes
Posts: 8,168
Threads: 160
Joined: Sep 2016
Posts: 31
Threads: 5
Joined: Jan 2021
Posts: 8,168
Threads: 160
Joined: Sep 2016
(Jan-10-2021, 05:15 PM)Kakha Wrote: the function calculates all multiplications for numbers 0-99 that start with the same digit
you need to get a formula that works for all numbers 0-99 that don't start with the same digit there is NO function present in your code.
And we don't need to do anything - it's you [home]work. If you want help, help us to help you, don't make us guess.
Posts: 31
Threads: 5
Joined: Jan 2021
(Jan-10-2021, 05:19 PM)buran Wrote: (Jan-10-2021, 05:15 PM)Kakha Wrote: the function calculates all multiplications for numbers 0-99 that start with the same digit
you need to get a formula that works for all numbers 0-99 that don't start with the same digit there is NO function present in your code.
And we don't need to do anything - it's you [home]work. If you want help, help us to help you, don't make us guess.
this is a question for mathematicians
Posts: 4,803
Threads: 77
Joined: Jan 2018
Jan-10-2021, 06:29 PM
(This post was last modified: Jan-10-2021, 06:31 PM by Gribouillis.)
Replace (b + d)*a by a*d + b*c and it will work.
Posts: 31
Threads: 5
Joined: Jan 2021
(Jan-10-2021, 06:29 PM)Gribouillis Wrote: Replace (b + d)*a by a*d + b*c and it will work.
'''
thanks Gribouillis it works !!!
'''
a = 1
b = 5
c = 9
d = 4
sum1 = b * d
D1=sum1 % 10
D1_Memo= sum1 // 10
sum2 =a*d + b*c + D1_Memo
D2=sum2 % 10
D2_Memo= sum2 // 10
D3 = a * c + D2_Memo
print(a,b,"*",c,d,"=",D3,D2,D1) Output: 1 5 * 9 4 = 14 1 0
Posts: 4,803
Threads: 77
Joined: Jan 2018
Note that
D1=sum1 % 10
D1_Memo= sum1 // 10 can be shortened in
D1_Memo, D1 = divmod(sum1, 10)
|