Skip to content

Commit

Permalink
Merge pull request #37 from hernoufM/master
Browse files Browse the repository at this point in the history
Adding new set of exercises + Organising corpus.
  • Loading branch information
AltGr committed Oct 30, 2023
2 parents 54a1cec + b6e1f61 commit 5b94c8c
Show file tree
Hide file tree
Showing 630 changed files with 11,479 additions and 178 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
_opam
www
sync
*.report.html
*~
*~
*.cm*
exercises/**/*.js
3 changes: 2 additions & 1 deletion exercises/fpottier/alpha_beta/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"learnocaml_version":"1",
"kind":"exercise",
"stars":3,
"title":"Alpha-Beta Search"
"title":"Alpha-Beta Search",
"backward_exercises": ["mooc/week6/seq3/ex1"]
}
3 changes: 2 additions & 1 deletion exercises/fpottier/anagrams/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"learnocaml_version":"1",
"kind":"exercise",
"stars":3,
"title":"Recognizing Anagrams"
"title":"Recognizing Anagrams",
"backward_exercises": ["fpottier/alpha_beta"]
}
3 changes: 2 additions & 1 deletion exercises/fpottier/breaking_sort/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"learnocaml_version":"1",
"kind":"exercise",
"stars":3,
"title":"Breaking a Sort"
"title":"Breaking a Sort",
"backward_exercises": ["fpottier/anagrams"]
}
3 changes: 2 additions & 1 deletion exercises/fpottier/counting_trees/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"learnocaml_version":"1",
"kind":"exercise",
"stars":3,
"title":"Counting trees"
"title":"Counting trees",
"backward_exercises": ["fpottier/breaking_sort"]
}
3 changes: 2 additions & 1 deletion exercises/fpottier/enumerating_trees/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"learnocaml_version":"1",
"kind":"exercise",
"stars":3,
"title":"Enumerating Trees"
"title":"Enumerating Trees",
"backward_exercises": ["fpottier/counting_trees"]
}
3 changes: 2 additions & 1 deletion exercises/fpottier/generic_sorting/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"learnocaml_version":"1",
"kind":"exercise",
"stars":3,
"title":"Generic Sorting"
"title":"Generic Sorting",
"backward_exercises": ["fpottier/enumerating_trees"]
}
3 changes: 2 additions & 1 deletion exercises/fpottier/huffman/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"learnocaml_version":"1",
"kind":"exercise",
"stars":3,
"title":"Huffman Compression"
"title":"Huffman Compression",
"backward_exercises": ["fpottier/generic_sorting"]
}
3 changes: 2 additions & 1 deletion exercises/fpottier/infinite_arrays/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"learnocaml_version":"1",
"kind":"exercise",
"stars":3,
"title":"Infinite Arrays"
"title":"Infinite Arrays",
"backward_exercises": ["fpottier/huffman"]
}
3 changes: 2 additions & 1 deletion exercises/fpottier/leftist_heaps/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"learnocaml_version":"1",
"kind":"exercise",
"stars":3,
"title":"Leftist heaps"
"title":"Leftist heaps",
"backward_exercises": ["fpottier/infinite_arrays"]
}
3 changes: 2 additions & 1 deletion exercises/fpottier/merge_sort/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"learnocaml_version":"1",
"kind":"exercise",
"stars":3,
"title":"Merge Sort"
"title":"Merge Sort",
"backward_exercises": ["fpottier/leftist_heaps"]
}
3 changes: 2 additions & 1 deletion exercises/fpottier/nondet_monad_cont/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"learnocaml_version":"1",
"kind":"exercise",
"stars":3,
"title":"Implementing Nondeterminism with Continuations"
"title":"Implementing Nondeterminism with Continuations",
"backward_exercises": ["fpottier/merge_sort"]
}
3 changes: 2 additions & 1 deletion exercises/fpottier/nondet_monad_defun/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"learnocaml_version":"1",
"kind":"exercise",
"stars":3,
"title":"Implementing Nondeterminism as an Abstract Machine"
"title":"Implementing Nondeterminism as an Abstract Machine",
"backward_exercises": ["fpottier/nondet_monad_cont"]
}
3 changes: 2 additions & 1 deletion exercises/fpottier/nondet_monad_seq/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"learnocaml_version":"1",
"kind":"exercise",
"stars":3,
"title":"Implementing Nondeterminism with Sequences"
"title":"Implementing Nondeterminism with Sequences",
"backward_exercises": ["fpottier/nondet_monad_defun"]
}
3 changes: 2 additions & 1 deletion exercises/fpottier/parser_combinators/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"learnocaml_version":"1",
"kind":"exercise",
"stars":3,
"title":"Parser Combinators"
"title":"Parser Combinators",
"backward_exercises": ["fpottier/nondet_monad_seq"]
}
3 changes: 2 additions & 1 deletion exercises/fpottier/persistent_arrays/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"learnocaml_version":"1",
"kind":"exercise",
"stars":3,
"title":"Persistent arrays"
"title":"Persistent arrays",
"backward_exercises": ["fpottier/parser_combinators"]
}
3 changes: 2 additions & 1 deletion exercises/fpottier/pprint/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"learnocaml_version":"1",
"kind":"exercise",
"stars":3,
"title":"A pretty-printer"
"title":"A pretty-printer",
"backward_exercises": ["fpottier/persistent_arrays"]
}
3 changes: 2 additions & 1 deletion exercises/fpottier/random_access_lists/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"learnocaml_version":"1",
"kind":"exercise",
"stars":3,
"title":"Random access lists"
"title":"Random access lists",
"backward_exercises": ["fpottier/pprint"]
}
3 changes: 2 additions & 1 deletion exercises/fpottier/sat/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"learnocaml_version":"1",
"kind":"exercise",
"stars":3,
"title":"A SAT solver"
"title":"A SAT solver",
"backward_exercises": ["fpottier/random_access_lists"]
}
3 changes: 2 additions & 1 deletion exercises/fpottier/spectre/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"learnocaml_version":"1",
"kind":"exercise",
"stars":3,
"title":"From a Spectre to a Tree"
"title":"From a Spectre to a Tree",
"backward_exercises": ["fpottier/sat"]
}
3 changes: 2 additions & 1 deletion exercises/fpottier/stereo/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"learnocaml_version":"1",
"kind":"exercise",
"stars":3,
"title":"Trees in Stereo Vision"
"title":"Trees in Stereo Vision",
"backward_exercises": ["fpottier/spectre"]
}
3 changes: 2 additions & 1 deletion exercises/fpottier/symbolic_sequences_data/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"learnocaml_version":"1",
"kind":"exercise",
"stars":3,
"title":"Symbolic Sequences as Data"
"title":"Symbolic Sequences as Data",
"backward_exercises": ["fpottier/stereo"]
}
3 changes: 2 additions & 1 deletion exercises/fpottier/symbolic_sequences_objects/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"learnocaml_version":"1",
"kind":"exercise",
"stars":3,
"title":"Symbolic Sequences as Objects"
"title":"Symbolic Sequences as Objects",
"backward_exercises": ["fpottier/symbolic_sequences_data"]
}
3 changes: 2 additions & 1 deletion exercises/fpottier/tictactoe/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"learnocaml_version":"1",
"kind":"exercise",
"stars":3,
"title":"Building a Game Tree"
"title":"Building a Game Tree",
"backward_exercises": ["fpottier/symbolic_sequences_objects"]
}
3 changes: 2 additions & 1 deletion exercises/fpottier/tree_iterators/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"learnocaml_version":"1",
"kind":"exercise",
"stars":3,
"title":"Tree Iterators"
"title":"Tree Iterators",
"backward_exercises": ["fpottier/tictactoe"]
}
3 changes: 2 additions & 1 deletion exercises/fpottier/unionfind/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"learnocaml_version":"1",
"kind":"exercise",
"stars":3,
"title":"The Union-Find data structure"
"title":"The Union-Find data structure",
"backward_exercises": ["fpottier/tree_iterators"]
}
27 changes: 27 additions & 0 deletions exercises/hferee/1.2_declarations/descr.md
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
```
13 changes: 13 additions & 0 deletions exercises/hferee/1.2_declarations/meta.json
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.
1 change: 1 addition & 0 deletions exercises/hferee/1.2_declarations/prepare.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

8 changes: 8 additions & 0 deletions exercises/hferee/1.2_declarations/solution.ml
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
12 changes: 12 additions & 0 deletions exercises/hferee/1.2_declarations/template.ml
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

39 changes: 39 additions & 0 deletions exercises/hferee/1.2_declarations/test.ml
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

71 changes: 71 additions & 0 deletions exercises/hferee/1.3_bool/descr.md
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`.
Loading

0 comments on commit 5b94c8c

Please sign in to comment.