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 fromstringifyMap
back into a map.The resulting format and data has to be the same as the input value for
stringifyMap
.stringifyMap
andparseMap
will be tested in a sandboxed environment.In the test cases, the sandboxed versions of these functions are
stringify
andparse
.
These will callstringifyMap
andparseMap
.
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.
Similar Kata:
Stats:
Created | Sep 15, 2017 |
Published | Sep 15, 2017 |
Warriors Trained | 194 |
Total Skips | 3 |
Total Code Submissions | 838 |
Total Times Completed | 64 |
JavaScript Completions | 64 |
Total Stars | 16 |
% of votes with a positive feedback rating | 98% of 30 |
Total "Very Satisfied" Votes | 29 |
Total "Somewhat Satisfied" Votes | 1 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 11 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 6 kyu |