[Community puzzle] Self-driving car testing

This topic is about the puzzle Self-driving car testing.

Feel free to send your feedback or ask some help here!

This one has a few issues.

Typo: in the Output description it says to put an X in the current position of the car, while the description in the Goal section and in the example say to use a # .

Test case 3 has fewer road sections than moves. Not sure if that was intentional or not.

While I’m quibbling, it wasn’t very clear in the description that the first road section did not show the initial position, but rather the position after the first move was completed. Since none of the test cases start with a turn, I had to count moves and outputs in the test cases to figure that out.

9 Likes

I concur with MrAnderson, test 3 is missing one road section so I had to put a test to avoid going out of range of my list.
Also, nothing specifies in the description that the car is going downward. I assumed it was the contrary and had false positives on TC 1 and 3 since they are mirrored.

2 Likes

I fixed the testcase 3 (and corrected the typo).

1 Like

The line : “The number N of lines describing the road pattern” sounds confusing to me, it sounds like the road is made of N lines.
Also it’s not explicitely said if you scroll from top to bottom or from bottom to top.

The example doesn’t help understanding, and if you try the testcases it doesn’t help either, as it only show the first line of the expected output.
So, as I don’t like to start a problem if I don’t have full understanding of what’s asked, I had to go to the contrib page to see the expected outputs.

I don’t think you should re-word or what but showing a better example like testcase 2 would make it more straightforward to understand.

I don’t see what you mean. To look at the testcases, you have to click on the top-right icon (Show testcases) of the testcases box.

2 Likes

Oh I didn’t know that, I’ll make good use of it, thanks.

Ignore my complaints about the ambiguous wording then.

I think the example really should contain more than just straight driving, and should include a sequence of several different instructions and several different road types. Either that, or the description should illustrate what that looks like. It may be deduced that the car is expected to travel downwards at each step, regardless of whether it’s straight, left, or right, but it’s never explicitly said, and this may mean needless trial and error.

:wave: Hi to All and thanks @Merome (and @JBM, @Wolve & @ValNykol validators) or this funny puzzle :slight_smile: !
→ I took pleasure with this ASCII-art exercise :+1: :handshake: .

Have good, :sun_with_face: sun, :dark_sunglasses: fun and :keyboard: CodinGame days :wink: …

I have a problem with parsing the input. This is the first time this happened to me. Could someone help please? Kotlin parsing code follows:

import java.util.*
import java.io.*
import java.math.*

fun main(args : Array<String>) {
    val input = Scanner(System.`in`)
    val height = input.nextInt()
    input.nextLine()
    val startingX = input.nextInt()
    val moves = input.nextLine().split(";")
    for (i in 0 until height) {
        val repeats = input.nextInt()
        var segment = input.nextLine()
        segment = segment.slice(1..segment.length-1)
    }
}

Exception in thread “main” java.util.InputMismatchException
on lines 9 and 12 (reading startingX and repeats)

For the record, this workaround code seems to work. But I would still like to know what was the problem.

import java.util.*
import java.io.*
import java.math.*

fun main(args : Array<String>) {
    val input = Scanner(System.`in`)
    val height = input.nextInt()
    input.nextLine()

    val items = input.nextLine().split(";")
    val startingX = items[0].toInt()
    val moves = items.slice(1..items.size-1)

    for (i in 0 until height) {
        val items = input.nextLine().split(";")
        val repeats = items[0].toInt()
        val segment = items[1]
    }
}

After .nextLine() you are supposed to readln
But you tried to read int before readln, caused the error.

1 Like

An interesting fact: input.nextInt() is not going to parse “3;5” for example, but will parse “3 5”. Is that what you were trying to say?

“3;5” is not a number.
“3 5” is fine. It needs a space for Scanner to tokenize the input.

For your case, it is better to read the whole line, then split it by yourself, then parse it to int as needed.

I looked up the description of the java Scanner class and only now I get it. The default set of delimiters that Scanner uses is whitespace (space, tab, newline). The nextInt() does not read 0…9 digits and stop at non digits. It reads everything that is not a current delimiter, gathers that, and puts through String.toInt(). Am I right?

Yes. So it needs a custom delimiter by doing your custom split.

ps Cumbersome input parsing is not enjoyable. Avoid similar design if you make your puzzles.

1 Like