- 1

Write a function that computes the biggest product of 2 adjacent digits

the number is large_number = "6265625639770930589729165948157604396883137944753038530630802554971098857083971475495106467594633963" how can I write a python function to find the biggest product of 2 adjacent digits in the above number ? Than you!

5th Oct 2020, 1:05 PM
Bia_U
Bia_U - avatar
8 ответов
+ 6
Velouria Darkstar , before we can help you, you should do a try by yourself first. put your code in playground and link it here. Thanks!
5th Oct 2020, 2:44 PM
Lothar
Lothar - avatar
+ 6
thanks for sharing your code. here is the approach i made. https://code.sololearn.com/coT03yYVzdfc/?ref=app
5th Oct 2020, 4:15 PM
Lothar
Lothar - avatar
+ 3
Then use what you know! create a function that takes a string, then creates a list out of said string. You know what to do after that
5th Oct 2020, 1:20 PM
Slick
Slick - avatar
+ 1
No worries, thank you for the attempt. Check this out: https://code.sololearn.com/cVGsOLTQFX0E/?ref=app
5th Oct 2020, 3:21 PM
Slick
Slick - avatar
+ 1
Velouria Darkstar edited your code to get correct way. Hope it helps to idenify correct approach of your way. https://code.sololearn.com/c7tbMKG9ZemM/?ref=app
5th Oct 2020, 4:26 PM
Jayakrishna 🇮🇳
0
9*8=72 is the answer for this? If yes, then find max(list(large_number)) Large_number.indexof(max)*large_number.indexof(max+1, or - 1), next find next repeat this for from index max(list(str(large_number.substring(large_number.index(max)+1)).. If greater one replace it with previous one.. You said you know about array method so if this is same as you know, then ingore it.
5th Oct 2020, 1:34 PM
Jayakrishna 🇮🇳
0
(sorry I'm new here and very much struggling with Python) I tried something like this but it's wrong because it keeps giving me 1,0,1,0.... the correct answer is supposed to be 72 import sys def biggestProduct(string, m) : n = len(string) maxProd = (-(sys.maxsize) - 1, -(sys.maxsize) - 1) for i in range(n - m) : product = 1, 0 for j in range(i, m + i) : product = product * (ord(string[j]) - ord('0')) maxProd = max(maxProd, product) print("Biggest Product =", maxProd) if __name__ == "__main__" : string = "6265625639770930589729165948157604396883137944753038530630802554971098857083971475495106467594633963" m = 2 biggestProduct(string, m)
5th Oct 2020, 3:01 PM
Bia_U
Bia_U - avatar
0
Hi
6th Oct 2020, 11:35 PM
Randy Adomako