This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-01-17 22:17:01

occlumencymaster
Scratcher
Registered: 2009-07-08
Posts: 16

make a sum of variables equal to a number? (and other questions)

I was trying to create a sudoku solving engine and realized I have no idea how. Mainly to better my knowledge of scratch, I was just wondering how I might write a script to set a sum of variables equal to a number (in this case 45: i.e. v1 + v2 +v3 +v4 +v5 +v6 +v7 +v8 +v9= 45)

Also, how do I ensure that v1 is not equal to v2 or v3 or v5 or etc and that it is a number 1-9?

These are very complicated questions and I apologize but if you could help that would be great.

I realize lists are a viable option but I can't figure out how to make them work for what I want to do.

Offline

 

#2 2011-01-17 22:37:42

Jonathanpb
Scratcher
Registered: 2008-07-25
Posts: 1000+

Re: make a sum of variables equal to a number? (and other questions)

Well, in these types of things you'll have to use lists...

I made a script for this - first, it fills a list with the numbers 1 to 9 - then, it fills a second list by (repeatedly until all the numbers have been used) randomly choosing one of the items from the first list, taking the number from the item and placing it in the second list, and then deleting the item from the first list so it can't be used again.

Here's the script:

http://img844.imageshack.us/img844/2876/369randomlyorderingthen.png

Is that understandable?


"Human beings... must have action; and they will make it if they cannot find it.
-Charlotte Brontë

Offline

 

#3 2011-01-18 07:56:00

Lar-Rew
Scratcher
Registered: 2010-02-19
Posts: 100+

Re: make a sum of variables equal to a number? (and other questions)

To sum the entries of a list, you can use this:

http://lasergnlsdjkfila.weebly.com/uploads/4/6/4/3/4643709/4055198.gif

Offline

 

Board footer