Computer Science Canada Super7 |
Author: | compudave [ Mon Nov 10, 2003 10:45 pm ] |
Post subject: | Super7 |
Hi I'm taking the grade 11 Computer Info & Sci course. I'd like some help with this program. This program is supposed to randomly choose 7 numbers, the only problem is sometimes these numbers are chosen twice. My question is, what can I add that will make the program not choose the same number twice? Quote: randomize
var i : int put "Super7 Lottery Number Chooser" for count : 1 ..7 randint(i, 1, 47) put i end for |
Author: | Chimaera [ Mon Nov 10, 2003 10:54 pm ] |
Post subject: | |
easy, just set up 7 randints separately and make it redo itself if it is equal to a number that has already been selected. Ta da! 8) |
Author: | Tony [ Mon Nov 10, 2003 11:08 pm ] |
Post subject: | |
no no no tsk tsk tsk you do not to that I've already wrote up the code for generating a list of random unique numbers, it is here |
Author: | Chimaera [ Mon Nov 10, 2003 11:15 pm ] |
Post subject: | |
Here's exactly what your program should be doing <code> randomize var i, a, b, c, d, e,f : int put "Super7 Lottery Number Chooser" randint (a, 1, 47) randint (b, 1, 47) randint (c, 1, 47) randint (d, 1, 47) randint (e, 1, 47) randint (f, 1, 47) randint (i, 1, 47) loop if a = b or a = c or a = d or a = e or a = f or a = i then randint (a, 1, 47) elsif b = a or b = c or b = d or b = e or b = f or b = i then randint (b, 1, 47) elsif c = b or c = a or c = d or c = e or c = f or c = i then randint (c, 1, 47) elsif d = b or d = c or d = a or d = e or d = f or d = i then randint (d, 1, 47) elsif e = b or e = c or e = a or e = d or e = f or e = i then randint (e, 1, 47) elsif f = b or f = c or f = a or f = e or f = d or f = i then randint (f, 1, 47) elsif i = b or i = c or i = a or i = e or i = f or i = d then randint (i, 1, 47) end if exit when a not= b and a not= c and a not= d and a not= e and a not= f and a not= i and b not= a and b not= c or b not= d and b not= e and b not= f and b not= i and c not= b and c not= a and c not= d and c not= e and c not= f and c not= i and d not= b and d not= c and d not= a and d not= e and d not= f and d not= i and e not= b and e not= c and e not= a and e not= d and e not= f and e not= i and f not= b and f not= c and f not= a and f not= e and f not= d and f not= i and f not= b and f not= c and f not= a and f not= e and f not= d and f not= i end loop put a, " ", b, " ", c, " ", d, " ", e, " ", f, " ", i </code> |
Author: | PaddyLong [ Tue Nov 11, 2003 1:06 pm ] |
Post subject: | |
ohhh please noooo don't do it the way Chimaera says... that way is horrible... using wayyy more variables than you need.... sure that way works but it's not a very good way to do it |
Author: | compudave [ Tue Nov 11, 2003 1:28 pm ] |
Post subject: | |
lol, yeah thanks for the coding but that's a lot of variables... i'm going to try and work with the other code... |
Author: | AsianSensation [ Tue Nov 11, 2003 7:21 pm ] |
Post subject: | |
lol, Chimaera, what if someone wanted 100 different numbers? by your method, then it would take (100(101))/2, or 5050 different comparisons. codes have to be effiecient and clean,, and usually have to deal with any situation of it's type. |
Author: | Tony [ Tue Nov 11, 2003 7:29 pm ] | ||
Post subject: | |||
doesn't anyone ever look at my code I'll post it here, not just the link this time
|
Author: | Chimaera [ Tue Nov 11, 2003 9:04 pm ] |
Post subject: | |
wow I am so shamed by tony =_= well actually tony didn't shame me, I shamed myself by putting up my cruddy code. I don't really think in terms of that, I just think of doing what the question asks specifically as opposed to allowing it to be more open ended and perhaps using it for other things in the future. Props to tony for doing that stuff though |
Author: | Tony [ Tue Nov 11, 2003 11:08 pm ] |
Post subject: | |
heh, dont worry about that Chimaera this comes with experience. Everybody starts off with programing a program that acomplishes a task, but with experience and knowledge, you'll begin to see a bigger picture. And as far as I know, when it comes to programming - there's a LOT of changes between original goal and final product. Heh - here's an interesting consept you'll come across if you keep on programming long enough : [b]abstract classes[/i]. I learned them in Java 8) They are basically object parts that cannot be used directly, but other objects incorporate in themselves. Though you'd probly need to get into OOP first to understand. |
Author: | Chimaera [ Tue Nov 11, 2003 11:27 pm ] |
Post subject: | |
btw what is this OOP stuff that you guys talk about sometimes. I've heard you guys use the term, but still have no idea just what it is. |
Author: | Tony [ Tue Nov 11, 2003 11:32 pm ] |
Post subject: | |
OOP - Object Oriented Programming. It's a style of programming where you create interactive objects, rether then one continues code that flows one way. It's possible to use OOP in Turing (WinOOT - Windows Object Oriented Turing but it's all a big lie. Noone but Catalyst uses OOP in turing ), you might touch onto it in C++ (I didn't ) but Java is where the fun is at in Java, everything is OOP. Heck, even your variables are objects - each containing it's own properties and methods that can be executed. |
Author: | Blade [ Tue Nov 11, 2003 11:45 pm ] |
Post subject: | |
for the answer to the question... wouldn't it be much better to use a boolean array? because they way tony's doing it you are running a for loop a hella lotta times... maximizing execution time.. |
Author: | Tony [ Tue Nov 11, 2003 11:53 pm ] |
Post subject: | |
blade, you must be on drugs or something Quote: for decreasing i:47..40
thats 7 executions, exactly how many random numbers are needed first for loop is just initialization of the array, something you would also need for a boolean array As I said this before - to randomly pick 1000th unique number, you would have a 1/1000 chance of landing the right number and a hell lots of if statments executed using boolean array method:lol: |
Author: | Blade [ Wed Nov 12, 2003 12:50 pm ] | ||
Post subject: | |||
if your numbers are between like 30 and 40 then chance your boolean array to 30 .. 40 and your Rand.Int between 30 and 40 it works for everything, and its simpler than yours, but i dont know about execution time |
Author: | Catalyst [ Wed Nov 12, 2003 1:05 pm ] |
Post subject: | |
tony- u should look at the OOP in c++, it might not be as "correct" as it is in java but it is really powerful (mutiple inheritance, abstract functions/classes, etc) |
Author: | smith_scott_04 [ Wed Nov 12, 2003 6:38 pm ] | ||
Post subject: | I Have Already Wrote The Program | ||
Here is the lotto 649 game just change a few variables.
|
Author: | Chimaera [ Wed Nov 12, 2003 7:34 pm ] |
Post subject: | |
you can't exit your program without doing it manually. Perhaps you should modify your program to do so, but other than that nice program. It doesn't have much to do with Super 7 though. |
Author: | Tony [ Wed Nov 12, 2003 11:52 pm ] |
Post subject: | |
blade - obviously mine is simpler AND has better execution time... has less lines of code too |
Author: | compudave [ Thu Nov 13, 2003 12:52 am ] |
Post subject: | |
hehe, You said it Tony... |
Author: | hackman [ Thu Nov 13, 2003 11:40 am ] | ||
Post subject: | |||
I had to do the same program, my teacher was happy with a simple
|
Author: | Tony [ Thu Nov 13, 2003 3:18 pm ] | ||
Post subject: | |||
well the chances of
to generate a list of 10 unique numbers... is 1 in 10*9*8...*1 |