There is no Spoon - Episode 1 puzzle discussion


#67

You can use http://pastebin.com/ to share code, because your Google Doc is not publicly available.


#68

Sorry - that link may not work… try this:
No Spoon Link


#69

If it’s Python3, you missed the “file=sys.stderr” part

# To debug: print("Debug messages...", file=sys.stderr)

Like :

 print("Debug messages...", width, height, file=sys.stderr)

#70

Thank you! That helped!


#71

Hi all, I got all test cases passed, but once I submit the code, it fails on the “single” test case and I do not know how to debug it. Anybody has the same problem? Result is 88% and not 100%… Any help?


#72

Hello, just stupid question…is there a difference between evaluation from top to bottom in columns and from left to right in rows? Because I wrote this in rows and it fails theirs stupid evaluation…dont want to rewwire it.


#73

Changed implementation and now it works


#74

Hi, complete noob here and need some help. This is Javascript and my code doesn’t seem to save the x1, x2, y1, y2 results. I declared the variables outside the for loops. This is not a complete code since I’ve just started. Any ideas what I am doing wrong.

/**
 * Don't let the machines win. You are humanity's last hope...
 **/

var width = parseInt(readline()); // the number of cells on the X axis
var height = parseInt(readline()); // the number of cells on the Y axis
var x1 = '';
var y1 = '';
var x2 = '';
var y2 = '';
var x3 = '';
var y3 = '';
    
for (var i = 0; i < height; i++) 
{
    for (var j=0; j < width; j++ ) 
    {
    var line = readline(); // width characters, each either 0 or .
    if (line === 0)
        {
            x1 = j;
            y1 = i;
            j++;
            if (line === 0)
            {
                x2 = j;
                y2 = i;
                j--;
            } else 
                { 
                    x2 = -1;
                    y2 = -1;
                    j--;
                }
 
        }


    }
 print (x1 + " " + y1 + " " + x2 + " " + y2 + " " + '0 0');
   
}

// Write an action using print()
// To debug: printErr('Debug messages...');
//printErr('Debug messages...', + x1);


// Three coordinates: a node, its right neighbor, its bottom neighbor

#75

[SOLVED] (there was a space missing)
I’m getting the following error in swift. Any guess of what causes this? Looks like a bug in codingame.

Game information:
invalid input. Expected ‘x1 y1 x2 y2 x3 y3’ but found ‘0 0 -1 -1-1 -1’


#76

Several things…

  1. The 0 in if (line === 0) should be in quotes. The number 0 and a string that represents the number 0 are not equal.
  2. That same line, as written, is comparing the whole string to 0 rather than looking at the individual characters in it, which is what I think you wanted to do.
  3. The else block will never be called. I’ll elaborate if you want but hopefully you can figure out why by following the flow of the program.

Bonus advice: Since the data is given to you in rows, readline() should be called once for each row, not each character.


#78

I cant even get started with this one

i have used this code in an attempt to output the full grid to the console (and show i can reading it correctly)

for ($i = 0; $i < $height; $i++)
{
   error_log($line); 
}

But all that does is repeat the first line of the grid for as many times as there are rows.

IE

if we have the following grid

X X X
X
X

it would output

0 0 0
0 0 0
0 0 0

when the output should be

0 0 0
0 . .
0 . .

How can i read each line in the grid?


#80

Check the console, your output does not follow the right form.


#82

by the look of it, I’d say it’s an index issue. Don’t hesitate to use debug prints (printErr in JS I think) to understand when your program fails to enter a loop


#85

Got the same problem


#86

I didn’t want to use the 2D Array way so i created a Object and just do the calc in the main.

admin edit: please dont just post your code. Either ask a specific question or give hints for others


#88

Pro tip: Keep looking for neighbors to the south and west until you reach the edge of the map. In my first attempt I failed to look for neighbors more than one cell away. Seeing the test case made it clear that I was supposed to keep searching in a given direction. This was frustrating at first but it added a nice complexity element once I knew what was expected.


#89

I think I must be missing something with the input, my code passes all the test cases on my local machine but fails on the site. Can anyone help me?

As I understand it I get the width and height as an integer, then a string with all of the rows from top to bottom, so a grid like this:

00
0.

should have input like this:
2
2
00
0.

and that’s how I modeled the tests.

But I fail the horizontal case which looks like this:

000

on the site, but I pass it on my machine with the inputs
3
1
000

I tried printing out the third input as I get it and I get 0.0.0

Am I just misunderstanding what the inputs are supposed to look like?

I’ve put my code here, apologies for it being a bit messy, I only started learning python yesterday:
https://pastebin.com/207r2Nys


#90

I feel like I’m missing something. Any solution I’ve tried in C++ results in a timeout. It almost seems like just taking in the input’s alone takes up the majority of the available time before an output is required.
Solutions so far have been recursive and non-recursive and even then if I don’t just output immediately I get the infamous “Timeout: the program did not provide 1 input lines in due time…” error.
In fact I’ve even tried just outputting right after the default setup and receive this error. If I just run it from default setup I get the timeout and no output of the 0 0 1 0 0 1. It doesn’t seem to allow at all for a C++ solution.


#91

I just test it with the default C++ template and I get

Game information:
Timeout: Only 1 node has been computed.

This is different that what you’re saying. Your problem comes from not printing a '\n' most likely


#92
int main()
{
    int width; // the number of cells on the X axis
    cin >> width; cin.ignore();
    int height; // the number of cells on the Y axis
    cin >> height; cin.ignore();
    int array[height][width];
    for (int i = 0; i < height; i++) {
        for(int x = 0; x < width; x++){
               cin >> array[i][x]; cin.ignore();
        }
    }
        cout << "0 0 1 0 0 1" << endl;   
}

Game information:
Timeout: the program did not provide 1 input lines in due time…

It’s funny, yesterday the above was default. Today it doesn’t setup the array at all. The only thing missing from the above code that was setup was the debug message section I deleted.