Converted everything to orgmode

converted everything to orgmode and added solution to the README files
This commit is contained in:
2025-03-31 08:37:19 +02:00
parent 3013d7ad47
commit 311cb8434c
25 changed files with 319 additions and 502 deletions

View File

@@ -6,14 +6,14 @@ This task is a text based task. You do not need to write any program/C++ file: t
* Task
Which of the following expressions evaluate to `true`, which to `false`?
Which of the following expressions evaluate to =true=, which to =false=?
1. `3 >= 3`
1. `true || false && false`
1. `(true || false) && false`
1. `3 > (1 < true)`
1. `8 > 4 > 2 > 1`
1. `2 < a < 4` (a is a variable of type int)
1. =3 >= 3=
1. =true || false && false=
1. =(true || false) && false=
1. =3 > (1 < true)=
1. =8 > 4 > 2 > 1=
1. =2 < a < 4= (a is a variable of type int)
* Solutions

View File

@@ -3,9 +3,9 @@
* Task
Translate the following natural language expressions to `C++` expressions. Assume that all the variables are non-negative integers or boolean (of value `true` or `false`).
Translate the following natural language expressions to =C++= expressions. Assume that all the variables are non-negative integers or boolean (of value =true= or =false=).
/For this task you need to write the solutions in the `solutions.cpp` file, by filling the various functions that have been defined for each subtasks./
/For this task you need to write the solutions in the =solutions.cpp= file, by filling the various functions that have been defined for each subtasks./
*Example:* \(a\) is greater than \(3\) and smaller than \(5\). \(\Longrightarrow\) *Solution:*
@@ -13,7 +13,7 @@ Translate the following natural language expressions to `C++` expressions. Assum
return a > 3 && a < 5;
#+end_src
/Note:/ Do not confuse the bitwise logical operators (e.g., `&`) with their binary logical counterparts (`&&`). The semantics are slightly different — bitwise operators do not exhibit short circuit evaluation.
/Note:/ Do not confuse the bitwise logical operators (e.g., =&=) with their binary logical counterparts (=&&=). The semantics are slightly different — bitwise operators do not exhibit short circuit evaluation.
1. \(a\) greater than \(b\) and the difference between \(a\) and \(b\) is smaller than \(15\).
1. \(a\) is an even natural number greater than \(a\).
@@ -23,9 +23,9 @@ return a > 3 && a < 5;
** Input
The program expects the task number as the first input followed by the parameters to the chosen task. For example, `3 5 1 1` selects task `3` with `a = 5`, `b = 1`, and `c = 1`.
The program expects the task number as the first input followed by the parameters to the chosen task. For example, =3 5 1 1= selects task =3= with =a = 5=, =b = 1=, and =c = 1=.
Note that boolean parameters for tasks 4 and 5 are entered as true and false. For example `4 true false true` would run task `4` with `a = true`, `b = false`, and `c = true`.
Note that boolean parameters for tasks 4 and 5 are entered as true and false. For example =4 true false true= would run task =4= with =a = true=, =b = false=, and =c = true=.
* Solutions
@@ -80,3 +80,7 @@ bool task5(bool a, int b) {
}
}
#+end_src
-----
Made by JirR02 in Switzerland 🇨🇭

View File

@@ -20,7 +20,7 @@ If your program is asked to print the Fibonacci primes between $0$ and $14$ the
Found 4 Fibonacci primes
#+end_src
*Important:* using anything other than `int` (e.g., `unsigned int`, floating point numbers, `long`, or double `long`) is forbidden.
*Important:* using anything other than =int= (e.g., =unsigned int=, floating point numbers, =long=, or double =long=) is forbidden.
* Solutions

View File

@@ -7,17 +7,17 @@
* Task
Fibonacci numbers grow fast, and can thus easily exceed the value range of 32-bit `int`. Think of a general way how you can check if the result of an addition would exceed the range of a 32-bit `int` (i.e. overflow) *without actually performing the addition causing the overflow.*
Fibonacci numbers grow fast, and can thus easily exceed the value range of 32-bit =int=. Think of a general way how you can check if the result of an addition would exceed the range of a 32-bit =int= (i.e. overflow) *without actually performing the addition causing the overflow.*
Remember that we consider *signed integers.* Because only half of the numbers are positive, this leaves us with 31 bits to store the actual positive number value.
Write a program that asks the user for an integer \(n\) and then prints the first $n$ Fibonacci numbers, each number on a new line. Use an `int` (we assume 32 bits, including the sign) to represent the current Fibonacci number. *Most importantly:* exit the print loop as soon as you detect that an overflow /would occur./
Write a program that asks the user for an integer \(n\) and then prints the first $n$ Fibonacci numbers, each number on a new line. Use an =int= (we assume 32 bits, including the sign) to represent the current Fibonacci number. *Most importantly:* exit the print loop as soon as you detect that an overflow /would occur./
Finally, again on a new line, output the count \(c\) of Fibonacci numbers previously printed, and the initial input \(n\) from the user, in the format: `c of n`.
Finally, again on a new line, output the count \(c\) of Fibonacci numbers previously printed, and the initial input \(n\) from the user, in the format: =c of n=.
** Example:
Let's (wrongly!) assume that \(5\) cannot be represented using a 32 bit `int`. This means that \(3\) is the largest 32-bit Fibonacci number. If your program is asked to print the first \(4\) Fibonacci numbers the output should look as follows:
Let's (wrongly!) assume that \(5\) cannot be represented using a 32 bit =int=. This means that \(3\) is the largest 32-bit Fibonacci number. If your program is asked to print the first \(4\) Fibonacci numbers the output should look as follows:
#+begin_src shell
0
@@ -38,7 +38,7 @@ If you instead ask it to print the first 100 Fibonacci numbers the output should
Printed 5 of 100 Fibonacci numbers
#+end_src
*Important:* using anything other than `int` (e.g., `unsigned int`, floating point numbers, `long`, or double `long`) is forbidden.
*Important:* using anything other than =int= (e.g., =unsigned int=, floating point numbers, =long=, or double =long=) is forbidden.
*Restrictions:*
@@ -56,7 +56,7 @@ Printed 5 of 100 Fibonacci numbers
* Mistakes
- The variable `j` goes into overflow which is not allowed!
- The variable =j= goes into overflow which is not allowed!
* Solution

View File

@@ -3,7 +3,7 @@
* Task
Write a program that inputs a non-negative integer `n` (but store it as `int`) and outputs the binary digits of `n` in the /correct/ order (i.e., starting with the most significant bit). Do not output the leading zeros or the sign.
Write a program that inputs a non-negative integer =n= (but store it as =int=) and outputs the binary digits of =n= in the /correct/ order (i.e., starting with the most significant bit). Do not output the leading zeros or the sign.
*Hint:* In order to find the largest integer \(k\) such that \(2^k \leq x\), you can utilize that \(k\) is the smallest integer such that \(2^k > \frac{x}{2}\). This observation is particularly useful to avoid an overflow for the expression \(2^k\) when searching for the most significant bit to represent \(x\).