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
Don't forget to witness vote for me!:)
Posted with STEMGeeks
Great Post!
!1UP
great comment
!BEER
View or trade
BEER
.Hey @luizeba, here is a little bit of
BEER
from @isnochys for you. Enjoy it!Do you want to win SOME BEER together with your friends and draw the
BEERKING
.You have received a 1UP from @luizeba!
@bee-curator, @ccc-curator, @stem-curator, @vyb-curator, @pob-curator
And they will bring !PIZZA 🍕
Learn more about our delegation service to earn daily rewards. Join the family on Discord.
PIZZA Holders sent $PIZZA tips in this post's comments:
@curation-cartel(12/20) tipped @isnochys (x1)
You can now send $PIZZA tips in Discord via tip.cc!
Bookmarked :)
Hatte noch keine Zeit, das letzte Rätsel auszutesten..
Dann erstmal in Ruhe das !BEER genießen.
View or trade
BEER
.Hey @lammbock, here is a little bit of
BEER
from @isnochys for you. Enjoy it!Learn how to earn FREE BEER each day by staking your
BEER
.Thank you for your witness vote!
Have a !BEER on me!
To Opt-Out of my witness beer program just comment !STOP below
View or trade
BEER
.Hey @lammbock, here is a little bit of
BEER
from @isnochys for you. Enjoy it!Learn how to earn FREE BEER each day by staking your
BEER
.Congratulations @isnochys! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s):
Your next target is to reach 58000 upvotes.
You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word
STOP
To support your work, I also upvoted your post!
Check out the last post from @hivebuzz:
Support the HiveBuzz project. Vote for our proposal!