There is no Spoon - Episode 1 puzzle discussion


#115

The autogenerated code in java only shows the first line of each test case to me, as it seems. Changing nothing but adding a print statement to the for loop it can’t be because I removed something… Do I have to add something to it to get all the input? Can’t see anyone here having the same issue, so… I’m quite confused


#116

Does anybody have an idee ?


#117

hi every body
i am under standing the problem & write the code put its a problem in the zeros marked line
i cant guess it
please help me ^^…
here my code …
import java.util.;
import java.io.
;
import java.math.*;

/**

  • Don’t let the machines win. You are humanity’s last hope…
    **/
    class Player {

    public static void main(String args[]) {
    Scanner in = new Scanner(System.in);
    int width = in.nextInt(); // the number of cells on the X axis
    int height = in.nextInt();

     // the number of cells on the Y axis
     if (in.hasNextLine()) {
         in.nextLine();
     }
     int i=0;
     int j=0;
     
     char ss[][]=new char[height][width];
     for (int v = 0; v < height; v++) {
          for ( int m = 0; m < width; m++){
             String s=in.nextLine();
       ss[v][m]=s.charAt(m);}}                                    //the wrong line --_--
       for ( j = 0; j < height; j++) {       
          for ( i = 0; i < width; i++){
               System.out.print(i+" "+j+" ");
           if (ss[i+1][j]==0)
           System.out.print(i+1+" "+j+" ");
           else 
           System.out.print("-1 -1 ");
         // width characters, each either 0 or .
          }if(ss[i][j+1]==0)
           System.out.print(i+" "+j+1+" ");
           else 
           System.out.print("-1 -1 ");
          
     }
    
     // Write an action using System.out.println()
     // To debug: System.err.println("Debug messages...");
    
    
     // Three coordinates: a node, its right neighbor, its bottom neighbor
    

    }
    }


#118

You are reading the input in the wrong way.

You are trying to read the data for each row-column, but the input is provide on row-based. You need to move input scanner to the outer loop.


#119

With C++, I just use ‘sort’ for X and Y. A little bit clumsy but it works.

p.s. If ‘filled’ not passed in this way, this means your sorting is not precise.


#120

I am giving this question a solid 1 star, the difficulty of this question is not on the technical side, but depends on how you understand the problem, this is bad.


#121

what is input to 2nd test case


#122

what is input to 2nd test case please…

getting this error

Standard Output Stream:

0 2 4 0 -1 -1

Game information:

Invalid node: (0, 2).


#124

I was sceptic when my code didn’t work. So i copied it to VSCode with the wanted parameters and it gives me the wanted output with the right coordinates, while the debugger in codingame tells me i have something else.

So i don’t really know where the error is coming from and any help would be appreciated, here is my code :

bool[,] allNodes = new bool[height-1,width-1];
        for (int i = 0; i < height -1; i++)
        {
            string line = Console.ReadLine(); // width characters, each either 0 or .
            for(int j=0; j<width-1;j++) {
                if(line[j] != '.') {                       
                    allNodes[i,j] = true;
                }else {
                    allNodes[i,j] = false;   
                }                    
            }
        }
        for(int i=0;i<height-1;i++){
            for(int j=0;j<width-1;j++){
                if(allNodes[i,j]){
                
                var k = j+1;
                var right = "-1 -1";
                var rightFound = false;
                while(!rightFound && k<width-1) {
                    if(allNodes[i,k]){
                        right = $"{k} {i}";   
                        rightFound = true;
                    }else{
                        k++;   
                    }                                                
                } 
                
                var b = i+1;
                var bottom = "-1 -1";
                var bottomFound = false;
                while(!bottomFound && b<height-1) {
                    if(allNodes[b,j]){
                        bottom = $"{j} {b}";   
                        bottomFound = true;
                    }else{
                        b++;   
                    }                                                
                } 
                Console.WriteLine("{0} {1} {2} {3}",j,i,right,bottom);
            }
            }                
        }

#125

