Project Euler #4 Python while loop efficiency: palindromic number
The problem statement for Project Euler Problem 4 is as follows:
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 ×ばつ 99. Find the largest palindrome made from the product of two 3-digit numbers.
LookingI'm looking to make this code more efficient, especially the while
loop. I'm using a variable to pass into the function so that the answer to ints of various lengths can be determined. It's been the most efficient that I've been able to come up with. Any suggestions?
def largestPalindromeProduct(digits):
num=int(digits*"9")
maxPalindrome=0
i=int(num)
floor=int(num/10) if digits > 1 else -1
while i > floor:
j=i
while j > floor:
val=str(i*j)
if val==val[::-1]:
floor=j
maxPalindrome=max(maxPalindrome,i*j)
j-=1
i-=1
return maxPalindrome
print(largestPalindromeProduct(3))
Project Euler #4 Python while loop efficiency
The problem statement for Project Euler Problem 4 is as follows:
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 ×ばつ 99. Find the largest palindrome made from the product of two 3-digit numbers.
Looking to make this code more efficient. I'm using a variable to pass into the function so that the answer to ints of various lengths can be determined. It's been the most efficient that I've been able to come up with. Any suggestions?
def largestPalindromeProduct(digits):
num=int(digits*"9")
maxPalindrome=0
i=int(num)
floor=int(num/10) if digits > 1 else -1
while i > floor:
j=i
while j > floor:
val=str(i*j)
if val==val[::-1]:
floor=j
maxPalindrome=max(maxPalindrome,i*j)
j-=1
i-=1
return maxPalindrome
print(largestPalindromeProduct(3))
Project Euler #4: palindromic number
The problem statement for Project Euler Problem 4 is as follows:
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 ×ばつ 99. Find the largest palindrome made from the product of two 3-digit numbers.
I'm looking to make this code more efficient, especially the while
loop. I'm using a variable to pass into the function so that the answer to ints of various lengths can be determined. It's been the most efficient that I've been able to come up with. Any suggestions?
def largestPalindromeProduct(digits):
num=int(digits*"9")
maxPalindrome=0
i=int(num)
floor=int(num/10) if digits > 1 else -1
while i > floor:
j=i
while j > floor:
val=str(i*j)
if val==val[::-1]:
floor=j
maxPalindrome=max(maxPalindrome,i*j)
j-=1
i-=1
return maxPalindrome
print(largestPalindromeProduct(3))
The problem statement for Project Euler Problem 4 is as follows:
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 ×ばつ 99. Find the largest palindrome made from the product of two 3-digit numbers.
Looking to make this code more efficient. I'm using a variable to pass into the function so that the answer to ints of various lengths can be determined. It's been the most efficient that I've been able to come up with. Any suggestions?
def largestPalindromeProduct(digits):
num=int(digits*"9")
maxPalindrome=0
i=int(num)
floor=int(num/10) if digits > 1 else -1
while i > floor:
j=i
while j > floor:
val=str(i*j)
if val==val[::-1]:
floor=j
maxPalindrome=max(maxPalindrome,i*j)
j-=1
i-=1
return maxPalindrome
print(largestPalindromeProduct(3))
Looking to make this code more efficient. I'm using a variable to pass into the function so that the answer to ints of various lengths can be determined. It's been the most efficient that I've been able to come up with. Any suggestions?
def largestPalindromeProduct(digits):
num=int(digits*"9")
maxPalindrome=0
i=int(num)
floor=int(num/10) if digits > 1 else -1
while i > floor:
j=i
while j > floor:
val=str(i*j)
if val==val[::-1]:
floor=j
maxPalindrome=max(maxPalindrome,i*j)
j-=1
i-=1
return maxPalindrome
print(largestPalindromeProduct(3))
The problem statement for Project Euler Problem 4 is as follows:
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 ×ばつ 99. Find the largest palindrome made from the product of two 3-digit numbers.
Looking to make this code more efficient. I'm using a variable to pass into the function so that the answer to ints of various lengths can be determined. It's been the most efficient that I've been able to come up with. Any suggestions?
def largestPalindromeProduct(digits):
num=int(digits*"9")
maxPalindrome=0
i=int(num)
floor=int(num/10) if digits > 1 else -1
while i > floor:
j=i
while j > floor:
val=str(i*j)
if val==val[::-1]:
floor=j
maxPalindrome=max(maxPalindrome,i*j)
j-=1
i-=1
return maxPalindrome
print(largestPalindromeProduct(3))
Project Euler #4 Python while loop efficiency
Looking to make this code more efficient. I'm using a variable to pass into the function so that the answer to ints of various lengths can be determined. It's been the most efficient that I've been able to come up with. Any suggestions?
def largestPalindromeProduct(digits):
num=int(digits*"9")
maxPalindrome=0
i=int(num)
floor=int(num/10) if digits > 1 else -1
while i > floor:
j=i
while j > floor:
val=str(i*j)
if val==val[::-1]:
floor=j
maxPalindrome=max(maxPalindrome,i*j)
j-=1
i-=1
return maxPalindrome
print(largestPalindromeProduct(3))