34
1
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:
?~~~~~??
?....~??
?.**.~??
?~..~~??
?~~~~~??
?~~..~??
~~~.^.??
~~~~~~??
7Welcome to Programming Puzzles & Code Golf! This is a nice first challenge. A couple things are unclear to me though: Must all symbols in the output be space separated? That seems to be the case in the example output but it isn't explicitly stated anywhere. Also, what purpose do the star directions serve? I thought maybe they controlled where on the map the symbols go, but following the examples and starting in the bottom left, that doesn't seem to be the case. Can you elaborate on that? – Alex A. – 2016-03-30T16:55:29.803
Output does not have to be space seperated, that's an error on my part. The "#" represents "no observation". They occur whenever you are on the boundary of the map, but could also occur randomly. – user52676 – 2016-03-30T16:57:41.843
Do we assume that input is valid? Meaning, we won't have one observation that says a particular position is a mountain, but a later observation saying it's water? – AdmBorkBork – 2016-03-30T16:59:02.803
Your spyglass always reports the correct feature except when it makes "no observation". – user52676 – 2016-03-30T17:01:15.257
I would suggest adding an example where the map is 3x3 to make it easier to understand. Also, add a note that the four symbols you see are in the north, south, east, and west directions in that order. I guessed that from the order of possible movement directions, but it appears to be true according to the examples. – El'endia Starman – 2016-03-30T17:05:10.007
Good idea, I added a 3x3 example and more clarification for movement. – user52676 – 2016-03-30T17:11:15.577
4
Excellent. As Alex said, this is a great first challenge. I hope to see more from you in the future! :) (FYI, the Sandbox is a great place to get feedback on future challenges.)
– El'endia Starman – 2016-03-30T17:18:49.6371I suspect the first example (where the input is
~#~#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?.
– Leaky Nun – 2016-03-30T17:57:21.033For first example, you forgot
.$~~
at end of input. – TheNumberOne – 2016-03-30T20:00:31.037You describe the explorer as being on a ship. Does that imply that you will always be on a sea square? – dmckee --- ex-moderator kitten – 2016-03-31T04:45:16.553
3It's a magical air ship ;) – user52676 – 2016-03-31T09:59:41.920