From f002f12a4f64edf7c8e00ef61e70dd16096e1024 Mon Sep 17 00:00:00 2001 From: colinleach Date: Sun, 8 Sep 2024 15:02:27 -0700 Subject: [PATCH 1/8] modify concept exercise lasagna --- config.json | 4 +- .../concept/lasagna/.docs/instructions.md | 18 +- .../concept/lasagna/.docs/introduction.md | 156 +++++++++--------- .../concept/lasagna/.docs/introduction.md.tpl | 16 +- exercises/concept/lasagna/.meta/config.json | 3 +- exercises/concept/lasagna/.meta/design.md | 9 +- exercises/concept/lasagna/.meta/exemplar.jl | 6 +- exercises/concept/lasagna/lasagna.jl | 3 + exercises/concept/lasagna/runtests.jl | 6 + 9 files changed, 113 insertions(+), 108 deletions(-) diff --git a/config.json b/config.json index 8a1bee8d..b815e44f 100644 --- a/config.json +++ b/config.json @@ -39,9 +39,7 @@ "name": "Lasagna", "uuid": "39ebdd04-4f84-4817-bf9d-f1f9e066c283", "concepts": [ - "functions", - "integer-introduction", - "comments" + "basics" ], "prerequisites": [], "status": "wip" diff --git a/exercises/concept/lasagna/.docs/instructions.md b/exercises/concept/lasagna/.docs/instructions.md index a32ae435..1d1bf6d1 100644 --- a/exercises/concept/lasagna/.docs/instructions.md +++ b/exercises/concept/lasagna/.docs/instructions.md @@ -2,9 +2,18 @@ In this exercise you're going to write some code to help you cook a brilliant lasagna from your favorite cooking book. -You have three tasks, all related to the time spent cooking the lasagna. +You have four tasks, all related to the time spent cooking the lasagna. -## 1. Calculate the preparation time in minutes +## 1. + +Define the `expected_bake_time` constant that returns how many minutes the lasagna should bake in the oven. According to the cooking book, lasagna needs to be in the oven for a total of 60 minutes. + +```julia-repl +julia> expected_bake_time +60 +``` + +## 2. Calculate the preparation time in minutes Define the `preptime` function that takes the number of layers you added to the lasagna as an argument and returns how many minutes you spent preparing the lasagna, assuming each layer takes you 2 minutes to prepare. @@ -13,9 +22,8 @@ julia> preptime(4) 8 ``` -## 2. Calculate the remaining oven time in minutes +## 3. Calculate the remaining oven time in minutes -According to the cooking book, lasagna needs to be in the oven for a total of 60 minutes. Define the `remaining_time` function 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. ```julia-repl @@ -23,7 +31,7 @@ julia> remaining_time(50) 10 ``` -## 3. Calculate the total working time in minutes +## 4. Calculate the total working time in minutes Define the `total_working_time` function that takes two arguments: the first argument is the number of layers you added to the lasagna, and the second parameter is the number of minutes the lasagna has been in the oven. The function 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. diff --git a/exercises/concept/lasagna/.docs/introduction.md b/exercises/concept/lasagna/.docs/introduction.md index 21acec2d..01f1a287 100644 --- a/exercises/concept/lasagna/.docs/introduction.md +++ b/exercises/concept/lasagna/.docs/introduction.md @@ -3,122 +3,120 @@ The entire Julia track will require you to treat your solution like small libraries, i.e. you need to define functions, types etc. which will then be run against a test suite. For that reason, we will introduce named functions as the very first concept. -## Functions +Julia is a dynamic, strongly-typed programming langauge. +The programming style is mainly functional, though with more flexibility than in languages such as Haskell. -### Defining functions +## Comments -There are two common ways to define a named function in Julia: +Two options are possible in Julia: +- Single-line comments start with `#` +- Multi-line comments start with `#=` and end with `=#`. Nesting is allowed. -1. Using the `function` keyword - - ```julia - function muladd(x, y, z) - return x * y + z - end - ``` +```julia +# This is a single-line comment -2. Using the "assignment form" +x = 3 # This is an inline comment - ```julia - muladd(x, y, z) = x * y + z - ``` +#= + Multi-line comments can be used for longer explanations. - This is most commonly used for one-line function definitions or mathematical functions, where the function body is a single expression. + They are especially useful to comment out blocks of code during debugging. +=# +``` -### Invoking functions +## Variables and assignment -Invoking a function is done by specifying its name and passing arguments for each of the function's parameters: +To create a variable, just assign a value to it: -```julia -# invoking a function -muladd(10, 5, 1) +```julia-repl +julia> myvar = 42 # an integer +42 -# and of course you can invoke a function within the body of another function: -square_plus_one(x) = muladd(x, x, 1) +julia> name = "Maria" # strings are surrounded by double-quotes "" +"Maria" ``` -## Integers and Arithmetic operations +Types are an important subject in Julia, but for now it is best to ignore them them. +The compiler will infer a suitable type for any expression you use. -Integer literals in Julia are represented in the usual way. -Underscores may be used as a digit separator. +## Constants -```julia-repl -julia> 1 -1 - -julia> -1234 --1234 +Global variables, created outside any function, are: +- Allowed. +- Sometimes necessary. +- Usually discouraged (only within `*.jl` files; the REPL operates differently). -julia> 1_234_567_890 -1234567890 -``` +If a value needs to be available throughout the program, but is not expected to change, use a constant instead. -### Arithmetic operations +Prefacing the assignemt with the `const` keyword allows the compiler to generate more efficient code. -The standard prefix and infix operations are available: `+`, `-`, `*`, `%`. +Accidentally trying to change the `const` value will give a warning: ```julia-repl -julia> +16 -16 +julia> const answer = 42 +42 -julia> -16 --16 - -julia> 16 + 6 -22 +julia> answer = 24 +WARNING: redefinition of constant Main.answer. This may fail, cause incorrect answers, or produce other errors. +24 +``` -julia> 16 - 6 -10 +## Arithmetic operators -julia> 16 * 6 -96 +These mostly work conventionally: -julia> 16 % 6 -4 +```julia +2 + 3 # 5 (addition) +2 - 3 # -1 (subtraction) +2 * 3 # 6 (mutlplication) +8 / 2 # 4.0 (division with floating-point result) +8 % 3 # 2 (remainder) ``` -#### Division +## Functions -Dividing two numbers with the `/` operator will result in a floating point value. -To perform integer division +There are two common ways to define a named function in Julia: -- use the `div(x, y)` function, or -- use the `÷` operator (Julia source code is unicode-aware) +1. Using the `function` keyword -```julia-repl -julia> 16 / 6 -2.6666666666666665 + ```julia + function muladd(x, y, z) + x * y + z + end + ``` -julia> div(16, 6) -2 + Indentation by 4 spaces is conventional for readability, but the compiler ignores this. + The `end` keyword is essential: more like Ruby than like Python. -julia> 16 ÷ 6 -2 -``` + Note that we could have written `return x * y + z`. + However, Julia functions always return the last expression evaluated, so the `return` keyword is optional. + Many programmers prefer to include it to make their intentions more explicit. -~~~~exercism/note -It's natural to use Unicode symbols in Julia source files, typically in mathematical expressions. -When using the Julia REPL, or in other Julia editing environments, the division symbol can be entered by typing `\div` followed by the `Tab` key. -More details can be found in the manual at [Unicode Input][unicode]. +2. Using the "assignment form" -[unicode]: https://docs.julialang.org/en/v1/manual/unicode-input/#Unicode-Input -~~~~ + ```julia + muladd(x, y, z) = x * y + z + ``` -## Comments + This is most commonly used for one-line function definitions or mathematical functions, where the function body is a single expression. + A `return` keyword is *never* used in the assignment form. -Julia supports two kinds of comments. -Single line comments are preceded by `#` and multiline comments are inserted between `#=` and `=#`. +The two forms are equivalent, and are used in exactly the same way, so choose whichever is more readable. + +Invoking a function is done by specifying its name and passing arguments for each of the function's parameters: ```julia -add(1, 3) # returns 4 +# invoking a function +muladd(10, 5, 1) -#= Some random code that's no longer needed but not deleted -sub(x, y) = x - y -mulsub(x, y, z) = sub(mul(x, y), z) -=# +# and of course you can invoke a function within the body of another function: +square_plus_one(x) = muladd(x, x, 1) ``` -## Types +## Naming conventions + +Like many languages, Julia requires that names (of variables, functions, and many other things) start with a letter, followed by any combination of letters, digits and underscores. + +By convention, variable, constant, and function names are *lowercase*, with underscores kept to a reasonable minimum. -Depending on which other programming languages you know, you may expect parameters, variables or return values to have explicit type annotations. -For now, assume that Julia will infer the types automagically and don't worry about them, we will get to the specifics of the type system in later exercises. +However, Julia uses Unicode throughout, so "letter" is interpreted quite flexibly: not just *English* letters. diff --git a/exercises/concept/lasagna/.docs/introduction.md.tpl b/exercises/concept/lasagna/.docs/introduction.md.tpl index cd2296a7..2c5ce066 100644 --- a/exercises/concept/lasagna/.docs/introduction.md.tpl +++ b/exercises/concept/lasagna/.docs/introduction.md.tpl @@ -3,19 +3,5 @@ The entire Julia track will require you to treat your solution like small libraries, i.e. you need to define functions, types etc. which will then be run against a test suite. For that reason, we will introduce named functions as the very first concept. -## Functions +%{concept:basics} -%{concept:functions} - -## Integers and Arithmetic operations - -%{concept:integer-introduction} - -## Comments - -%{concept:comments} - -## Types - -Depending on which other programming languages you know, you may expect parameters, variables or return values to have explicit type annotations. -For now, assume that Julia will infer the types automagically and don't worry about them, we will get to the specifics of the type system in later exercises. diff --git a/exercises/concept/lasagna/.meta/config.json b/exercises/concept/lasagna/.meta/config.json index 120ce1ed..7e1785c7 100644 --- a/exercises/concept/lasagna/.meta/config.json +++ b/exercises/concept/lasagna/.meta/config.json @@ -4,7 +4,8 @@ ], "contributors": [ "ErikSchierboom", - "glennj" + "glennj", + "colinleach" ], "files": { "solution": [ diff --git a/exercises/concept/lasagna/.meta/design.md b/exercises/concept/lasagna/.meta/design.md index 9c978c03..ec9120ba 100644 --- a/exercises/concept/lasagna/.meta/design.md +++ b/exercises/concept/lasagna/.meta/design.md @@ -2,7 +2,7 @@ ## Goal -The goal of this exercise is to teach the student the fundamentals of the Concept of functions in Julia, so that they are able to understand the basic structure of Exercism exercises. +The goal of this exercise is to teach the student the fundamentals of the `basics` Concept in Julia, so that they are able to understand the basic structure of Exercism exercises. ## Learning objectives @@ -11,17 +11,18 @@ The goal of this exercise is to teach the student the fundamentals of the Concep - Know how to call a function. - Know about implicit `return`s. - Know how to define an integer. +- Know how to define a global constant. - Know how to use mathematical operators on integers. ## Out of scope +Everthing beyond the simplest minimum for the first exercise of a novice. + ## Concepts The Concepts this exercise practices are: -- `functions`: Defining a function with one or more positional arguments that returns something. Bare minimum to be able to understand the basic structure of Exercism exercises. -- `integers-introduction`: Present integer literals and basic arithmetic operations. -- `comments` +- `basics`: Defining a constant. Defining a function with one or more positional arguments that returns something. Bare minimum to be able to understand the basic structure of Exercism exercises. ## Prerequisites diff --git a/exercises/concept/lasagna/.meta/exemplar.jl b/exercises/concept/lasagna/.meta/exemplar.jl index 33fcd21d..95cd8d51 100644 --- a/exercises/concept/lasagna/.meta/exemplar.jl +++ b/exercises/concept/lasagna/.meta/exemplar.jl @@ -1,3 +1,7 @@ +expected_bake_time = 60 + preptime(layers) = 2 * layers -remaining_time(current_time) = 60 - current_time + +remaining_time(current_time) = expected_bake_time - current_time + total_working_time(layers, current_time) = preptime(layers) + current_time diff --git a/exercises/concept/lasagna/lasagna.jl b/exercises/concept/lasagna/lasagna.jl index 50fff09f..5e90cd3e 100644 --- a/exercises/concept/lasagna/lasagna.jl +++ b/exercises/concept/lasagna/lasagna.jl @@ -1,5 +1,8 @@ +# Define the `expected_bake_time` constant` + # Define the `preptime(layers)` function. # Define the `remaining_time(time_in_oven)` function. # Define the `total_working_time(layers, time_in_oven)` function. + diff --git a/exercises/concept/lasagna/runtests.jl b/exercises/concept/lasagna/runtests.jl index 25b92a26..9088d932 100644 --- a/exercises/concept/lasagna/runtests.jl +++ b/exercises/concept/lasagna/runtests.jl @@ -3,6 +3,12 @@ using Test include("lasagna.jl") @testset verbose = true "tests" begin + + @testset "expected bake time" begin + @test expected_bake_time == 60 + @test isconst(typeof(expected_bake_time), expected_bake_time) == true + end + @testset "preparation time" begin @test preptime(2) == 4 @test preptime(3) == 6 From cade192a59e7539e4d96584dc2e9fd011b7c1a83 Mon Sep 17 00:00:00 2001 From: colinleach Date: Mon, 9 Sep 2024 12:18:51 -0700 Subject: [PATCH 2/8] added guard on one test, which fails on v1.6 LTS --- exercises/concept/lasagna/runtests.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/exercises/concept/lasagna/runtests.jl b/exercises/concept/lasagna/runtests.jl index 9088d932..92f1eb37 100644 --- a/exercises/concept/lasagna/runtests.jl +++ b/exercises/concept/lasagna/runtests.jl @@ -6,7 +6,9 @@ include("lasagna.jl") @testset "expected bake time" begin @test expected_bake_time == 60 - @test isconst(typeof(expected_bake_time), expected_bake_time) == true + if VERSION > v"1.7" + @test isconst(typeof(expected_bake_time), expected_bake_time) == true + end end @testset "preparation time" begin From c6cf1d756a950036aadc844a0d9659764b804b13 Mon Sep 17 00:00:00 2001 From: colinleach Date: Mon, 9 Sep 2024 12:19:46 -0700 Subject: [PATCH 3/8] Update exercises/concept/lasagna/.meta/design.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: András B Nagy <20251272+BNAndras@users.noreply.github.com> --- exercises/concept/lasagna/.meta/design.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/concept/lasagna/.meta/design.md b/exercises/concept/lasagna/.meta/design.md index ec9120ba..87c64f5f 100644 --- a/exercises/concept/lasagna/.meta/design.md +++ b/exercises/concept/lasagna/.meta/design.md @@ -16,7 +16,7 @@ The goal of this exercise is to teach the student the fundamentals of the `basic ## Out of scope -Everthing beyond the simplest minimum for the first exercise of a novice. +Everything beyond the simplest minimum for the first exercise of a novice. ## Concepts From 5e9edd7cdf810a68e305e5f6581c9110bfc68337 Mon Sep 17 00:00:00 2001 From: colinleach Date: Mon, 9 Sep 2024 12:31:23 -0700 Subject: [PATCH 4/8] Update exercises/concept/lasagna/.docs/introduction.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: András B Nagy <20251272+BNAndras@users.noreply.github.com> --- exercises/concept/lasagna/.docs/introduction.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/concept/lasagna/.docs/introduction.md b/exercises/concept/lasagna/.docs/introduction.md index 01f1a287..60818ab1 100644 --- a/exercises/concept/lasagna/.docs/introduction.md +++ b/exercises/concept/lasagna/.docs/introduction.md @@ -48,7 +48,7 @@ Global variables, created outside any function, are: If a value needs to be available throughout the program, but is not expected to change, use a constant instead. -Prefacing the assignemt with the `const` keyword allows the compiler to generate more efficient code. +Prefacing the assignment with the `const` keyword allows the compiler to generate more efficient code. Accidentally trying to change the `const` value will give a warning: From 1eebafffa5bd9c3494d3a63adb109da63d720dc8 Mon Sep 17 00:00:00 2001 From: colinleach Date: Mon, 9 Sep 2024 16:06:45 -0700 Subject: [PATCH 5/8] responses to @BNAndras review comments --- exercises/concept/lasagna/.docs/hints.md | 15 ++++--- .../concept/lasagna/.docs/instructions.md | 11 +++-- .../concept/lasagna/.docs/introduction.md | 44 +++++-------------- .../concept/lasagna/.docs/introduction.md.tpl | 7 --- exercises/concept/lasagna/.meta/exemplar.jl | 6 +-- exercises/concept/lasagna/lasagna.jl | 2 +- exercises/concept/lasagna/runtests.jl | 6 +-- 7 files changed, 35 insertions(+), 56 deletions(-) delete mode 100644 exercises/concept/lasagna/.docs/introduction.md.tpl diff --git a/exercises/concept/lasagna/.docs/hints.md b/exercises/concept/lasagna/.docs/hints.md index f4ba6e72..e5158fe8 100644 --- a/exercises/concept/lasagna/.docs/hints.md +++ b/exercises/concept/lasagna/.docs/hints.md @@ -4,18 +4,23 @@ - You will need to define [functions][functions] and use [arithmetic operators][arithmetics]. -## 1. Calculate the preparation time in minutes +## 1. Store the expected bake time in a constant + +- Define a [const][const] to store this value. + +## 2. Calculate the preparation time in minutes - Use the [`times` arithmetic operator][arithmetics] to multiply the argument by `2`. -## 2. Calculate the remaining oven time in minutes +## 3. Calculate the remaining oven time in minutes - Use the [`minus` arithmetic operator][arithmetics] to subtract the argument from `60`. -## 3. Calculate the total working time in minutes +## 4. Calculate the total working time in minutes -- Reuse the `preptime` function defined in the first step. -- Use the [`plus` arithmetic operator][arithmetics] to add the return value of `preptime` to the argument. +- Reuse the `preparation_time` function defined in the first step. +- Use the [`plus` arithmetic operator][arithmetics] to add the return value of `preparation_time` to the argument. +[const]: https://docs.julialang.org/en/v1/base/base/#const [functions]: https://docs.julialang.org/en/v1/manual/functions/ [arithmetics]: https://docs.julialang.org/en/v1/manual/mathematical-operations/#Arithmetic-Operators-1 diff --git a/exercises/concept/lasagna/.docs/instructions.md b/exercises/concept/lasagna/.docs/instructions.md index 1d1bf6d1..63e9edd1 100644 --- a/exercises/concept/lasagna/.docs/instructions.md +++ b/exercises/concept/lasagna/.docs/instructions.md @@ -4,9 +4,11 @@ In this exercise you're going to write some code to help you cook a brilliant la You have four tasks, all related to the time spent cooking the lasagna. -## 1. +## 1. Store the expected bake time in a constant -Define the `expected_bake_time` constant that returns how many minutes the lasagna should bake in the oven. According to the cooking book, lasagna needs to be in the oven for a total of 60 minutes. +Define the `expected_bake_time` constant that returns how many minutes the lasagna should bake in the oven. + +According to the cooking book, lasagna needs to be in the oven for a total of 60 minutes. ```julia-repl julia> expected_bake_time @@ -15,10 +17,10 @@ julia> expected_bake_time ## 2. Calculate the preparation time in minutes -Define the `preptime` function that takes the number of layers you added to the lasagna as an argument and returns how many minutes you spent preparing the lasagna, assuming each layer takes you 2 minutes to prepare. +Define the `preparation_time` function that takes the number of layers you added to the lasagna as an argument and returns how many minutes you spent preparing the lasagna, assuming each layer takes you 2 minutes to prepare. ```julia-repl -julia> preptime(4) +julia> preparation_time(4) 8 ``` @@ -34,6 +36,7 @@ julia> remaining_time(50) ## 4. Calculate the total working time in minutes Define the `total_working_time` function that takes two arguments: the first argument is the number of layers you added to the lasagna, and the second parameter is the number of minutes the lasagna has been in the oven. + The function 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. ```julia-repl diff --git a/exercises/concept/lasagna/.docs/introduction.md b/exercises/concept/lasagna/.docs/introduction.md index 60818ab1..abdadb9e 100644 --- a/exercises/concept/lasagna/.docs/introduction.md +++ b/exercises/concept/lasagna/.docs/introduction.md @@ -6,27 +6,10 @@ For that reason, we will introduce named functions as the very first concept. Julia is a dynamic, strongly-typed programming langauge. The programming style is mainly functional, though with more flexibility than in languages such as Haskell. -## Comments - -Two options are possible in Julia: -- Single-line comments start with `#` -- Multi-line comments start with `#=` and end with `=#`. Nesting is allowed. - -```julia -# This is a single-line comment - -x = 3 # This is an inline comment - -#= - Multi-line comments can be used for longer explanations. - - They are especially useful to comment out blocks of code during debugging. -=# -``` - ## Variables and assignment -To create a variable, just assign a value to it: +There is no need to declare a variable in advance. +Just assign a value to a suitable name: ```julia-repl julia> myvar = 42 # an integer @@ -36,20 +19,13 @@ julia> name = "Maria" # strings are surrounded by double-quotes "" "Maria" ``` -Types are an important subject in Julia, but for now it is best to ignore them them. -The compiler will infer a suitable type for any expression you use. - ## Constants -Global variables, created outside any function, are: -- Allowed. -- Sometimes necessary. -- Usually discouraged (only within `*.jl` files; the REPL operates differently). - -If a value needs to be available throughout the program, but is not expected to change, use a constant instead. +If a value needs to be available throughout the program, but is not expected to change, it is best to mark it as a constant. -Prefacing the assignment with the `const` keyword allows the compiler to generate more efficient code. +Prefacing an assignment with the `const` keyword allows the compiler to generate more efficient code than is possible for a variable. +Constants also help to protect you against errors in coding. Accidentally trying to change the `const` value will give a warning: ```julia-repl @@ -61,6 +37,9 @@ WARNING: redefinition of constant Main.answer. This may fail, cause incorrect an 24 ``` +Note that a `const` can only be declared *outside* any function. +This will typically be near the top of the `*.jl` file, before the function definitions. + ## Arithmetic operators These mostly work conventionally: @@ -88,7 +67,7 @@ There are two common ways to define a named function in Julia: Indentation by 4 spaces is conventional for readability, but the compiler ignores this. The `end` keyword is essential: more like Ruby than like Python. - Note that we could have written `return x * y + z`. + Note that we could have written `return x * y + z`. However, Julia functions always return the last expression evaluated, so the `return` keyword is optional. Many programmers prefer to include it to make their intentions more explicit. @@ -98,7 +77,8 @@ There are two common ways to define a named function in Julia: muladd(x, y, z) = x * y + z ``` - This is most commonly used for one-line function definitions or mathematical functions, where the function body is a single expression. + This is most commonly used for making concise single-expression functions. + A `return` keyword is *never* used in the assignment form. The two forms are equivalent, and are used in exactly the same way, so choose whichever is more readable. @@ -118,5 +98,3 @@ square_plus_one(x) = muladd(x, x, 1) Like many languages, Julia requires that names (of variables, functions, and many other things) start with a letter, followed by any combination of letters, digits and underscores. By convention, variable, constant, and function names are *lowercase*, with underscores kept to a reasonable minimum. - -However, Julia uses Unicode throughout, so "letter" is interpreted quite flexibly: not just *English* letters. diff --git a/exercises/concept/lasagna/.docs/introduction.md.tpl b/exercises/concept/lasagna/.docs/introduction.md.tpl deleted file mode 100644 index 2c5ce066..00000000 --- a/exercises/concept/lasagna/.docs/introduction.md.tpl +++ /dev/null @@ -1,7 +0,0 @@ -# Introduction - -The entire Julia track will require you to treat your solution like small libraries, i.e. you need to define functions, types etc. which will then be run against a test suite. -For that reason, we will introduce named functions as the very first concept. - -%{concept:basics} - diff --git a/exercises/concept/lasagna/.meta/exemplar.jl b/exercises/concept/lasagna/.meta/exemplar.jl index 95cd8d51..f5399fde 100644 --- a/exercises/concept/lasagna/.meta/exemplar.jl +++ b/exercises/concept/lasagna/.meta/exemplar.jl @@ -1,7 +1,7 @@ -expected_bake_time = 60 +const expected_bake_time = 60 -preptime(layers) = 2 * layers +preparation_time(layers) = 2 * layers remaining_time(current_time) = expected_bake_time - current_time -total_working_time(layers, current_time) = preptime(layers) + current_time +total_working_time(layers, current_time) = preparation_time(layers) + current_time diff --git a/exercises/concept/lasagna/lasagna.jl b/exercises/concept/lasagna/lasagna.jl index 5e90cd3e..68b15903 100644 --- a/exercises/concept/lasagna/lasagna.jl +++ b/exercises/concept/lasagna/lasagna.jl @@ -1,6 +1,6 @@ # Define the `expected_bake_time` constant` -# Define the `preptime(layers)` function. +# Define the `preparation_time(layers)` function. # Define the `remaining_time(time_in_oven)` function. diff --git a/exercises/concept/lasagna/runtests.jl b/exercises/concept/lasagna/runtests.jl index 92f1eb37..9ab3d331 100644 --- a/exercises/concept/lasagna/runtests.jl +++ b/exercises/concept/lasagna/runtests.jl @@ -12,9 +12,9 @@ include("lasagna.jl") end @testset "preparation time" begin - @test preptime(2) == 4 - @test preptime(3) == 6 - @test preptime(8) == 16 + @test preparation_time(2) == 4 + @test preparation_time(3) == 6 + @test preparation_time(8) == 16 end @testset "remaining time" begin From 9ee15acefac7140f972e70726c45d9bfd91f4836 Mon Sep 17 00:00:00 2001 From: colinleach Date: Mon, 9 Sep 2024 16:17:57 -0700 Subject: [PATCH 6/8] Update introduction.md Fixing the requested change I missed in the previous commit. --- exercises/concept/lasagna/.docs/introduction.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/concept/lasagna/.docs/introduction.md b/exercises/concept/lasagna/.docs/introduction.md index abdadb9e..9de123ad 100644 --- a/exercises/concept/lasagna/.docs/introduction.md +++ b/exercises/concept/lasagna/.docs/introduction.md @@ -65,7 +65,7 @@ There are two common ways to define a named function in Julia: ``` Indentation by 4 spaces is conventional for readability, but the compiler ignores this. - The `end` keyword is essential: more like Ruby than like Python. + The `end` keyword is essential. Note that we could have written `return x * y + z`. However, Julia functions always return the last expression evaluated, so the `return` keyword is optional. From 18af01ae2cf79d7de6db80c7ff964b50a7c01039 Mon Sep 17 00:00:00 2001 From: colinleach Date: Sat, 21 Sep 2024 21:44:32 -0700 Subject: [PATCH 7/8] Update exercises/concept/lasagna/.docs/instructions.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: András B Nagy <20251272+BNAndras@users.noreply.github.com> --- exercises/concept/lasagna/.docs/instructions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/concept/lasagna/.docs/instructions.md b/exercises/concept/lasagna/.docs/instructions.md index 63e9edd1..28cd5efb 100644 --- a/exercises/concept/lasagna/.docs/instructions.md +++ b/exercises/concept/lasagna/.docs/instructions.md @@ -35,7 +35,7 @@ julia> remaining_time(50) ## 4. Calculate the total working time in minutes -Define the `total_working_time` function that takes two arguments: the first argument is the number of layers you added to the lasagna, and the second parameter is the number of minutes the lasagna has been in the oven. +Define the `total_working_time` function that takes two arguments: the first argument is the number of layers you added to the lasagna, and the second argument is the number of minutes the lasagna has been in the oven. The function 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. From 76d6208ac0f402a85c0f7dcfad4b2718c233428d Mon Sep 17 00:00:00 2001 From: colinleach Date: Sat, 21 Sep 2024 21:45:14 -0700 Subject: [PATCH 8/8] Update exercises/concept/lasagna/.docs/introduction.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit oops... Co-authored-by: András B Nagy <20251272+BNAndras@users.noreply.github.com> --- exercises/concept/lasagna/.docs/introduction.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/concept/lasagna/.docs/introduction.md b/exercises/concept/lasagna/.docs/introduction.md index 9de123ad..fa8adf47 100644 --- a/exercises/concept/lasagna/.docs/introduction.md +++ b/exercises/concept/lasagna/.docs/introduction.md @@ -47,7 +47,7 @@ These mostly work conventionally: ```julia 2 + 3 # 5 (addition) 2 - 3 # -1 (subtraction) -2 * 3 # 6 (mutlplication) +2 * 3 # 6 (multiplication) 8 / 2 # 4.0 (division with floating-point result) 8 % 3 # 2 (remainder) ```