Your task is to, given a map as input, zoom it out or in, depending on the scale. Note that the scale given is the scale by which to zoom out, so a scale between 0 and 1 will actually zoom in.
For example, given the following (badly made) map:
..____....
../OOO\...
..\OO/\...
..........
And a scale factor of 2, you should first separate it into 2x2 sections:
.. | __ | __ | .. | ..
.. | /O | OO | \. | ..
----------------------
.. | \O | O/ | \. | ..
.. | .. | .. | .. | ..
And in each section find the most common character:
.__..
.....
Note that there was an ambiguous section:
__
OO
I chose to use _
for this section, but using O
would have been perfectly acceptable too.
If, for example, you were given the scale factor of 4, you would split it into 4x4 sections, like so:
..__ | __.. | ..
../O | OO\. | ..
..\O | O/\. | ..
.... | .... | ..
As you can tell, the map doesn't perfectly fit into 4x4 sections, but that's fine, as we can just lower the size of the section at the side.
Also, whenever we need to cut off our maps, we cut off at the bottom or on the right side.
The resulting map would look like so:
...
What an interesting map!
For scale factors below 1, such as 0.5, the process is simpler as we zoom in instead. Take this map:
./O\.
.\O/.
Zooming with a scale of 0.5:
..//OO\\..
..//OO\\..
..\\OO//..
..\\OO//..
Note that whenever your zoom factor is less than 1
, the following will always be true: 1/(zoom factor) % 2 == 0
. When it is above 1
, the only guarantee you have is that it will be a whole number. When it is 1
, the map should stay the same.
Examples:
4
/OO\
|OO|
|OO|
\OO/
O
0.25
ABCD
AAAABBBBCCCCDDDD
AAAABBBBCCCCDDDD
AAAABBBBCCCCDDDD
AAAABBBBCCCCDDDD
1
My zoom
should
not change
My zoom
should
not change
You may also take the map as a newline-separated array.
.
thanO
. We cut off on the right and bottom side. \$\endgroup\$