Discuss Scratch

jkibbe
Scratcher
32 posts

Solving a math problem with Scratch - reverse palindromes

Hi, I'm trying to solve this problem using Scratch:

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.


Here's an example of how to solve it using Python, but I've yet to find a way to do it in Scratch. This code is a little more efficient than the ‘easy’ approach, which is to multiply two numbers in range 100-999 together and test to see if they ‘read’ the same way forward and backwards. Any ideas?
http://www.codeskulptor.org/#user23_t9ZVehfJLV_0.py
The_Grits
Scratcher
1000+ posts

Solving a math problem with Scratch - reverse palindromes

Hang on!
I am working on a (possible) solution!
jkibbe
Scratcher
32 posts

Solving a math problem with Scratch - reverse palindromes

I'm still working, too! Trying to solve the simpler two-digit times two-digit version, first…!
Firedrake969
Scratcher
1000+ posts

Solving a math problem with Scratch - reverse palindromes

Some code I just thought up, but it may or may not be practical:
Add each character of the number to a list, in order
Add item last of that list to a new list
add item last-1 of that list to a new list

Repeat that

Check if the lists are equal.
jkibbe
Scratcher
32 posts

Solving a math problem with Scratch - reverse palindromes

I figured it out in a similar way. I keep looping through two variables a and b, multiplying them together and checking to see if their product reads the same way forward and backward (using a product varaible and if letter 1 = letter 6 AND letter 2 = letter 5 AND letter 3 = letter 4, then add product to a list)

Thanks all!
The_Grits
Scratcher
1000+ posts

Solving a math problem with Scratch - reverse palindromes

I had the last part of the answer, just not the first part. Good job solving it!
The_Grits
derniersamourai
Scratcher
100+ posts

Solving a math problem with Scratch - reverse palindromes

So, who's the winner (speed): python or scratch ?
KermitMC
Scratcher
100+ posts

Solving a math problem with Scratch - reverse palindromes

Python more likely since it is much easier to code with IMO
derniersamourai
Scratcher
100+ posts

Solving a math problem with Scratch - reverse palindromes

IMO = ?
scubajerry
Scratcher
1000+ posts

Solving a math problem with Scratch - reverse palindromes

derniersamourai wrote:

IMO = ?

In My Opinion
firedrake969_test
Scratcher
500+ posts

Solving a math problem with Scratch - reverse palindromes

jkibbe wrote:

I figured it out in a similar way. I keep looping through two variables a and b, multiplying them together and checking to see if their product reads the same way forward and backward (using a product varaible and if letter 1 = letter 6 AND letter 2 = letter 5 AND letter 3 = letter 4, then add product to a list)

Thanks all!
The one thing you might want to be careful of is that the length could be five characters long (assuming you're multiplying between 100-999).
jkibbe
Scratcher
32 posts

Solving a math problem with Scratch - reverse palindromes

firedrake969_test wrote:

The one thing you might want to be careful of is that the length could be five characters long (assuming you're multiplying between 100-999).

Agreed. I decided to go for the six digit number approach first and then modifying the code if no palindrome was found since most of the products are six digit numbers.

The Python code I posted (http://www.codeskulptor.org/#user23_t9ZVehfJLV_0.py) pretty much gives the correct solution instantaneously. My Scratch code also gets the correct answer almost instantly, but it continues to run and check other numbers (which are less likely to be correct since the numbers used are smaller). It does, however, produce a list of 506 palindromes that are the product of two 2-digit numbers in about 30 seconds. Interestingly, the first two palindromes calculated are not the greatest, presumably because they are the product of one really big and one not-so-big number. If I could clean up my code a little, it would be more efficient and run faster.

Update: when I run the program in Turbo mode, it produces the correct answer and the list of 506 palindromes in about two seconds. I can live with that!
s402311
Scratcher
1 post

Solving a math problem with Scratch - reverse palindromes

brown
deck26
Scratcher
1000+ posts

Solving a math problem with Scratch - reverse palindromes

s402311 wrote:

brown
Please don't spam or necropost - not a good start for your first post.

Powered by DjangoBB