It seems like the submarine can take a series of commands like forward 1
, down 2
, or up 3
:
down X
increases your aim byX
units.up X
decreases your aim byX
units.forward X
does two things:- It increases your horizontal position by
X
units. - It increases your depth by your aim multiplied by
X
.
- It increases your horizontal position by
Note that since you're on a submarine, down
and up
affect your aim and do the opposite of what you might think.
The submarine seems to already have a planned course. You should probably figure out where it's going. For example:
forward 5
down 5
forward 8
up 3
down 8
forward 2
Your horizontal position, depth and aim all start at 0. The steps above would then modify them as follows:
forward 5
adds5
to your horizontal position, a total of5
.- Because your aim is
0
, your depth does not change.
- Because your aim is
down 5
adds5
to your aim, resulting in a value of5
.forward 8
adds8
to your horizontal position, a total of13
.- Because your aim is
5
, your depth increases by8*5=40
.
- Because your aim is
up 3
decreases your aim by3
, resulting in a value of2
.down 8
adds8
to your aim, resulting in a value of10
.forward 2
adds2
to your horizontal position, a total of15
.- Because your aim is
10
, your depth increases by2*10=20
to a total of60
.
- Because your aim is
After following these instructions, you would have a horizontal position of 15
and a depth of 60
.
Original instructions come from the AOC2021 and are available [here](// Advent of code instructions available here : https://adventofcode.com/2021/day/2)
The goal of the kata is to write the following unit tests as expressed during an example mapping workshop with your business:
Be careful we have probably missed certain Test cases...
Feature: Submarine
Verifying the submarine controls are correct
Scenario: Scenario 1
Given submarine is initialized
Then submarine depth should be 0
And submarine position should be 0
Scenario: Step 1
Given submarine is initialized
When submarine receives command forward 5
Then submarine depth should be 0
And submarine position should be 5
And submarine aim should be 0
Scenario: Step 2
Given submarine is initialized
And submarine receives command forward 5
When submarine receives command down 5
Then submarine depth should be 0
And submarine position should be 5
And submarine aim should be 5
Scenario: Step 3
Given submarine is initialized
And submarine receives command forward 5
And submarine receives command down 5
When submarine receives command forward 8
Then submarine depth should be 40
And submarine position should be 13
And submarine aim should be 5
Scenario: Step 4
Given submarine is initialized
And submarine receives command forward 5
And submarine receives command down 5
And submarine receives command forward 8
When submarine receives command up 3
Then submarine depth should be 40
And submarine position should be 13
And submarine aim should be 2
Scenario: Step 5
Given submarine is initialized
And submarine receives command forward 5
And submarine receives command down 5
And submarine receives command forward 8
And submarine receives command up 3
When submarine receives command down 8
Then submarine depth should be 40
And submarine position should be 13
And submarine aim should be 10
Scenario: Step 6
Given submarine is initialized
And submarine receives command forward 5
And submarine receives command down 5
And submarine receives command forward 8
And submarine receives command up 3
And submarine receives command down 8
When submarine receives command forward 2
Then submarine depth should be 60
And submarine position should be 15
And submarine aim should be 10
Scenario: Full example
Given submarine is initialized
When submarine receives all commands from file submarineCommands.txt
Then submarine depth should be 987457
And submarine position should be 2162
And submarine aim should be 1051
Original kata is available here