You are an explorer, mapping an unknown world. Your ship is carried on the wind. Where it goes, who knows?
Each day, in your spyglass, you see features to the north, south, east and west. You always see four such features, corresponding to the cardinal directions. Your spyglass reports ASCII symbols like this:
~~.*
, ~~~~
, ~.^^
, ~#~#
The symbols are in the order (north, south, east, west).
These are the symbols: ~
= sea, .
= coast, ^
= mountain, *
= tree, #
= invalid (no observation, this occurs whenever you see the edge of the world, or the landscape is obscured by fog). Your spyglass sees exactly one unit in every direction.
Each night, you look up at the stars to see how far you've travelled. Looking at the stars reports an ascii symbol like this:
n
, s
, e
, w
corresponding to North, South, East and West, respectively. You always move exactly one unit to the north, south, east or west every night. So you, as explorer will be receiving an endless stream of symbols:
~~.*n~~~~s~~.*s~.**
Your task is to output a 2D map of the world (where ?
are unknown parts of the map, north is up, east is right):
?~~~??????
?~~~??????
?~~~.^^.??
?~~.***.~~
~~.*^^*.~~
~~~..~~~~~
~~~~~~~~~~
~~~~~~~~~~
For the sake of simplicity let's assume you start in the bottom left corner of the map. Assume all maps are 8x8.
Here is a simple 3x3 example. Assume the map looks like this:
~.~
~^~
~.~
With the following input: ~#.#n~~^#s
You will get this output:
~??
~^?
~.?
More example inputs and outputs:
input
~#~#n~~~#n~~~#n~~~#n~~~#n~~.#n~~.#n#~~#e#.~~e#.~~e#.~~e#.~~e#~~~e#~~~e#~#~s~~#~s~~#~s~~#~s~~#.s~~#~s~~#~s~##~w~#~~w.#~~w^#~~w.#~~
output
~~~~~~~~
~....~~~
~.????~~
~~????~~
~~????.~
~~????~~
~~?.^.~~
~~~~~~~~
Input:
~#~#e~#~~e~#~~e.#~~e^#~~n.~..n~^~.n~.~~n.~~.n.~~*n~.~.n#.~~w#.~~w#.~~s~*..s..*.s*~.~s.~~~s
Output:
?~~~~~??
?....~??
?.**.~??
?~..~~??
?~~~~~??
?~~..~??
~~~.^.??
~~~~~~??
~#~#n~~~#n~~~#n~~~#n~~~#n~~.#n~~.#n#~~#e#.~~e#.~~e#.~~e#.~~e#~~~e#~~~e#~#~s~~#~s~~#~s~~#~s~~#.s~~#~s~~#~s~##~w~#~~w.#~~w^#~~w
) is wrong, and the output should have??
where it says?.
\$\endgroup\$