5 kyu

Shrink the maze!

Description:

You open your mailbox, and see a high priority message...

Valued employee #36,

Our dear CEO, mister H. Edge is on edge!
The MazeMap™ software has gained a massive following, but now our ADSL line can't cope with the traffic.
We need you to shrink down our map data, so we need way fewer bytes to transfer our state of the art rectangular maze maps our clients.

Good luck!

Problem

Since you're new here, I'll give you a quick "walkthrough" of what our mazes look like.

MazeMap™ renders state of the art rectangular mazes, like this one:

      
      
      
      
      

As you can see, every square in the maze is either a path, or a wall.

A code representation of this map would be:

map = [[true,  true,  true,  false, true],
       [false, false, true,  false, true],
       [true,  false, true,  false, true],
       [true,  false, false, false, true],
       [true,  true,  true,  true,  true]];

Basically, true means there's a hedge, false means there isn't.

The intern you're replacing decided it was a good idea to stringify the map array, resulting in a string like this:

"[[true,true,true,false,true],[false,false,true,false,false],[true,false,true,false,true],[true,false,false,false,true],[true,true,true,true,true]]"

This works, but it takes way too much data.

Kata Task

Write two methods:

  • stringifyMap(map) - Returns a string representation of the passed map.

  • The passed map will in the format shown above.

  • The returned value has to be short. Compression is the name of the game.

  • For the example above, a string of 9 characters is possible.

  • parseMap(mapString) - Transforms the result from stringifyMap back into a map.

  • The resulting format and data has to be the same as the input value for stringifyMap.

  • stringifyMap and parseMap will be tested in a sandboxed environment.

  • In the test cases, the sandboxed versions of these functions are stringify and parse.
    These will call stringifyMap and parseMap.

Notes

  • A map will always be a rectangle:
  • Every row has to have the same amount of elements.
  • The map's width / height aren't necessarily the same.
  • You don't need to validate the input.
  • The map's width / height is variable.
  • We have an compression estimate from L33tCoderz™, but I'm sure you can match that! (You'll get test warnings)
  • No cheating. Storing the map in a global variable will not work.
Strings
Algorithms
Logic
Puzzles
Arrays
Parsing

Similar Kata:

Stats:

CreatedSep 15, 2017
PublishedSep 15, 2017
Warriors Trained194
Total Skips3
Total Code Submissions838
Total Times Completed64
JavaScript Completions64
Total Stars16
% of votes with a positive feedback rating98% of 30
Total "Very Satisfied" Votes29
Total "Somewhat Satisfied" Votes1
Total "Not Satisfied" Votes0
Total Rank Assessments11
Average Assessed Rank
5 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • Cerbrus Avatar
  • dcieslak Avatar
Ad