Discuss Scratch

JAVAProgramming
Scratcher
100+ posts

Script Not Doing What It's Supposed To Do

My new little project is not working the way it's supposed to.

The point of the project it to find the next perfect number. A Perfect number is a number that, when all of its proper divisors are added up, equals the sum of its factors. So the script is supposed to find all of the factors, then add them up to see if the number being tested = sum of the factors. But the script just keeps adding to the #BeingTested variable, with nothing else happening.


Some help would be appreciated!
J

My Newest Project, Come Check It Out
Dots, On Scratch
Want to change the way we count? The Dozenal System.

“The story so far:
In the beginning the Universe was created.
This has made a lot of people very angry and been widely regarded as a bad move.”
― Douglas Adams, The Restaurant at the End of the Universe
scubajerry
Scratcher
1000+ posts

Script Not Doing What It's Supposed To Do

See remix

Last edited by scubajerry (Oct. 29, 2013 19:37:05)

DadOfMrLog
Scratcher
1000+ posts

Script Not Doing What It's Supposed To Do

It may be worth replacing your divisor check (the one that looks for a dot in the answer) with a check that the remainder is zero using the “mod” function:
if <((number) mod (divisor)) = (0) > then
change [sum v] by (divisor) // "divisor" divides into "number" exactly, so add it to sum
end
That will help make your script look simpler, which could help you track your way through it to check it's doing what you expect.

I presume you're not wanting to go as far as trying to find these perfect numbers via Mersenne primes…?

A final thought: when looking for factors of a number, you only need to go as far as its square-root (rounded down). When you find a factor, you can add that factor to the sum, and immediately also add the value of the number that comes from dividing by that factor.

Hope that helps!


Alternate account: TheLogFather –– HowTos and useful custom blocks (see studio). Examples below…


- String manipulation - - - X to power of Y - - - Clone point to clone - Detect New Scratcher - Speed tests studio -

lafoudre
Scratcher
100+ posts

Script Not Doing What It's Supposed To Do

Well, I went to see your project, but nothing happen.
Discouraged ?
Just ask help and tell people that you want to learn something, not to read solutions.

Choose another challenge (number theory has lots of them) and if you have question, tell not to remix your project !!!

Powered by DjangoBB