Click here to Skip to main content
15,914,165 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: Find an emtpy entry in a 3x3 grid? Pin
Neo1010118-Jul-11 6:24
Neo1010118-Jul-11 6:24 
GeneralRe: Find an emtpy entry in a 3x3 grid? Pin
David198718-Jul-11 6:31
David198718-Jul-11 6:31 
GeneralRe: Find an emtpy entry in a 3x3 grid? Pin
Neo1010118-Jul-11 6:47
Neo1010118-Jul-11 6:47 
GeneralRe: Find an emtpy entry in a 3x3 grid? Pin
David198718-Jul-11 7:03
David198718-Jul-11 7:03 
GeneralRe: Find an emtpy entry in a 3x3 grid? Pin
Neo1010118-Jul-11 7:04
Neo1010118-Jul-11 7:04 
GeneralRe: Find an emtpy entry in a 3x3 grid? Pin
Wjousts21-Jul-11 9:45
Wjousts21-Jul-11 9:45 
QuestionCollision detection? [modified] Pin
Neo1010116-Jul-11 4:29
Neo1010116-Jul-11 4:29 
AnswerRe: Collision detection? [modified] Pin
Wjousts21-Jul-11 9:30
Wjousts21-Jul-11 9:30 
What you did is fine for a 3x3 grid. But a more efficient way would be to produce a list of all the possible pairs of points and then randomly pull a pair from that list, assign it to your item and then remove it from the list. This way you can guarantee no collisions. As a bonus, whatever you have left in the list at the end is all your empty cells.

Whether this method is faster than yours depends on the size of the grid and the number of items in the grid. For example, in a 10 x 10 grid with 99 items, it will almost certainly be faster. In a 10 x 10 grid with 1 item, it certainly isn't.

However, the worst case performance of your algorithm is infinity!

modified on Thursday, July 21, 2011 3:45 PM

QuestionSorting algorithm problem [modified] Pin
Neo1010115-Jul-11 6:56
Neo1010115-Jul-11 6:56 
AnswerRe: Sorting algorithm problem Pin
Wjousts21-Jul-11 9:02
Wjousts21-Jul-11 9:02 
GeneralData Pin
Burt12313-Jul-11 10:23
Burt12313-Jul-11 10:23 
GeneralRe: Data Pin
Richard MacCutchan13-Jul-11 21:48
mveRichard MacCutchan13-Jul-11 21:48 
GeneralRe: Data Pin
Burt12314-Jul-11 7:37
Burt12314-Jul-11 7:37 
GeneralRe: Data Pin
Richard MacCutchan14-Jul-11 8:11
mveRichard MacCutchan14-Jul-11 8:11 
QuestionModulo statement Pin
Lutosław5-Jul-11 1:44
Lutosław5-Jul-11 1:44 
GeneralRe: Modulo statement Pin
David19875-Jul-11 2:05
David19875-Jul-11 2:05 
GeneralRe: Modulo statement Pin
BobJanova5-Jul-11 2:38
BobJanova5-Jul-11 2:38 
GeneralRe: Modulo statement Pin
David19875-Jul-11 3:13
David19875-Jul-11 3:13 
GeneralRe: Modulo statement Pin
Lutosław5-Jul-11 2:47
Lutosław5-Jul-11 2:47 
GeneralRe: Modulo statement Pin
David19875-Jul-11 3:06
David19875-Jul-11 3:06 
GeneralRe: Modulo statement Pin
Lutosław5-Jul-11 5:19
Lutosław5-Jul-11 5:19 
GeneralRe: Modulo statement Pin
BobJanova5-Jul-11 5:45
BobJanova5-Jul-11 5:45 
GeneralRe: Modulo statement Pin
David19875-Jul-11 6:03
David19875-Jul-11 6:03 
GeneralRe: Modulo statement Pin
BobJanova5-Jul-11 7:13
BobJanova5-Jul-11 7:13 
GeneralRe: Modulo statement Pin
BobJanova5-Jul-11 3:13
BobJanova5-Jul-11 3:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.