Isnochys Math Problem #4.1 [HSBI]
Last week we faced the issues of Palindromes.
This week we are going to solve it.
With Python.
First, lets have a look at the obvious solution:
We need to find a Palindrome. Forward is the same as backwards:
str(x*y) == str(x*y)[::-1]
This line takes the product(xy) makes a string out of it, str(xy), inverts that string, [::-1], and compares it to the original string.
"[a:b:c]" is so much fun to work with and every time I get very confused and will google it:))
Next one is to find the values for x and y:
for x in range(9000,10000):
for y in range(x,10000):
We just try numbers above 9000, all the other are not worth to test.
Now mix everything together:
maxpal = 0
for x in range(9000,10000):
for y in range(x,10000):
p = x * y
if str(p) == str(p)[::-1] and p > maxpal:
maxpal = p
print(maxpal)
We run it and get the answer:
99000099
There you go!
But now for the fun one:
max([x*y for x in range(9000,10000) for y in range(x,10000) if str(x*y) == str(x*y)[::-1]])
What is this?
The maximum out of the list:
[x*y for x in range(9000,10000) for y in range(x,10000) if str(x*y) == str(x*y)[::-1]]
The list are items made of the product x*y
and the rest are the same for loops and if statements as described above to filter it.
Result is the same.
This week, there is no homework for you, just post a comment or question and get some BEER
Leave Isnochys Math Problem #4.1 [HSBI] to:
Read more #imp posts
Best Posts From Isnochys
We have not curated any of isnochys's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From Isnochys
- Crowded Calendar
- Adventskalender 2023 1-9
- Adventskalender 2023 1+2
- Wow - Nothing to see here
- Trenchrun
- Isnochys Quiz Alert: Harry Potter #14 [HSBI][SPOILER] Who is not Harry Potters roommate?
- IBooRP: Jim Knopf und Lukas der Lokomotivführer #17 [DEU/ENG][SPOILER]
- Web3 Going Great 2022-05-04
- Isnochys Quiz Alert:Jim Knopf #15 [HSBI] What natural spectacle do they discover in the desert?
- Isnochys Math Problem #5.1
- Isnochys Quiz Alert:Star Trek #12 [HSBI] What Captain did Picard never talk with?
- Isnochys Quiz Alert: Harry Potter #13 [HSBI][SPOILER] What House is Harry offered to join?
- Hive-Engine Witness active!
- IBooRP: Jim Knopf und Lukas der Lokomotivführer #16 [DEU/ENG][SPOILER]
- Isnochys Quiz Alert:Jim Knopf #14 [HSBI] What animals wait for Jim and Lukas in the desert?
- Isnochys Math Problem #5 [HBSI]
- Isnochys Quiz Alert:Star Trek #12 [HSBI] What law prohibits interaction with preWarp cultures?
- Tag des Bieres 🍻 und Buches 📚 Day of Beer 🍻 and Books 📚
- Isnochys Quiz Alert: Harry Potter #12 [HSBI][SPOILER] Students are choosen into different Houses by the Sorting ...?
- IBooRP: Jim Knopf und Lukas der Lokomotivführer #15 [DEU/ENG][SPOILER]