Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 649 trouble
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
MinionoiniM




PostPosted: Wed Dec 24, 2008 11:30 pm   Post subject: 649 trouble

Ok, so its a school assignment.
Create a program that makes a 649 ticket, using single dimensional arrays.
Im pretty new to turing (first year) so no drawing, or any fancy font styles of anything.
So i dont know if my teacher made this up or not, but does everyone get modules? (just curious)
Any help is greatly apprieciated.

Oh yeah, i dont know how to post what i got so far as a picture, so ill just copy and paste.
Thanks again!
Turing:
var count : array 1 .. 49 of int := init (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
var die, counter, amount, counta : int
counter := 0
counta := 0
put "how many times do you want to roll the die? "
get amount
loop
    counter := counter + 1
    loop
        counta := counta + 1
        randint (die, 1, 49)
        count (die) := count (die) + 1
        for i : 1 .. 49
            put count (i), " " ..
        end for
        put " "
        exit when counta = 6
    end loop
    exit when counter = amount
end loop



Mod Edit: Remember to use syntax tags! Thanks Smile
code:
[syntax="turing"]Code Here[/syntax]
Sponsor
Sponsor
Sponsor
sponsor
DanielG




PostPosted: Wed Dec 24, 2008 11:54 pm   Post subject: RE:649 trouble

1) use turing syntax
2) learn for loops they make life much easier and code easier to read
3)reset counta, you are currently trying to add to the counta after you pass your first ticket and you are reaching far more than 6
4) read 2-3 again.
MinionoiniM




PostPosted: Thu Dec 25, 2008 12:06 am   Post subject: Re: 649 trouble

..turing...syntax? Confused
yes, i am VERY new to this
and i did use a for loop
how would you have six digits picked from one line?
thanks again
Tony




PostPosted: Thu Dec 25, 2008 12:17 am   Post subject: Re: 649 trouble

Turing:

var count : array 1 .. 49 of int
var counter : int
var counta : int

Don't do this.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
MinionoiniM




PostPosted: Thu Dec 25, 2008 12:26 am   Post subject: RE:649 trouble

ok so i took out the counta part and replaced it with a for loop, even though it does the same thing.
Still, how would you pick six digits from one line?
DanielG




PostPosted: Thu Dec 25, 2008 12:42 am   Post subject: RE:649 trouble

use an array to store whether a number has been taken or not, and use a while loop (regular loop) until your randint returns a value that has not been taken. reset the taken array after every time you choose 6 values.
MinionoiniM




PostPosted: Thu Dec 25, 2008 12:53 am   Post subject: RE:649 trouble

Thanks alot i got it!
But how can i ensure no duplicates?
When i put randomize before the randint(die, 1, 49) a value from 1 - 49 will become chosen six times (assuming i rolled once)
Thanks again!
Tony




PostPosted: Thu Dec 25, 2008 2:25 am   Post subject: Re: RE:649 trouble

DanielG @ Thu Dec 25, 2008 12:42 am wrote:
use a while loop (regular loop) until your randint returns a value that has not been taken.

Bad idea. While this might not be apparent in a small sized set, but as you require more numbers, the chance of randomly picking an eligible choice decreases.

Here's a better idea

MinionoiniM @ Thu Dec 25, 2008 12:53 am wrote:
But how can i ensure no duplicates?
When i put randomize before the randint(die, 1, 49)...

randomize? Please read the documentation.
Quote:

Syntax randomize

Description This procedure is obsolete. It was originally used to produce a different sequence of random numbers each time a program executed. With current versions of Turing, the random number sequence is ?randomized? each time a Turing program is executed, eliminating the need for this procedure

On the similar note, randint is deprecated. Use Rand.Int instead.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
MinionoiniM




PostPosted: Thu Dec 25, 2008 7:26 pm   Post subject: RE:649 trouble

Ohh, thats how you show turing code. Thanks mod =D
And hmm, i tried Rand.Reset, which works good actually. Thanks alot everyone =D
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: