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

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




PostPosted: Fri Jun 03, 2005 10:59 am   Post subject: Shuffle Algorithm

I need an algorithm that takes my 2d array (1..4, 1..4) and gives each coord (the first array in the 2d is the x, the second is the y) a number from 1 through 16. Each number must be used only once.

Thanks
Sponsor
Sponsor
Sponsor
sponsor
rizzix




PostPosted: Fri Jun 03, 2005 11:29 am   Post subject: (No subject)

n = y*4 + x
Artimes




PostPosted: Fri Jun 03, 2005 11:37 am   Post subject: (No subject)

Wouldn't that give me the same output every time?
lyam_kaskade




PostPosted: Fri Jun 03, 2005 11:41 am   Post subject: (No subject)

code:

for y:0..3
    for x:0..3
       array (x,y):=(y*4+x) + 1
    end for
end for
GlobeTrotter




PostPosted: Fri Jun 03, 2005 4:38 pm   Post subject: (No subject)

Artimes wrote:
Wouldn't that give me the same output every time?


Yes it would, I don't know what these people are talking about.

First go through and assign them normal values, in order 1 - 16 then,
go through the two degrees in nested for loops. In these loops pick a random numer between 1 and 16 and swap the given element with the random one.
Artimes




PostPosted: Fri Jun 03, 2005 8:11 pm   Post subject: (No subject)

Thanks GlobeTrotter, I got it workin'! Very Happy
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  [ 6 Posts ]
Jump to:   


Style:  
Search: