Skip to content
Snippets Groups Projects
Commit 6d2f9c5a authored by Nicolas M. Thiéry's avatar Nicolas M. Thiéry
Browse files

Préparation

parent ba1782b5
No related branches found
No related tags found
No related merge requests found
Showing
with 1405 additions and 0 deletions
No preview for this file type
......@@ -121,3 +121,27 @@ rise:
</div>
```{code-cell}
:tags: []
double f(int, double) {
return 0;
}
```
```{code-cell}
:tags: []
#include <typeinfo>
```
```{code-cell}
:tags: []
typeid(f).name()
```
```{code-cell}
```
File added
---
jupytext:
text_representation:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.15.2
kernelspec:
display_name: C++17
language: C++17
name: xcpp17
---
### Objectif pédagogique : division entière
```{code-cell}
:editable: false
:tags: [hide-cell]
#include <iostream>
#include "jupyter_exercizer_helpers.hpp"
using namespace std;
```
+++
```{code-cell}
:tags: [hide-cell, variable]
CONST I1 = RANDOM_CHOICE(3, 5, 7);
I1
```
+++
```{code-cell}
:tags: [hide-cell, variable]
CONST I3 = RANDOM_CHOICE(1, 2, 4, 8, 11, 13, 16, 17, 19, 22);
I3
```
+++
```{code-cell}
:tags: [hide-output, substitution]
int r;
r = I3 / I1;
```
+++
:::{admonition} Consigne
Quelle est la valeur attendue de `r`?
:::
```{code-cell}
---
editable: true
nbgrader:
grade: false
grade_id: init
locked: false
schema_version: 3
solution: true
---
int result = INPUT(
/// BEGIN SOLUTION
I3 / I1
/// END SOLUTION
);
```
+++
```{code-cell}
---
editable: false
nbgrader:
grade: true
grade_id: check
locked: true
points: 1
schema_version: 3
solution: false
tags: [hide-cell]
---
CHECK( result == r );
```
---
jupytext:
text_representation:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.15.2
kernelspec:
display_name: C++17
language: C++17
name: xcpp17
---
### Objectif pédagogique : reste de la division entière
```{code-cell}
:editable: false
:tags: [hide-cell]
#include <iostream>
#include "jupyter_exercizer_helpers.hpp"
using namespace std;
```
+++
```{code-cell}
:tags: [hide-cell, variable]
CONST I1 = RANDOM_CHOICE(3, 5, 7);
I1
```
+++
```{code-cell}
:tags: [hide-cell, variable]
CONST I3 = RANDOM_CHOICE(1, 2, 4, 8, 11, 13, 16, 17, 19, 22);
I3
```
+++
```{code-cell}
:tags: [hide-output, substitution]
int r;
r = I3 % I1;
```
+++
:::{admonition} Consigne
Quelle est la valeur attendue de `r`?
:::
```{code-cell}
---
editable: true
nbgrader:
grade: false
grade_id: init
locked: false
schema_version: 3
solution: true
---
int result = INPUT(
/// BEGIN SOLUTION
I3 % I1
/// END SOLUTION
);
```
+++
```{code-cell}
---
editable: false
nbgrader:
grade: true
grade_id: check
locked: true
points: 1
schema_version: 3
solution: false
tags: [hide-cell]
---
CHECK( result == r );
```
---
jupyter:
jupytext:
text_representation:
extension: .md
format_name: myst
kernelspec:
display_name: C++17
language: C++17
name: xcpp17
---
### Objectif pédagogique : priorité des opérations
```{code-cell} c++
---
editable: false
tags: [hide-cell]
---
#include <iostream>
#include "jupyter_exercizer_helpers.hpp"
using namespace std;
```
+++
```{code-cell} c++
---
tags: [hide-cell, variable]
---
CONST I1 = RANDOM_INT(1, 7);
I1
```
+++
```{code-cell} c++
---
tags: [hide-cell, variable]
---
CONST I2 = RANDOM_INT(5, 12);
I2
```
+++
```{code-cell} c++
---
tags: [hide-cell, variable]
---
CONST I3 = RANDOM_INT(1, 7);
I3
```
+++
```{code-cell} c++
---
tags: [hide-output,substitution]
---
int r;
r = I2 + I1 * I3;
```
+++
:::{admonition} Consigne
Quelle est la valeur attendue de `r`?
:::
```{code-cell}
---
editable: true
nbgrader:
grade: false
grade_id: init
locked: false
schema_version: 3
solution: true
---
int result = INPUT(
/// BEGIN SOLUTION
I2 + I1 * I3
/// END SOLUTION
);
```
+++
```{code-cell}
---
editable: false
nbgrader:
grade: true
grade_id: check
locked: true
points: 1
schema_version: 3
solution: false
tags: [hide-cell]
---
CHECK( result == r );
```
---
jupyter:
jupytext:
text_representation:
extension: .md
format_name: myst
kernelspec:
display_name: C++17
language: C++17
name: xcpp17
---
### Objectif pédagogique : priorité des opérations
```{code-cell} c++
---
editable: false
tags: [hide-cell]
---
#include <iostream>
#include "jupyter_exercizer_helpers.hpp"
using namespace std;
```
+++
```{code-cell} c++
---
tags: [hide-cell, variable]
---
CONST I1 = RANDOM_INT(1, 5);
I1
```
+++
```{code-cell} c++
---
tags: [hide-cell, variable]
---
CONST I2 = RANDOM_INT(1, 3);
I2
```
+++
```{code-cell} c++
---
tags: [hide-cell, variable]
---
CONST I3 = RANDOM_INT(1, 7);
I3
```
+++
```{code-cell} c++
---
tags: [hide-output,substitution]
---
int r;
r = (I2 PLUSOUMOINS I1) * I3;
```
+++
:::{admonition} Consigne
Quelle est la valeur attendue de `r`?
:::
```{code-cell}
---
editable: true
nbgrader:
grade: false
grade_id: init
locked: false
schema_version: 3
solution: true
---
int result = INPUT(
/// BEGIN SOLUTION
(I2 PLUSOUMOINS I1) * I3
/// END SOLUTION
);
```
+++
```{code-cell}
---
editable: false
nbgrader:
grade: true
grade_id: check
locked: true
points: 1
schema_version: 3
solution: false
tags: [hide-cell]
---
CHECK( result == r );
```
---
jupytext:
text_representation:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.15.2
kernelspec:
display_name: C++17
language: C++17
name: xcpp17
---
### Objectif pédagogique : alternative aux parenthèses
```{code-cell}
:editable: false
:tags: [hide-cell]
#include <iostream>
#include "jupyter_exercizer_helpers.hpp"
using namespace std;
```
+++
```{code-cell}
:tags: [hide-cell, variable]
CONST I1 = RANDOM_INT(1, 5);
CONST I2 = RANDOM_INT(1, 7);
CONST I3 = RANDOM_INT(1, 5);
```
+++
```{code-cell}
:tags: [hide-output, substitution]
int I, J, K, N;
I = I2 - I1;
J = I3 + I2;
K = I * J;
N = I2 - I1 * I3 + I2;
bool r = K == N;
```
+++
:::{admonition} Consigne
Quelle est la valeur attendue de `r`?
:::
```{code-cell}
---
editable: true
nbgrader:
grade: false
grade_id: init
locked: false
schema_version: 3
solution: true
---
bool result = INPUT(
/// BEGIN SOLUTION
r
/// END SOLUTION
);
```
+++
```{code-cell}
---
editable: false
nbgrader:
grade: true
grade_id: check
locked: true
points: 1
schema_version: 3
solution: false
tags: [hide-cell]
---
CHECK( result == r );
```
#ifndef RANDOMIZATION_H
#define RANDOMIZATION_H
#include <iostream>
#include <cstdlib>
#include <vector>
#include <functional>
/** Infrastructure minimale de test **/
#ifndef ASSERT
#define ASSERT(test) if (!(test)) { throw std::runtime_error("\\x1b[48;5;224mTest failed: "#test); }
#endif
#ifndef CHECK
#define CHECK(test) if ( !(test) ) { throw std::runtime_error("\\x1b[48;5;224mTest failed: "#test); }
#endif
// TODO: how to initialize the seed?
// TODO: randomize ???
#define PLUSOUMOINS +
#define CONST const auto
// TODO: randomize ???
#define X x
#define Y y
#define Z z
int RANDOM_INT(int min, int max) {
return min + (rand() % (max - min + 1));
}
template<typename T, typename ... Args>
T RANDOM_CHOICE(const T arg0, const Args... args) {
const std::vector<T> v({arg0, args...});
return v[rand() % v.size()];
}
template<typename ... Args>
auto RANDOM_CHOICE(const char * arg0, const Args... args) {
const std::vector<std::string> v({arg0, args...});
return v[rand() % v.size()];
}
class RANDOM_VECTOR_CLASS {
public:
template <typename F, typename ... Args>
auto operator ()(int N, F f, Args ... args) {
using invoke_result_t = typename std::invoke_result<F, Args ...>::type;
std::vector<invoke_result_t> v(N);
for (auto &value: v)
value = f(args...);
return v;
}
/*template<typename ... Args>
auto operator ()(int N, RANDOM_VECTOR_CLASS f, Args... args) {
std::vector<std::vector<int>> v(N);
for (auto &value: v)
value = f(args...);
return v;
}*/
};
RANDOM_VECTOR_CLASS RANDOM_VECTOR;
template<typename T>
std::ostream & operator << (std::ostream& o, const std::vector<T> &v) {
o << "{";
if ( v.size() >= 0 ) {
o << v[0];
for ( unsigned int i=1; i<v.size(); i++ )
o << ", " << v[i];
}
o << "}";
return o;
}
template<class T>
T INPUT(T t) {
return t;
}
#endif
from typing import Any
from random import randint, choice
CONST = Any
def INPUT(default: Any) -> Any:
return default
def RANDOM_INT(min: int, max: int):
return randint(min, max+1)
def RANDOM_CHOICE(*args):
r"""
Return a random element of `args`
>>> RANDOM_CHOICE("alice", "bob", "charlie") # doctest: +SKIP
'charlie'
>>> RANDOM_CHOICE("alice")
'alice'
"""
return choice(args)
---
jupyter:
jupytext:
text_representation:
extension: .md
format_name: myst
kernelspec:
display_name: C++17
language: C++17
name: xcpp17
---
### Objectif pédagogique : opération "and"
```{code-cell} c++
---
editable: false
tags: [hide-cell]
---
#include <iostream>
#include "jupyter_exercizer_helpers.hpp"
using namespace std;
```
+++
```{code-cell} c++
---
tags: [hide-cell, variable]
---
CONST I1 = RANDOM_INT(3, 9);
I1
```
+++
```{code-cell} c++
---
tags: [hide-output, substitution]
---
int x = I1;
bool r = x >= 0 and x <= 2;
```
+++
:::{admonition} Consigne
Quelle est la valeur attendue de `r`?
:::
```{code-cell}
---
editable: true
nbgrader:
grade: false
grade_id: init
locked: false
schema_version: 3
solution: true
---
bool result = INPUT(
/// BEGIN SOLUTION
r
/// END SOLUTION
);
```
+++
```{code-cell}
---
editable: false
nbgrader:
grade: true
grade_id: check
locked: true
points: 1
schema_version: 3
solution: false
tags: [hide-cell]
---
CHECK( result == r );
```
---
jupyter:
jupytext:
text_representation:
extension: .md
format_name: myst
kernelspec:
display_name: C++17
language: C++17
name: xcpp17
---
### Objectif pédagogique : opération "or"
```{code-cell} c++
---
editable: false
tags: [hide-cell]
---
#include <iostream>
#include "jupyter_exercizer_helpers.hpp"
using namespace std;
```
+++
```{code-cell} c++
---
tags: [hide-cell, variable]
---
CONST I1 = RANDOM_INT(-1, 4);
I1
```
+++
```{code-cell} c++
---
tags: [hide-output, substitution]
---
int x = I1;
bool r = x < 0 or x > 2;
```
+++
:::{admonition} Consigne
Quelle est la valeur attendue de `r`?
:::
```{code-cell}
---
editable: true
nbgrader:
grade: false
grade_id: init
locked: false
schema_version: 3
solution: true
---
bool result = INPUT(
/// BEGIN SOLUTION
r
/// END SOLUTION
);
```
+++
```{code-cell}
---
editable: false
nbgrader:
grade: true
grade_id: check
locked: true
points: 1
schema_version: 3
solution: false
tags: [hide-cell]
---
CHECK( result == r );
```
#ifndef RANDOMIZATION_H
#define RANDOMIZATION_H
#include <iostream>
#include <cstdlib>
#include <vector>
#include <functional>
/** Infrastructure minimale de test **/
#ifndef ASSERT
#define ASSERT(test) if (!(test)) { throw std::runtime_error("\\x1b[48;5;224mTest failed: "#test); }
#endif
#ifndef CHECK
#define CHECK(test) if ( !(test) ) { throw std::runtime_error("\\x1b[48;5;224mTest failed: "#test); }
#endif
// TODO: how to initialize the seed?
// TODO: randomize ???
#define PLUSOUMOINS +
#define CONST const auto
// TODO: randomize ???
#define X x
#define Y y
#define Z z
int RANDOM_INT(int min, int max) {
return min + (rand() % (max - min + 1));
}
template<typename T, typename ... Args>
T RANDOM_CHOICE(const T arg0, const Args... args) {
const std::vector<T> v({arg0, args...});
return v[rand() % v.size()];
}
template<typename ... Args>
auto RANDOM_CHOICE(const char * arg0, const Args... args) {
const std::vector<std::string> v({arg0, args...});
return v[rand() % v.size()];
}
class RANDOM_VECTOR_CLASS {
public:
template <typename F, typename ... Args>
auto operator ()(int N, F f, Args ... args) {
using invoke_result_t = typename std::invoke_result<F, Args ...>::type;
std::vector<invoke_result_t> v(N);
for (auto &value: v)
value = f(args...);
return v;
}
/*template<typename ... Args>
auto operator ()(int N, RANDOM_VECTOR_CLASS f, Args... args) {
std::vector<std::vector<int>> v(N);
for (auto &value: v)
value = f(args...);
return v;
}*/
};
RANDOM_VECTOR_CLASS RANDOM_VECTOR;
template<typename T>
std::ostream & operator << (std::ostream& o, const std::vector<T> &v) {
o << "{";
if ( v.size() >= 0 ) {
o << v[0];
for ( unsigned int i=1; i<v.size(); i++ )
o << ", " << v[i];
}
o << "}";
return o;
}
template<class T>
T INPUT(T t) {
return t;
}
#endif
from typing import Any
from random import randint, choice
CONST = Any
def INPUT(default: Any) -> Any:
return default
def RANDOM_INT(min: int, max: int):
return randint(min, max+1)
def RANDOM_CHOICE(*args):
r"""
Return a random element of `args`
>>> RANDOM_CHOICE("alice", "bob", "charlie") # doctest: +SKIP
'charlie'
>>> RANDOM_CHOICE("alice")
'alice'
"""
return choice(args)
import random
import re
from typing import Dict, Tuple
from jupyter_exercizer_helpers import RANDOM_INT, RANDOM_CHOICE
STRING_QUOTE = '"'
VECTOR_OPEN = "{"
VECTOR_CLOSE = "}"
def_regexp = {
"C++": r"CONST\s+(\w+)\s+=\s+(.*?);?\s*$",
"python": r"(\w+):\s+CONST\s+=\s+(.*?);?\s*$"
}
for language in ['C++11', 'C++14', 'C++17']:
def_regexp[language] = def_regexp['C++']
def to_language(value):
"""
Return `value` as a string representing a C++ constant
.. TODO:: make the output language configurable
>>> to_language(3)
'3'
>>> to_language("alice")
'"alice"'
>>> to_language([1,2,3])
'{1, 2, 3}'
>>> to_language([[1,2],["alice", "bob"]])
'{{1, 2}, {"alice", "bob"}}'
"""
if isinstance(value, str):
if value == "REF":
return "&"
if value == "VAL":
return ""
return STRING_QUOTE + value + STRING_QUOTE
elif isinstance(value, list):
return VECTOR_OPEN + ", ".join(to_language(v) for v in value) + VECTOR_CLOSE
else:
return str(value)
def RANDOM_VECTOR(n, generator, *args):
r"""
Return a random vector of length `n` and whose elements are
generated by calling `generator(*args)`
This return a random vector of integers of length 5, with
elements between 1 and 3:
>>> RANDOM_VECTOR(5, RANDOM_INT, 1, 3) # doctest: +SKIP
[3, 1, 2, 1, 3]
>>> RANDOM_VECTOR(5, RANDOM_INT, 1, 1)
[1, 1, 1, 1, 1]
"""
return [generator(*args) for i in range(n)]
def RANDOM_VALOUREF():
r"""
pas sur que ce soit la meilleur des methodes....
"""
return str(random.choice(["REF", "VAL"]))
locals = {
"RANDOM_INT": RANDOM_INT,
"RANDOM_CHOICE": RANDOM_CHOICE,
"RANDOM_VECTOR": RANDOM_VECTOR,
"RANDOM_VALOUREF": RANDOM_VALOUREF,
}
test_code = """CONST N = RANDOM_INT(3,3);
CONST M = RANDOM_INT(4,4);
CONST V = RANDOM_VECTOR(N, RANDOM_INT, 5, 5);
CONST VV = RANDOM_VECTOR(N, RANDOM_VECTOR, M, RANDOM_INT, 1, 1);
int main () {
int a = N + M;
vector<int> v = V;
vector<vector<int>> vv = VV;
}"""
class Randomizer:
def __init__(self, language='C++'):
consts = {}
consts["R"], consts["S"], consts["T"] = random.sample("rst", 3)
consts["X"], consts["Y"], consts["Z"] = random.sample("xyz", 3)
consts["I"], consts["J"], consts["K"], consts["N"] = random.sample("ijkn", 4)
consts["PLUSOUMOINS"] = str(random.choice(["+", "-"]))
consts["NAME"] = str(
random.choice(
["Alexandre", "Yasmine", "Albert", "Alice", "Antoine", "Anna"]
)
)
self.consts = consts
self.def_regexp = re.compile(def_regexp[language])
def randomize(self, text: str, is_code: bool = True) -> str:
result = []
for line in text.splitlines():
pattern = re.compile(r"\b(" + "|".join(self.consts.keys()) + r")\b")
if is_code:
match = re.match(self.def_regexp, line)
else:
match = None
if match:
# Define new constant
variable, value = match.groups()
# Substitutes all constants in the value
value = pattern.sub(lambda i: self.consts[i.group()], value)
# Evaluates the value in a context containing all the RANDOM_*
# functions
self.consts[variable] = to_language(eval(value, {}, locals))
else:
# Substitutes all constants
line = pattern.sub(lambda i: self.consts[i.group()], line)
result.append(line)
return "\n".join(result)
def randomize_code(code: str) -> Tuple[str, Dict]:
r"""
Randomize the given code
Examples:
>>> import random
>>> random.seed(0)
>>> randomize_code("int XX=3;")[0]
'int XX=3;'
>>> randomize_code("int X=3; int Y=4; int Z=5;")[0]
'int z=3; int x=4; int y=5;'
>>> randomize_code("I, J, K, N")[0]
'n, k, j, i'
>>> randomize_code("int X=1;\nint Y=2;")[0]
'int z=1;\nint y=2;'
>>> print(test_code)
CONST N = RANDOM_INT(3,3);
CONST M = RANDOM_INT(4,4);
CONST V = RANDOM_VECTOR(N, RANDOM_INT, 5, 5);
CONST VV = RANDOM_VECTOR(N, RANDOM_VECTOR, M, RANDOM_INT, 1, 1);
int main () {
int a = N + M;
vector<int> v = V;
vector<vector<int>> vv = VV;
}
>>> print(randomize_code(test_code)[0])
int main () {
int a = 3 + 4;
vector<int> v = {5, 5, 5};
vector<vector<int>> vv = {{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}};
}
"""
randomizer = Randomizer()
code = randomizer.randomize(code)
return code, randomizer.consts
---
jupytext:
text_representation:
extension: .md
format_name: myst
format_version: 0.13
kernelspec:
display_name: Python 3 (ipykernel)
language: python
name: python3
---
# Exercices d'entraînement
Exécutez la cellule suivante, puis choisissez le thème sur lequel
vous souhaitez vous entraîner.
```{code-cell} ipython3
---
editable: true
slideshow:
slide_type: ''
---
from entraîneur import entraîneur
entraîneur
```
```{code-cell} ipython3
```
import glob
from ipywidgets import interactive # type: ignore
from jupyter_exercizer import Exercizer
from IPython.display import display
thèmes = {
'variable': 'Variables',
'arithmetic': 'Arithmétique',
'bool': 'Expressions booléennes',
'for': 'Boucles for',
'while': 'Boucles while',
'function_prototype': 'Prototypes de fonctions',
}
def entraîneur(Thème=[(a, b) for b, a in thèmes.items()]):
exercizes = glob.glob(f"{Thème}/*.md")
display(Exercizer(exercizes))
entraîneur = interactive(entraîneur)
---
jupyter:
jupytext:
text_representation:
extension: .md
format_name: myst
kernelspec:
display_name: C++17
language: C++17
name: xcpp17
---
### Objectif pédagogique : accumulateur avec boucle for
```{code-cell} c++
---
editable: false
tags: [hide-cell]
---
#include <iostream>
#include "jupyter_exercizer_helpers.hpp"
using namespace std;
```
+++
```{code-cell} c++
---
tags: [hide-cell, variable]
---
CONST RINIT = RANDOM_INT(1, 7);
RINIT
```
+++
```{code-cell} c++
---
tags: [hide-cell, variable]
---
CONST IMAX = RANDOM_INT(2, 4);
IMAX
```
+++
```{code-cell} c++
---
tags: [hide-output, substitution]
---
int r = RINIT;
for ( int I = 1; I <= IMAX ; I = I + 1 ) {
r = r + I;
}
```
+++
:::{admonition} Consigne
Quelle est la valeur attendue de `r`?
:::
```{code-cell}
---
editable: true
nbgrader:
grade: false
grade_id: init
locked: false
schema_version: 3
solution: true
---
int result = INPUT(
/// BEGIN SOLUTION
r
/// END SOLUTION
);
```
+++
```{code-cell}
---
editable: false
nbgrader:
grade: true
grade_id: check
locked: true
points: 1
schema_version: 3
solution: false
tags: [hide-cell]
---
CHECK( result == r );
```
---
jupyter:
jupytext:
text_representation:
extension: .md
format_name: myst
kernelspec:
display_name: C++17
language: C++17
name: xcpp17
---
### Objectif pédagogique : comprendre une boucle for et faire un calcul simple
```{code-cell} c++
---
editable: false
tags: [hide-cell]
---
#include <iostream>
#include "jupyter_exercizer_helpers.hpp"
using namespace std;
```
+++
```{code-cell} c++
---
tags: [hide-cell, variable]
---
CONST RINIT = RANDOM_INT(1, 7);
RINIT
```
+++
```{code-cell} c++
---
tags: [hide-cell, variable]
---
CONST IMAX = RANDOM_INT(2, 4);
IMAX
```
+++
```{code-cell} c++
---
tags: [hide-output, substitution]
---
int r = RINIT;
int a = 2;
for ( int I = 1; I <= IMAX ; I = I + 1 ) {
r = r + a * I;
}
```
+++
:::{admonition} Consigne
Quelle est la valeur attendue de `r`?
:::
```{code-cell}
---
editable: true
nbgrader:
grade: false
grade_id: init
locked: false
schema_version: 3
solution: true
---
int result = INPUT(
/// BEGIN SOLUTION
r
/// END SOLUTION
);
```
+++
```{code-cell}
---
editable: false
nbgrader:
grade: true
grade_id: check
locked: true
points: 1
schema_version: 3
solution: false
tags: [hide-cell]
---
CHECK( result == r );
```
---
jupyter:
jupytext:
text_representation:
extension: .md
format_name: myst
kernelspec:
display_name: C++17
language: C++17
name: xcpp17
---
### Objectif pédagogique : comprendre une factorielle avec une boucle for
```{code-cell} c++
---
editable: false
tags: [hide-cell]
---
#include <iostream>
#include "jupyter_exercizer_helpers.hpp"
using namespace std;
```
+++
```{code-cell} c++
---
tags: [hide-cell, variable]
---
CONST N0 = RANDOM_INT(3, 5);
// Ne pas randomiser le nom de variable pour l'indice k, sinon risque qu'on tombe sur n, qui existe déjà dans ce code.
// (Ou alors remplacer n par m, puis randomiser le nom de variable de l'indice k ?)
N0
```
+++
```{code-cell} c++
---
tags: [hide-output, substitution]
---
int n, r;
n = N0;
r = 1;
for ( int k = 1; k <= n; k++ ) {
r = r * k;
}
```
+++
:::{admonition} Consigne
Quelle est la valeur attendue de `r`?
:::
+++
```{code-cell}
---
editable: true
nbgrader:
grade: false
grade_id: init
locked: false
schema_version: 3
solution: true
---
int result = INPUT(
/// BEGIN SOLUTION
r
/// END SOLUTION
);
```
+++
```{code-cell}
---
editable: false
nbgrader:
grade: true
grade_id: check
locked: true
points: 1
schema_version: 3
solution: false
tags: [hide-cell]
---
CHECK( result == r );
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment