Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated need-for-speed exercise to clarify CanFinish task #2742

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions exercises/concept/need-for-speed/.docs/hints.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
## 4. Check if a remote controlled car can finish a race

- Assume the car is just starting the race
- Assume that `battery` and `distance` values can be non default, for example if car has been driving before the track
- You need to calculate the maximum distance a car can drive with the current level of battery
- The number of times a car can be driven can be calculated by `battery / batteryDrain`.
- The maximum distance the car can cover is the product of the car's speed and the number of times it can be driven.
- The number of times a car can be driven can be calculated by `battery / batteryDrain`
- The maximum distance the car can cover is the product of the car's speed and the number of times it can be driven
- Knowing the maximum distance the car can drive, compare it with the distance of the race track

[struct]: https://tour.golang.org/moretypes/2
7 changes: 6 additions & 1 deletion exercises/concept/need-for-speed/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ Define a `Car` struct with the following `int` type fields:
- speed
- distance

~~~~exercism/note
`distance` in this struct represents a value of a car odometer. It shows which distance the car has traveled overall
and is not related to any specific track. So a car can start a track with it's `distance` value being not 0.
~~~~

Allow creating a remote controlled car by defining a function `NewCar` that takes the speed of the car in meters,
and the battery drain percentage as its two parameters (both of type `int`) and returns a `Car` instance:

Expand Down Expand Up @@ -57,7 +62,7 @@ car = Drive(car)

To finish a race, a car has to be able to drive the race's distance. This means not draining its battery before having crossed the finish line. Implement the `CanFinish` function that takes a `Car` and a `Track` instance as its parameter and returns `true` if the car can finish the race; otherwise, return `false`.

Assume that you are currently at the starting line of the race and start the engine of the car for the race. Take into account that the car's battery might not necessarily be fully charged when starting the race:
Assume that you are currently at the starting line of the race and start the engine of the car for the race from start to finish. Take into account when starting the race the car's battery might not necessarily be fully charged and car odometer value (`distance`) might be not 0:
```go
speed := 5
batteryDrain := 2
Expand Down
2 changes: 1 addition & 1 deletion exercises/concept/need-for-speed/need_for_speed.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func Drive(car Car) Car {
panic("Please implement the Drive function")
}

// CanFinish checks if a car is able to finish a certain track.
// CanFinish checks if a car can finish a certain track from start to finish.
func CanFinish(car Car, track Track) bool {
panic("Please implement the CanFinish function")
}