Last active
January 26, 2019 07:05
-
-
Save afrieirham/722b09f195d5eec254d22528ee134b0c to your computer and use it in GitHub Desktop.
Solution to Project Euler #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def isPalindrome(number): | |
string = str(number) | |
list = [] | |
revList = [] | |
i = 0; | |
while i<len(string): | |
list.append(string[i]) | |
i += 1 | |
i = len(string)-1 | |
while i>=0: | |
revList.append(string[i]) | |
i -= 1 | |
i = 0 | |
x = '' | |
while i<len(list): | |
x += str(list[i]) | |
i += 1 | |
i = 0 | |
y = '' | |
while i < len(list): | |
y += str(revList[i]) | |
i += 1 | |
return x==y | |
# Working method | |
def run(): | |
i, j, count, index = 100,100, 0, 0 | |
palin = [] | |
while i<1000: | |
while j<1000: | |
print(str(i) + ', ' + str(j) + ': ' + str(i*j)) | |
if(isPalindrome(i*j)): | |
palin.append(i*j) | |
index += 1 | |
count += 1 | |
j += 1 | |
i += 1 | |
j=100 | |
biggest = 0 | |
for i in palin: | |
if(i>biggest): | |
biggest = i | |
print(biggest) | |
print(len(palin)) | |
run() | |
# Not working | |
# def run(): | |
# i, j, count, index = 999,999, 0, 0 | |
# | |
# palin = [] | |
# | |
# while i>100: | |
# while j>100: | |
# print(str(i) + ', ' + str(j) + ': ' + str(i*j)) | |
# if(isPalindrome(i*j)): | |
# return(i*j) | |
# count += 1 | |
# j -= 1 | |
# i -= 1 | |
# j=999 | |
# | |
# biggest = 0 | |
# for i in palin: | |
# if(i>biggest): | |
# biggest = i | |
# | |
# print(biggest) | |
# print(len(palin)) | |
# | |
# return 'Nothing' | |
# | |
# print(run()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment