Software Sauna Code Challenge
Follow a path of characters & collect letters:
- Start at the character
@
- Follow the path
- Collect letters
- Stop when you reach the character
x
Write a piece of code that takes a map of characters as an input and outputs the collected letters and the list of characters of the travelled path.
Input:
- a map (2-dimensional array) of characters in a data format of your choice (can even be hard-coded as a global constant)
Output:
- Collected letters
- Path as characters
- readable code
- small methods/functions/classes
- good naming
- minimise code duplication
- separation of logic and scaffolding (e.g. walking around is separated from loading the map)
- automated tests
- high-level tests (i.e. acceptance tests) which test that the program gives correct output for a given input, according to examples specified below
- unit tests which test small bits of logic separated from the rest of the program, e.g. advancing the current location based on the current direction
At Software Sauna automated tests are a first-class citizen. This is why we encourage you to try writing some tests, even if you're not accustomed to doing so. An easy win is to start with the example maps provided.
@---A---+
|
x-B-+ C
| |
+---+
Expected result:
- Letters
ACB
- Path as characters
@---A---+|C|+---+|+-B-x
@
| +-C--+
A | |
+---B--+
| x
| |
+---D--+
Expected result:
- Letters
ABCD
- Path as characters
@|A+---B--+|+--C-+|-||+---D--+|x
@---A---+
|
x-B-+ |
| |
+---C
Expected result:
- Letters
ACB
- Path as characters
@---A---+|||C---+|+-B-x
+-O-N-+
| |
| +-I-+
@-G-O-+ | | |
| | +-+ E
+-+ S
|
x
Expected result:
- Letters
GOONIES
- Path as characters
@-G-O-+|+-+|O||+-O-N-+|I|+-+|+-I-+|ES|x
+-L-+
| +A-+
@B+ ++ H
++ x
Expected result:
- Letters
BLAH
- Path as characters
@B+++B|+-L-+A+++A-+Hx
@-A--+
|
+-B--x-C--D
Expected result:
- Letters
AB
- Path as characters
@-A--+|+-B--x
-A---+
|
x-B-+ C
| |
+---+
Expected result: Error
@--A---+
|
B-+ C
| |
+---+
Expected result: Error
@--A-@-+
|
x-B-+ C
| |
+---+
@--A---+
|
C
x
@-B-+
@--A--x
x-B-+
|
@
Expected result: Error
x-B
|
@--A---+
|
x+ C
| |
+---+
Expected result: Error
@--A-+
|
B-x
Expected result: Error
x-B-@-A-x
Expected result: Error
@-A-+-B-x
Expected result: Error
- the only valid characters are all uppercase letters (
A
-Z
) and other characters appearing in the example maps; anything else found must result in an error - turns can be letters or
+
- input examples are jagged matrices - rows (lines) don't contain the same number of elements (characters): this is a valid form of input so keep that in mind