Skip to content

Commit b1d77b8

Browse files
committed
Removed white new lines
1 parent cafb9e7 commit b1d77b8

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

docs/src/lecture_02/conditions.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ x is equal to y
4040
<header class="admonition-header">Function declaration:</header>
4141
<div class="admonition-body">
4242
```
43+
4344
So far, we did not show how to define functions. However, the above example should show the basic syntax for defining functions. The `return` keyword specifies the function output. In this case, the function returns nothing since we only want to compare numbers. If we need to define a function that returns more than one variable, the following syntax is used.
4445

4546
```julia
4647
return x, y, z
4748
```
4849

4950
Here `x`, `y`, and `z` are some variables. We will discuss the function declaration in more detail in the [next lesson](@ref Functions).
51+
5052
```@raw html
5153
</div></div>
5254
```
@@ -158,6 +160,7 @@ julia> compare(2.3, 2.3)
158160
<header class="admonition-header">Exercise:</header>
159161
<div class="admonition-body">
160162
```
163+
161164
Write the `fact(n)` function that computes the factorial of `n`. Use the following function declaration:
162165

163166
```julia
@@ -169,6 +172,7 @@ end
169172
Make sure that the input argument is a non-negative integer. For negative input arguments and for arguments that can not be represented as an integer, the function should throw an error.
170173

171174
**Hint:** use recursion, the `isinteger` function and the `error` function. The or operator is written by `|`.
175+
172176
```@raw html
173177
</div></div>
174178
<details class = "solution-body">
@@ -278,6 +282,7 @@ julia> f(1) || println(2) # both expressions are evaluated
278282
<header class="admonition-header">Short-circuit evaluation vs. bitwise boolean operators</header>
279283
<div class="admonition-body">
280284
```
285+
281286
Boolean operations without short-circuit evaluation can be done with the bitwise boolean operators `&` and `|` introduced in [previous lecture](@ref Numeric-comparison). These are normal functions, which happen to support infix operator syntax, but always evaluate their arguments.
282287

283288
```jldoctest shortcirc
@@ -290,6 +295,7 @@ julia> f(1) && t(2)
290295
1
291296
false
292297
```
298+
293299
```@raw html
294300
</div></div>
295301
```
@@ -340,7 +346,9 @@ true
340346
<header class="admonition-header">Exercise:</header>
341347
<div class="admonition-body">
342348
```
349+
343350
Rewrite the factorial function from the exercises above. Use the short-circuit evaluation to check if the given number is a non-negative integer and the ternary operator for recursion.
351+
344352
```@raw html
345353
</div></div>
346354
<details class = "solution-body">

docs/src/lecture_02/exercises.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ There will be a whole [section](@ref Plots.jl) dedicated to the Plots package. H
2727
<header class="admonition-header">Exercise 1: </header>
2828
<div class="admonition-body">
2929
```
30+
3031
Every programmer should be able to rewrite pseudocode to actual code. The goal of this exercise is to rewrite the following pseudocode:
3132

