
Dec 4th, 2012, 11:32 AM
#1
Thread Starter
Addicted Member
Generating numbers
Hello is there some algorithm which can generate random numbers in int[,](two dimentional array).
Let's say I have these numbers :
lets say that the blue circle is the current position in the array where the loop have to enter a number,but first I have to check all four directions(current =>down,up,left,right) and if the random number don't exist in these four directions then to enter it in.
My problem is that I don't know how to check all the drections without throwing a error and I don't want to use try & catch.
Thx in advance.

Dec 10th, 2012, 05:32 AM
#2
Re: Generating numbers
So what happens if you are at 3 instead of 5? How would that look? Or would you only evaluate 6 and 8, instead of the 4 on the other far end? Otherwise this is pretty simple. The number above it, is just the index of the number on the bottom + 1, and then you'd just take the element[current_index  1] and element[current_index + 1] to get the sides. Otherwise, if the element index is 0 or the upperbound index, check as to whether to return the last index or the first index for the opposite end if that's the way you're going...
You don't need a 2D array to do this. Unless that top row of numbers, is not always going to be sequential and starting from 1, counting by 1, all the time. But even then, I don't see the requirement for a 2D array.
<<<
.NET Programming (2012  Present)
®Crestron  DMCT Certified Programmer  Software Developer <<<

Dec 11th, 2012, 02:37 AM
#3
Thread Starter
Addicted Member
Re: Generating numbers
Well the contest want to do it this way , I mean using 2D array.
But what worries now me is that the 2d array will be 1000x1000 which is a lot
And I am not sure that there is a way to write such thing and make the code to complete the action for 3 seconds

Dec 11th, 2012, 05:46 PM
#4
Re: Generating numbers
A 2D array wouldn't be 1000x1000 unless you have some awkward structure, it would be 1000+1000, if your concept is for the 2D array a structure like this:
Code:
{{1,2,3,4,5},{4,7,8,3,5}}
I don't even see the point in that...
<<<
.NET Programming (2012  Present)
®Crestron  DMCT Certified Programmer  Software Developer <<<
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
