Network Cabling puzzle discussion

This is why it is interesting :grinning:

Then how did you solved it?
I got only 16% score for now, even I know how to solve it I canā€™t solve it

I donā€™t think thatā€™ll work,

Hello, Iā€™m solving this Network Cabling puzzle in Python programming language, but I only got 16% score only. Can someone give me the whole solution in Python? My brain is about to burn.

Nonsense, isnā€™t it? I started using set when found that ā€œExample 7ā€ is having duplicates ā€” was not expecting that, to begin with; time-out issue solved. But my answer was off, 6 times; spent an hour or so, but to no avail. Then, luckily, I found your post here. I replaced set with list, then encountered time-out again ā€” back to where I was. I submitted, nonetheless. And to my surprise everything passed, got 100%. Thanks pal, but I still hate it.

I failed test 7 without understanding why, and found out that (spoiler) it was because I used an HashSet to store my house coordinates rather than a List: can multiple houses share the same coordinates? If so, I feel itā€™s rather counterintuitive and should be mentioned in the description, right?

You may check the inputs of all visible tests. Iā€™ve just checked Example 7, and indeed, multiple houses can share the same coordinates.

Hi. All tests succeeded but after submit I see a message: ā€œThe following validators differ from the puzzle test cases to prevent hard coded solutions. This is why you can have some fails here even if all of the tests provided in the IDE have been successfully passed.ā€

Tests 02 and 08 are red.

What does it mean?

It means your code is not general enough to solve all the validators, which are used to assess your code after you submit it. Test cases and validators are similar but different. You will have to improve your code.

This puzzle is great, itā€™s what puzzles should be, the hard part is coming up with the solution, not the implementation

I am wondering if anyone has solved this using F#? I have a working solution that prints the right answer but fails on Test 7 and 8 (large N). I translated my solution to a different language and got 100%.

I have a feeling that the criteria for passing 7 and 8 are harder for F#. My program dosnā€™t even get past reading the data:

for i in 1 .. N - 1 do // first item read beforehand
    let token = (Console.In.ReadLine()).Split [|' '|]
    yList <- List.append yList [int(token.[1])]
    //censored codeLine
    //censored codeLine
eprintfn "finished reading data" // this point is not reached in test 7 and test 8

I donā€™t see how this code can get any faster. But I am not a professional eitherā€¦ Iā€™d really like some feedback for F# in DM.

I use an array in my F# solution, and I suspect that arrays are faster than lists and more suitable in solving this puzzle.

1 Like

Thank you for the quick answer. The code works now. Seems like this was the right puzzle to learn something new for me.