Frontmatter

If you are publishing this notebook on the web, you can set the parameters below to provide HTML metadata. This is useful for search engines and social media.

Author 1

BMI

The BMI is calculated with this formula:

$$\text{BMI} = \frac{m}{l^2}$$

with $m$ as the mass in kg and $l$ as the height in m.

Write code that shows "Underweight" for $\text{BMI} < 18.5$, "Normal weight" for $18.5 \le \text{BMI} < 25$ and "Overweight" for $25.0 \le \text{BMI}$.

Test your code with the two sliders below.

The variables m and l are already defined and their values are updated with the sliders.

md"""
# BMI

The BMI is calculated with this formula:

$\text{BMI} = \frac{m}{l^2}$

with $m$ as the mass in kg and $l$ as the height in m.

Write code that shows "Underweight" for $\text{BMI} < 18.5$, "Normal weight" for $18.5 \le \text{BMI} < 25$ and "Overweight" for $25.0 \le \text{BMI}$.

Test your code with the two sliders below.

The variables `m` and `l` are already defined and their values are updated with the sliders.
"""
15.0 ms
@bind m Slider(2:200)
329 ms

m = 2 (kg)

md"""
`m` = $m (kg)
"""
10.6 ms
@bind l Slider(0.30:0.01:2.50)
108 ms

l = 0.3 (m)

455 μs
# Your code starts here

11.0 μs

Number of grains

You know for sure about the story with grains for every chess square.

A chess board has 64 squares. For the first square, there is only one grain. For the second one, there are two grains. The number of grains doubles for every square.

Calculate the number of grains for every square and their sum.

437 μs
# Your code starts here

10.5 μs

Reverse string

Write a function named reverse_string that takes an argument as a string and returns the reversed string.

No cheating by using builtin reversing functions!

Example: "string" would get "gnirts".

19.4 ms
# Write your function here

10.4 μs

🔴 The function reverse_string is not implemented yet 🤨

18.1 μs

String extraction

Extract the string "Hello world" out of the string variable mess defined below.

The space between the two words must be included!

The extracted string should be contained in a variable named extracted.

Hint: Remember that strings are a chain of characters. So you can use a lot of what you have learned about vectors on strings.

504 μs
"OHLENLNLMUIOQ WNHSIDWNOURLDSD"
# 12345678901234567890123456789
mess = "OHLENLNLMUIOQ WNHSIDWNOURLDSD"
9.5 μs
# Your code starts here

24.7 μs

🔴 The variable extracted is not defined yet 🤨

20.1 μs

Squaring difference

Write a function named squaring_difference that takes one argument N as a natural number and returns the following:

$$\left(\sum_{i=1}^N i\right)^2 - \sum_{i=1}^N i^2$$

249 μs
# Write your function here

10.3 μs

🔴 The function squaring_difference is not implemented yet 🤨

18.4 μs

Tick-tack-toe

Only for those who have time left and want to try a hard task!

Now that you know about matrices in Julia, use a matrix to present a Tick-tack-toe board.

To place X or O, take the user input for the row and column using the the form below. The input is stored in the variables input_row and input_column. Click on "Submit Query" to submit the input.

Make sure you update the board after the user input.

You want more?

  • Implement player names.

  • Implement a check if a user did win.

  • Check your code for possible performance issues. Try to minimize allocations.

  • Implement a playing AI. No, kidding! Just tell me to give you more tasks if get here 😂

BTW: You can use Julia for AI, so the programming language is not the limitation here 😅

27.0 ms

Row:

Column:

281 ms
1
input_row = parse(Int64, input_values[1])
43.4 μs
Loading more cells...