-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from hernoufM/master
Adding new set of exercises + Organising corpus.
- Loading branch information
Showing
630 changed files
with
11,479 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
_opam | ||
www | ||
sync | ||
*.report.html | ||
*~ | ||
*~ | ||
*.cm* | ||
exercises/**/*.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
**Question :** For each of the OCaml phrases below, predict the calculated | ||
result value by OCaml for that phrase and indicate this value on the left | ||
instead of the corresponding -1. Then, verify your answers using automatic | ||
notation (click the "Grade!" button above). | ||
|
||
```ocaml | ||
let phrase0 = | ||
let x = 3 | ||
in x + 1 | ||
let phrase1 = | ||
let x = 3 in | ||
let y = x + 1 | ||
in x + y | ||
let phrase2 = | ||
let x = 2 in | ||
let x = x + x | ||
in x + x | ||
(* notice the "and" syntax and guess what it means *) | ||
let phrase3 = | ||
let x = 2 in | ||
let x = 3 and y = x + 1 | ||
in x + y | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"learnocaml_version": "1", | ||
"kind": "exercise", | ||
"stars": 1, | ||
"focus": [ | ||
"Variable declaration", | ||
"int operators" | ||
], | ||
"title": "Local declarations", | ||
"backward_exercises": [ | ||
"mooc/week1/seq3/ex1" | ||
] | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
let phrase0 = 4 | ||
let phrase1 = 7 | ||
let phrase2 = 8 | ||
let phrase3 = 6 | ||
let phrase4 = | ||
let x = 7 * 7 in | ||
let x = x * x in | ||
x * x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
(* Replace the -1 with your answers *) | ||
|
||
let phrase0 = -1 | ||
|
||
let phrase1 = -1 | ||
|
||
let phrase2 = -1 | ||
|
||
let phrase3 = -1 | ||
|
||
let phrase4 = -1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
open Test_lib | ||
open Report | ||
|
||
let testint name = | ||
Section ([ Code name ], test_variable_against_solution [%ty : int] name) | ||
|
||
(* checks that the number of occurrences of function f in code_ast is n *) | ||
let check_count_fun code_ast name f n = | ||
let count = ref 0 in | ||
let reports = find_binding code_ast name (ast_check_expr ~on_variable_occurence: | ||
(fun v -> if v = f then incr count; [])) | ||
in | ||
if !count <> n then [Message ([Text ("You have to use exactly " ^ string_of_int n ^ " times '" ^ f ^ "'.")], Failure)] | ||
else [Message ([Text("Correct number of '" ^ f ^ "' : " ^ string_of_int n ^ ".")], Success 1)] | ||
|
||
|
||
let testmult name = | ||
Section ([Code name], | ||
test_variable_against_solution [%ty : int] name @ | ||
check_count_fun code_ast name "*" 3) | ||
|
||
let testadd name = | ||
Section ([Code name], | ||
test_variable_against_solution [%ty : int] name @ | ||
check_count_fun code_ast name "+" 0) | ||
|
||
let exercise = | ||
[ testadd "phrase0"; | ||
testadd "phrase1"; | ||
testadd "phrase2"; | ||
testadd "phrase3"; | ||
testmult "phrase4"] | ||
|
||
let () = | ||
set_result @@ | ||
ast_sanity_check code_ast @@ | ||
fun () -> | ||
exercise | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#### Reminder: *bool* expressions | ||
|
||
Boolean expressions can be: | ||
|
||
- Boolean constants `true` and `false`. | ||
|
||
- Comparison expressions: `e1 cmp e2` where *cmp* is one of the operators | ||
`=` , `<>`, `<`, `<=` , `>` ou `>=`, and *e1* and *e2* are of the same | ||
type. | ||
- Expressions constructed with logical operators: | ||
- `e1 && e2` (and) | ||
- `e1 || e2` (or) | ||
- `not e` (negation of) | ||
where *e1*, *e2* and *e* of type bool. | ||
|
||
Beware of the `==` and `!=` comparisons: they should **never** be used in | ||
OCaml unless you know exactly what you are doing (they perform *physical* | ||
or *pointer* comparisons. For example, `(1,2)==(1,2)` will yield `false`). | ||
|
||
Functions cannot be compared directly, but integers, characters, lists, | ||
tuples, etc., can be compared. For numeric types, the usual order on | ||
numbers is used; for characters, alphabetical order is used; for strings, | ||
lexicographic order is used; for tuples, lexicographic order is used based | ||
on their components, and so on. | ||
|
||
** Question 1.** In the following code, replace `false` with a boolean | ||
expression that evaluates to `true` if and only if the number `x` is within | ||
(inclusive) the range from `0` to `10`. | ||
|
||
|
||
```ocaml | ||
let interval10 x = false | ||
``` | ||
|
||
**Question 2.** In the following declarations, replace the boolean | ||
expression with its value (`true` or `false`) | ||
|
||
```ocaml | ||
let value1 = true && false | ||
let value2 = true || false | ||
let value3 = not (true || true) && true | ||
``` | ||
|
||
**Question 3.** In the following declarations, replace the expression on the | ||
right-hand side with a simpler equivalent expression. | ||
|
||
```ocaml | ||
let simplify1 x y = (x || y) || x | ||
let simplify2 x y = (x > 5 && x >= 7) | ||
let simplify3 x y z = x = y && y = z && x = z | ||
let simplify4 x y = x > 7 || (x <= 7 && y > 2) | ||
let simplify5 x = (((x = true) = false) = false) = true | ||
``` | ||
|
||
**Question 4.** A leap year is a year whose number is divisible by 4, except if it is | ||
also divisible by 100... unless it is also divisible by 400. In the following declaration, | ||
replace `false` with a boolean expression that evaluates to `true` only when `x` is an | ||
integer corresponding to a leap year. | ||
|
||
```ocaml | ||
let leap x = false | ||
``` | ||
|
||
It is worth noting that the `mod` operator calculates the remainder of the division operation. | ||
Specifically, `x mod y` is equal to `0` when `x` is divisible by `y`. |
Oops, something went wrong.