forked from exercism/nim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
exercises: add new concept exercise
basics
Decisions: - Use `inim` style repl commands - Simplify by using `let`. We can address `const` and `var` in later exercises. - Similarly, use `proc`, not `func`. Co-authored-by: Erik Schierboom <[email protected]> Co-authored-by: Jeremy Walker <[email protected]>
- Loading branch information
1 parent
4151608
commit d23c5bf
Showing
4 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
In this exercise you're going to write some code to help you cook a brilliant lasagna from your favorite cooking book. | ||
|
||
You have five tasks, all related to the time spent cooking the lasagna. | ||
|
||
## 1. Define the expected oven time in minutes | ||
|
||
Define the `expectedMinutesInOven` immutable variable that returns how many minutes the lasagna should be in the oven. It must be exported. According to the cooking book, the expected oven time in minutes is 40: | ||
|
||
```nim | ||
nim> expectedMinutesInOven | ||
40 == type int | ||
``` | ||
|
||
## 2. Calculate the remaining oven time in minutes | ||
|
||
Implement the `remainingMinutesInOven` procedure that takes the actual minutes the lasagna has been in the oven as a parameter and returns how many minutes the lasagna still has to remain in the oven, based on the expected oven time in minutes from the previous task. | ||
|
||
```nim | ||
nim> remainingMinutesInOven(30) | ||
10 == type int | ||
``` | ||
|
||
## 3. Calculate the preparation time in minutes | ||
|
||
Implement the `preparationTimeInMinutes` procedure that takes the number of layers you added to the lasagna as a parameter and returns how many minutes you spent preparing the lasagna, assuming each layer takes you 2 minutes to prepare. | ||
|
||
```nim | ||
nim> preparationTimeInMinutes(2) | ||
4 == type int | ||
``` | ||
|
||
## 4. Calculate the total working time in minutes | ||
|
||
Implement the `totalTimeInMinutes` procedure that takes two parameters: the `numberOfLayers` parameter is the number of layers you added to the lasagna, and the `actualMinutesInOven` parameter is the number of minutes the lasagna has been in the oven. The procedure should return how many minutes in total you've worked on cooking the lasagna, which is the sum of the preparation time in minutes, and the time in minutes the lasagna has spent in the oven at the moment. | ||
|
||
```nim | ||
nim> totalTimeInMinutes(3, 20) | ||
26 == type int | ||
``` | ||
|
||
## 5. Update the recipe with notes | ||
|
||
Go back through the recipe, adding notes and documentation. | ||
|
||
```nim | ||
proc totalTimeInMinutes*(numberOfLayers, actualMinutesInOven: int): int = | ||
## Calculate the total working time. That is, the time to prepare all the layers | ||
## of lasagna, and the time already spent in the oven. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"authors": [ | ||
{ | ||
"github_username": "ynfle", | ||
"exercism_username": "ynfle" | ||
} | ||
], | ||
"forked_from": ["javascript/basics", "python/basics"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
## Learning objectives | ||
|
||
- Know about `proc` definition | ||
- Know `const` definition | ||
- Know about type inference | ||
- Know about `proc` parameters | ||
- Know the different way of returning values from a `proc` (implicit, `return`, `result`) | ||
- Know how to export identifiers | ||
- Know how to print values for debugging (`echo`, `debugEcho`) | ||
|
||
## Out of scope | ||
|
||
- `func` (I think we'll do another exercise on this so don't what to put here) | ||
- `var`, `let`, `var` assignment | ||
|
||
## Concepts | ||
|
||
- `basics` | ||
|
||
## Prerequisites | ||
|
||
None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
let expectedMinutesInOven* = 40 | ||
|
||
let preparationMinutesPerLayer = 2 ## \ | ||
## The amount of minutes it takes to prepare a single layer. | ||
|
||
proc remainingMinutesInOven*(actualMinutesInOven: int): int = | ||
## Determine the amount of minutes the lasagna still needs to remain in the | ||
## oven to be properly prepared. | ||
expectedMinutesInOven - actualMinutesInOven | ||
|
||
proc preparationTimeInMinutes*(numberOfLayers: int): int = | ||
## Given a number of layers, determine the total preparation time. | ||
numberOfLayers * preparationMinutesPerLayer | ||
|
||
proc totalTimeInMinutes*(numberOfLayers, actualMinutesInOven: int): int = | ||
## Calculate the total working time. That is, the time to prepare all the layers | ||
## of lasagna, and the time already spent in the oven. | ||
preparationTimeInMinutes(numberOfLayers) + actualMinutesInOven |