There is no Spoon - Episode 1 puzzle discussion


#156

nope, the next cell on the right can be empty.


#157

For some reason I pass all of the tests but the Vertical and Horizontal, which give me an out of bounds error at line 11. Any ideas why?

1. static void Main(string[] args)
2.     {
3.         int width = int.Parse(Console.ReadLine()); // the number of cells on the X axis
4.         int height = int.Parse(Console.ReadLine()); // the number of cells on the Y axis
5.         char [,] a = new char [width, height];
6.         for (int i = 0; i < height; ++i)
7.         {
8.             string line = Console.ReadLine(); // width characters, each either 0 or .
9.             for(int j = 0; j < width; ++j)
10.             {
11.                 a[i,j] = line[j];
12.             }
13.         }
14.         
15.         for (int i = 0; i < height; i++)
16.         {
17.             for(int j = 0; j < width; j++)
18.             {
19.                 
20.                 if(a[i,j] == '0')
21.                 {
22.                    string endLine = findNodes(a, i, j, height, width);
23.                    Console.WriteLine(j + " " + i + " " + endLine);
24.                 }
25.                 
26.             }
27.         }

28.         // Write an action using Console.WriteLine()
29.         // To debug: Console.Error.WriteLine("Debug messages...");


30.         // Three coordinates: a node, its right neighbor, its bottom neighbor
31.         
32.     }`Preformatted text`

#158

what if height > width and i = height -1 ?


#159

I don't think I follow. Say height = 4, width = 1. at i =height -1 we have i =3, so a[3,0] = line[0] that should be in bounds.


#160

a[3,0] is out of bounds of your array of char [1, 4]


#161

Oh I see, my declaration is backwards.


#162

Hello all,
I had the same! I have found my mistake!
My code had took the gril for a square but it is n't.
I put "width" to "height" in a loop.


#163

I can't figure out what's the bug is in my code when it runs test case 'horizontal' or the test cases including nodes in horizontal direction. Though i've cleared the test cases 'Example' and 'vertical'.


// our grid of size height
vector grid(height);

for ( int i = 0; i < height; ++i)
{
	getline( cin, grid[i] );	// store our grid
}

// Now here goes the main program
for ( int i = 0; i < height; ++i ) {
	for ( int j = 0; j < width; ++j ) {
		
					
			if ( grid[i][j] == '0' ) // found a node
				cout << j << ' ' << i << ' ';
			else if ( grid[i][j] == '.' ) // not a node
				cout << -1 << ' ' << -1 << ' ';
			
			// check node's allias
			// right node:
			if ( j != (width -1) ) {
				if ( grid[i][j+1] == '0' ) // found a node
					cout << j+1 << ' ' << i << ' ';
				else if ( grid[i][j+1] == '.' ) // not a node
					cout << -1 << ' ' << -1 << ' ';
			}else{
			    cout << -1 << ' ' << -1 << ' ' ;
			}
			// bottom node:
			if ( i != (height -1)) {
				if ( grid[i+1][j] == '0' ) // found a node
					cout << j << ' ' << i+1 << '\n';
				else if ( grid[i+1][j] == '.' ) // not a node
					cout << -1 << ' ' << -1 << '\n';
			}else{
			    cout << -1 << ' ' << -1 << '\n';
			}
	
	}
}

#164

You need to check for any closest node to the right and to the bottom, not just the immediate right and bottom.


#165

aren't those just the same things?


#166

No, e.g. the closest node to the right may not be the one immediately right, there may be empty cells in between.


#167

oh! i get it. Thanks for your help.


#168

I have a question about the challenge : There is no Spoon - Episode 1.
When a node is empty, represented by a dote (.). How do i write the required response. does it an empty string or something else.


#169

If a cell is empty, it means there is no node on this cell.

If a neighbor does not exist, you must output the coordinates -1 -1 instead of (x2,y2) and/or (x3,y3).


#170

So i return an emty string for an emty node or do i return the coordinates nevertheless ??
Thx


#171

In There is no Spoon - Episode 1 coding with php.

The first test grid / Map
00
0.

I can generate those results using error_log().

Sortie d'erreur :

'0 0 1 0 0 1'
'1 0 -1 -1 -1 -1'
'0 1 -1 -1 -1 -1'
'1 1 -1 -1 -1 -1'

But echo() return an empty result

Sortie standard :

Informations :
invalid input. Expected 'x1 y1 x2 y2 x3 y3' but found ''

Thank for helping


#172

Any help ??


#173

How do you store the numbers? and how do you use echo()?


#174

I don’t understand how the grid system works in this problem
basically, a 2D array would follow s
(0,0) (0,1)
(1,0) (1,1)