[Community Puzzle] Dungeons and Maps

What about this simple test?
2 2
0 0
4
>#
.#
>v
T^
<.
.#
T.
.#

someone’s solutions, I think, will be broken :wink:

It breaks a couple of constraints:

There is always a T on the maps.
The given maps are representing the same dungeon, but the position for T may differ.

But starting at T’s position sounds interesting

1 Like

I get stuck on the 6th test case.

I don’t know how to find a valid path, with length, and how to check if there is a loop within a path?
Anybody please help me! (I prefer hints :slight_smile:)

For paths with loops you have to keep track of where you’ve already been one way or another, with information of distance from the start. Then if a path leads you back to a spot you’ve already visited, you should not continue that way if your current distance is greater or equal to the old one, because you know you won’t do better.

4 Likes

Your reply makes me have a good idea, and finally I can solve it.
Thanks indeed, brother!

1 Like

Ok…
2 2
0 0
4
>#
T#
>v
T^
<.
T#
T.
.#

The PUCIT solution is broken on test 1 (the cycle is controlled only by the starting point)
Solution by TheRipperJack is broken on test 2 (not controlled borders)
The solution from TetraktysPhi also controls the loop only by the initial position, and the second error is in the map
2 2
0 0
1
>.
T#

Simple rewrite current position with ‘.’ :wink:

1 Like

Hi, I don’t get the “Many maps” one, as I don’t understand why the output should be 2. We always start on a dot, isn’t that game over ?

Hey !
Have you noticed that the start position is not given in the x,y form, but in the row,column form ?

Cool. First draft if you’re interested: https://www.codingame.com/contribute/view/5470caf10bcfaf3298c18f0934e3567ddf06

1 Like

in map:

...........

.#########.

.>>>>>>>>v.

.^..###..v.

.^..###..T.

....###....

...........

.#########.

...........

...........

path length: 12

start point here:

.[^]..###..T.

@Di_Masta @Niako after playing around with it a bit, i’ve found that the issue with OCaml is related to multi-command loop lines. I resolved the issue in my own contributions by replacing:

loop N read name:word(10) R:int

with

loop N read resistor:string(20)

here is the forum post i’ve made about this:

1 Like

@Schwase I answered in the other thread.

About the current contribution (invoking @TwoSteps), here is the incorrect generated OCaml code:

     1	(* Auto-generated code below aims at helping you parse *)
     2	(* the standard input according to the problem statement. *)
     3	
     4	let w, h = Scanf.scanf " %d  %d" (fun w h -> (w, h)) in
     5	let startrow, startcol = Scanf.scanf " %d  %d" (fun startrow startcol -> (startrow, startcol)) in
     6	let n = int_of_string (input_line stdin) in
     7	for i = 0 to n - 1 do
     8	    for j = 0 to h - 1 do
     9	        let maprow = input_line stdin in
    10	        ();
    11	    done;
    12	
    13	    ();
    14	done;
    15	
    16	
    17	(* Write an answer using print_endline *)
    18	(* To debug: prerr_endline "Debug message"; *)
    19	
    20	print_endline "mapIndex";

And here is for instance what should be generated instead:

     4	let w, h = Scanf.sscanf (input_line stdin) " %d  %d" (fun w h -> (w, h)) in
     5	let startrow, startcol = Scanf.sscanf (input_line stdin) " %d  %d" (fun startrow startcol -> (startrow, startcol)) in
2 Likes

Thanks for the additional details (I had reported the issue already)

2 Likes

Yes, You could make new string and simply add rows together.
I did string with 3 dimension array, map[3][6][6] . This way I have packed all maps in one name.

1 Like

I’ve made my implementation based on wrong assumption, and I know it is wrong. However I managed to pass all tests. If you want identify my case you need add test case:
“King’s protector”
…k…

…b.



…q…Q.
…K…
N

c1, ‘K’
e8, ‘k’
c2, ‘q’
g6, ‘b’
g2, ‘Q’

That was fun! I liked having a little bit of story to start out with :grinning:.

1 Like

There is a little known wizard called Gandalf the White, who wielded a staff and a sword simultaneously.

1 Like

Hey everyone, I am stuck in the logic with the example :

Example:
W = 4 H = 4
startRow = 1 startCol = 1
N = 3

Maps:

0
.>>v
.^#v
#v
…T

1

.v#.
.v#.
.>>T

2

v<#.
v.#.
…>T

The Case 1 should be the solution, but if I start on the position 1, 1, I am surrounded with only “.” and no move.

Any suggestions on that ?
Thank you

1 Like