[Community Puzzle] Dungeons and Maps

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

Hey.
The cells indexing starts from zero.

3 Likes

Thx a lot for your help

Hello, could somebody please update the description for these 2 point:

  • What does ‘Empty square’ do? (I read a few first cmts but didn’t see any answer)
  • Why case 1 and case 2 should be valid? (I read @anon72424297 and found the answer, the description forgot to add map indexing should start from zero.)

I’m honest that I was a little bit panic at first because I don’t understand the sample output. I think if the description have more info for the 2 points about then it’ll be easier for everyone to understand.

P/M: Does anyone have raw input of 3 last testcase? I tried to log (console.error) them out but it doesn’t work. The console always breaks them like this:

  ],
  [
    '.', '#', '#', '#',
    '#', '#', '#', '#',
    '#', '#', '.'
  ],
  [
    '.', '.', '.', '.',
    '.', '.', '.', '.',
    '.', '.', '.'
  ],
  [
    '.', '.', '.', '.',
    '.', '.', '.', '.',

That’s because you’re printing an array directly, the default behavior in that case is what you see.
If you want a different output format you need code for it. Here’s an example :

dungeonMap.forEach(row => console.error(row.join('')));

Join creates a string from the array elements, and inserts a character between them (’’ here). Doing that for each row of a dungeon map will print it in the console.

2 Likes

I guess that’s one of solutions. But don’t you think print a whole array out look much better?

An array is an object and has a default toString implementation, this is part of the language specification : https://tc39.es/ecma262/#sec-object.prototype.tostring
You can create your own class and override the toString call if you want, but considering you only need a one liner to get what you want, I don’t think that’s worth it.

An interesting spin of this might force the user to use the constraint that all of the maps represent the same dungeon and attempt to fill in the missing paths with data from other maps, just a thought.

1 Like