3233
![](juliasetalg.png)
@@ -56,6 +57,7 @@ heatmap(A;
5657
ticks = :none
5758
)
5859
```
60+
5961
```@raw html
6062
</div></div>
6163
<details class = "solution-body">
@@ -125,6 +127,7 @@ heatmap(A;
125127
<header class="admonition-header">Exercise 2:</header>
126128
<div class="admonition-body">
127129
```
130+
128131
In the previous exercise, we rewrote pseudocode to an actual Julia code. This exercise will improve the central part of the code: the inner loop. Write a function which replaces the inner loop in the code from the exercise above. Use the following function definition
129132

130133
```julia
@@ -202,10 +205,12 @@ heatmap(A1;
202205
<header class="admonition-header">Exercise 3: </header>
203206
<div class="admonition-body">
204207
```
208+
205209
Try different values of variable `c` to create different plots. For inspiration, check the Wikipedia page about [Julia set](https://en.wikipedia.org/wiki/Julia_set).
206210
```@raw html
207211
</div></div>
208212
```
213+
209214
- ``c = 0.285 + 0.01 \cdot i``
210215
![](juliaset_ex3_1.svg)
211216

docs/src/lecture_02/loops.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ i = 5
5151
<header class="admonition-header">An alternative notation for <code>for</code> loops</header>
5252
<div class="admonition-body">
5353
```
54+
5455
There are two alternative notations for the `for` loop. It is possible to use the `=` or `` symbol instead of the `in` keyword.
5556

5657
```jldoctest
@@ -65,6 +66,7 @@ i = 5
6566
```
6667

6768
However, it is better to use the `in` keyword to improve code readability. Regardless of which notation is used, it is essential to be consistent and use the same notation in all `for` loops.
69+
6870
```@raw html
6971
</div></div>
7072
```
@@ -102,9 +104,11 @@ Hi, my name is Bob and I am 23 old.
102104
<header class="admonition-header">Exercise:</header>
103105
<div class="admonition-body">
104106
```
107+
105108
Use `for` or `while` loop to print all integers between `1` and `100` which can be divided by both `3` and `7`.
106109

107110
**Hint:** use the `mod` function.
111+
108112
```@raw html
109113
</div></div>
110114
<details class = "solution-body">
@@ -201,7 +205,9 @@ The code after the `continue` keyword is not evaluated.
201205
<header class="admonition-header">Exercise:</header>
202206
<div class="admonition-body">
203207
```
208+
204209
Rewrite the code from the exercise above. Use a combination of the `while` loop and the keyword `continue` to print all integers between `1` and `100` divisible by both `3` and `7`. In the declaration of the `while` loop use the `true` value instead of a condition. Use the `break` keyword and a proper condition to terminate the loop.
210+
205211
```@raw html
206212
</div></div>
207213
<details class = "solution-body">
@@ -295,6 +301,7 @@ There are other limitations of the shorter syntax, such as the impossibility to
295301
<header class="admonition-header">Exercise:</header>
296302
<div class="admonition-body">
297303
```
304+
298305
Use nested loops to create a matrix with elements given by the formula
299306

300307
```math
@@ -304,6 +311,7 @@ A_{i, j} = \frac{1}{2}\exp\left\{\frac{1}{2} (x_{i}^2 - y_{j}^2) \right\} \quad
304311
where ``x \in \{0.4, 2.3, 4.6\}`` and ``y \in \{1.4, -3.1, 2.4, 5.2\}``.
305312

306313
**Bonus:** try to create the same matrix in a more effective way.
314+
307315
```@raw html
308316
</div></div>
309317
<details class = "solution-body">
@@ -410,7 +418,9 @@ julia> [(x, y, x + y) for x in 1:10, y in 1:10 if x + y < 5]
410418
<header class="admonition-header">Exercise:</header>
411419
<div class="admonition-body">
412420
```
421+
413422
Use the list comprehension to create a vector of all integers from `1` to `100` divisible by `3` and `7` simultaneously. What is the sum of all these integers?
423+
414424
```@raw html
415425
</div></div>
416426
<details class = "solution-body">
@@ -502,7 +512,9 @@ julia> collect(gen)
502512
<header class="admonition-header">Exercise:</header>
503513
<div class="admonition-body">
504514
```
515+
505516
Use a generator to sum the square of all integers from `1` to `100`, which are divisible by `3` and `7` simultaneously.
517+
506518
```@raw html
507519
</div></div>
508520
<details class = "solution-body">
@@ -600,6 +612,7 @@ julia> for (i, vals) in enumerate(zip([1, 4, 2, 5], 2:12, (:a, :b, :c)))
600612
<header class="admonition-header">Exercise:</header>
601613
<div class="admonition-body">
602614
```
615+
603616
Create a matrix with elements given by the following formula
604617

605618
```math
@@ -612,6 +625,7 @@ where `i` represents row's number and `i_sum` the sum of all elements in this ro
612625
> *Sum of all elements in a column `i` is `i_sum`*
613626
614627
**Hint:** use iterators `eachcol` and `eachrow`.
628+
615629
```@raw html
616630
</div></div>
617631
<details class = "solution-body">

0 commit comments

Comments
 (0)