Java:

For some reason this isn’t returning true:

if (lineArr[x][y] == “0”) …

But if I do

System.out.print(lineArr[x][y];

I get:

Standard Output Stream:
0
I don’t get why it’s not returning true, as it was defined as a string array.


#126

Compare strings with lineArr[x][y].equals(“0”), if you don’t want to check if they are the same object.


#127

Thanks mate, completed it now.


#128

Hi. Brand new to this site. I might not be understanding the instructions. I got my C# code to work with the example and the vertical grids. However, all other tests fail. In looking at the output of the horizontal grid:
0.0.0, in my mind, the first line of output should be:
0 0 -1 -1 -1 -1
There is a “.” to the right at position 1,0 which according to the instructions would be -1 -1 for the output. And of course given there is only one horizontal line of data, there is nothing at 0,1 so it too would be -1 -1.

The game says:
(-1, -1) is not to the right of (0, 0). Expected (2, 0).

I just don’t understand that. To the right of position 0,0 is 1,0. And at 1,0 there is a “.”. I must clearly have misunderstood the instructions even after reading them about 10 times. Any guidance is very much appreciated.


#129

In this challenge, ‘to the right’ is not the same as ‘occupying the place that is 1 slot to the right’. i.e. if there is a node in the grid 2, 3, 4 or whatever slots to the right, it still counts. Could that be your problem?


#130

took me a minute to understand what was expected of the I/O but that’s what made this puzzle fun and satisfying in the end.


#131

Hi there
i’m pretty new to programming and still struggle sometimes with the basics, and my attempts are probably pretty clumsy at best. i can get the x1, y1, x2, y2 coordinates, but to calculate the x3, y3 coordinates i would need access to the information about the next line. i thought i could solve that by simply defining a variable line2 and give it the value of the next input, but that seems to be against the rules. any help would be greatly appreciated!

import sys
import math

# Don't let the machines win. You are humanity's last hope...
line2 = 0
width = int(input())  # the number of cells on the X axis
height = int(input())  # the number of cells on the Y axis
for i in range(height):

    if line2 != 0:
        line = line2
    else:
        line = input()# width characters, each either 0 or .


# Write an action using print    

    for j in range(len(line)):
        x1 = ""
        y1 = ""
        x2 = ""
        y2 = ""
        x3 = ""
        y3 = ""
    
        if line[j-1] == "0":
            x1 = str(j)
            y1 = str(i)
        else:
            x1 = "-1"
            y1 = "-1"
    
       if j < len(line)-1:
            if line[j] == "0":
                x2 = str(j+1)
                y2 = str(i) 
        else:
            x2 = "-1"
            y2 = "-1"
    
        line2 = input()
        if i < height:
            if line2[j] == "0":
                x3 = str(j)
                y3 = str(i+1) 
        else:
            x3 = "-1"
            y3 = "-1"
     
     

# Three coordinates: a node, its right neighbor, its bottom neighbor
       print(x1, y1, x2, y2, x3, y3)

#132

A quick glance leads to 2 observations/questions from me:

  1. How many times are you reading inputs? Is it better to read all the inputs before deciding what to output?
  2. if line[j-1] == “0” <- What is the value of j when the for loop is first run? And which position/character in the line does line[j-1] correspond to?
    Hope the above can give you a clue on where to start investigating the issues.

#133

i’m reading inputs twice, but i think it should be done by reading input once, i just don’t know how, since part of the information needed is only provided with the second input.
j is a temporary variable that is used for indexing loop iteration for the for-loop i made which iterates through the line-input. i probably could do without, but my main problem is that loading the input a second time gives me the correct answer, but causes a timeout-error: “Timeout: Only 1 node has been computed.”


#134

You may consider storing the inputs in a list as you read them. So your actual analysis of the inputs will be coded AFTER all inputs have been read.

You may read the inputs only once. Attempting to read inputs afterwards results in an error as there are no more inputs to read.


#135

Thank you so much for your responses and tips! that did the trick.