Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .local/share/rippkgs-index.sqlite
17 changes: 17 additions & 0 deletions .replit
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,20 @@ start = "ocamllsp"

[nix]
channel = "stable-23_11"

[packager]
language = "dotnet"

[packager.features]
packageSearch = true

[env]
DOTNET_NOLOGO = "1"
DOTNET_CLI_TELEMETRY_OPTOUT = "1"

[gitHubImport]
requiredFiles = [".replit", "replit.nix"]

[deployment]
run = ["dotnet", "run"]
deploymentTarget = "cloudrun"
31 changes: 31 additions & 0 deletions 01/.task.ml.2635795876~
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
(* Ex O1 *)
let char_succ c =
if c < '\255' then c |> int_of_char |> succ |> char_of_int
else
'\000'


(* Ex O2 *)
let string_cons c s = String.make 1 c ^ s



let _ =int_of_float (sqrt (float_of_int (int_of_string "81")))

let _ =
let string_to_int = int_of_string "81" in
let int_to_float = float_of_int string_to_int in
let square_root = sqrt int_to_float in
let d = int_of_float square_root in
d


let _ =
let cr = "cream" in
let i_u_we =
let sr = string_cons 's' cr in
"I " ^ sr ^ ", you " ^ sr ^ ", we all " ^ sr in
i_u_we ^ " for ice " ^ cr


let f = let c = ref 0 in fun x -> c := !c + x; !c
56 changes: 56 additions & 0 deletions 01/task.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
(* Ex O1 *)
let char_succ c =
if c < '\255' then c |> int_of_char |> succ |> char_of_int
else
'\000'


(* Ex O2 *)
let string_cons c s = String.make 1 c ^ s


(* EX 03 *)
let _ = int_of_float (sqrt (float_of_int (int_of_string "81")))

let _ =
let string_to_int = int_of_string "81" in
let int_to_float = float_of_int string_to_int in
let square_root = sqrt int_to_float in
let d = int_of_float square_root in


int_of_float (sqrt (float_of_int (int_of_string "81")))


(* EX 04 *)
let _ =
let cr = "cream" in
let i_u_we =
let sr = string_cons 's' cr in
"I " ^ sr ^ ", you " ^ sr ^ ", we all " ^ sr in
i_u_we ^ " for ice " ^ cr


(* Pour info *)
let f = let c = ref 0 in fun x -> c := !c + x; !c

(* Fonctions Récursives *)
(* EX1 *)

let rec char_range lo hi =
if lo > hi then
""
else
let next_char = char_succ lo in
string_cons lo (char_range next_char hi)



(* Lists *)
let swap lst = match lst with
| [] | [_] -> lst
| x :: y :: rest -> y :: x :: rest

let repeat s n =
if n < 0 then []
else List.init s(fun _ -> s)
17 changes: 9 additions & 8 deletions 02/lecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,29 +344,30 @@ Voici quelques exemples .
#### Calculer la longueur d'une liste
```ocaml
let rec longueur ll = match ll with
| [] -> failwith "todo"
| x :: xs -> failwith "todo"
| [] -> 0
| x :: xs -> 1 + longueur
```

#### Somme des éléments d'une liste
```ocaml
let rec sum ll = match ll with
| [] -> failwith "todo"
| head :: tail -> failwith "todo"
| [] -> 0
| x :: xs -> x + sum xs
```

#### Mettre des majuscules au début des mots
```ocaml
let rec capitalize ll = match ll with
| [] -> failwith "todo"
| _ :: _ -> failwith "todo" (* String.capitalize_ascii *)
| [] -> []
| x :: xs -> String.capitalize_ascii x :: capitalize xs
```

#### Rechercher un élément
```ocaml
let rec contient ll = match ll with
| [] ->
| _ :: _ -> failwith "todo"
| [] -> false
| x :: xs when x = a -> true
| _ :: xs -> contient xs a
```

## Fonctions d'ordre supérieur
Expand Down
53 changes: 53 additions & 0 deletions 02/task.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
(* EXO 02 *)


let swap lst = match lst with
| [] | [_] -> lst
| x :: y :: rest -> y :: x :: rest



(* EXO 3 *)

let repeat element n =
if n < 0 then []
else
List.init n (fun _ -> element)


(* EXO 4 *)
let repeat_i_j i j =
if j < i then []
else
List.init (j-i +1)(fun n -> i + n)

(* EXO 5 *)

let decr_list lst =
List.map (fun x -> x - 1) lst

(* EXO 6 *)
let rec rev lst =
let rec rev_acc acc = function
| [] -> acc
| hd :: tl -> rev_acc (hd :: acc) tl
in
rev_acc [] lst


let rev l =
let rec rev_aux acc rest =
match rest with
| [] -> acc
| t :: q -> rev_aux ( t :: acc)
in
rev_aux [] l

L'accumulateur, C'est un notion de PF,
Elle va avoir besoin de se rappeler de l'état intermediare
(* EXO 7 *)
let rec flat lst =
match lst with
| [] -> []
| hd :: tl -> hd @ flat tl

2 changes: 1 addition & 1 deletion 02/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ is_sorted [1; 3; 2]

### Question 13

Redéfinir `incr_list : int list -> int` en utilisant un itérateur.
Redéfinir `decr_list : int list -> int list` en utilisant un itérateur.

### Question 14

Expand Down
156 changes: 156 additions & 0 deletions 03/task.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
(* EXO 1 *)

type echec = Victoire | Nulle | Abondon

let echec_partie fin_partie = match fin_partie with
| Victoire -> 1.
| Nulle -> 0.5
| Abondon -> 0.


(* EXO 2 *)
type semaine = Samedi | Dimanche | Lundi | Mardi | Mercredi | Jeudi | Vendredi;;

let est_un_weekend jour = match jour with
| Samedi | Dimanche -> true
| _ -> false


(* EXO 3 *)

type etat = Metro | Boulot | Dodo | Vacances

let transition_etat etat =
match etat with
| Metro -> Boulot
| Boulot -> Dodo
| Dodo -> Metro
| Vacances -> Vacances

(* EXO 6 *)

type familles = Pique | Coeur | Carreaux | Trefle


type carte = As of familles
| Sept of familles
| Huit of familles
| Neuf of familles
| Dix of familles
| Valet of familles
| Dame of familles
| Roi of familles

type carte_a_jouer = { carte: carte; familles: familles}


(* EXO 7 *)

let est_une_tete c = match c with
| Valet _ | Dame _| Roi _-> true
| _ -> false


let est_rouge c = match c with
| Roi (Coeur | Carreaux)
| Huit (Coeur | Carreaux)
| Neuf (Coeur | Carreaux)
| Dix (Coeur | Carreaux)
| Dame (Coeur | Carreaux)
| Sept (Coeur | Carreaux)
| As (Coeur | Carreaux)
| Valet (Coeur | Carreaux) -> true
| _ -> false


let score_normal v = match v with
| As (Pique | Coeur | Carreaux | Trefle) -> 13
| Dix (Pique | Coeur | Carreaux | Trefle) -> 10
| Roi (Pique | Coeur | Carreaux | Trefle) -> 4
| Dame (Pique | Coeur | Carreaux | Trefle) -> 3
| Valet (Pique | Coeur | Carreaux | Trefle) -> 2
| Neuf (Pique | Coeur | Carreaux | Trefle) -> 0
| Huit (Pique | Coeur | Carreaux | Trefle)-> 0
| Sept (Pique | Coeur | Carreaux | Trefle) -> 0

let score_atout v = match v with
| As (Pique | Coeur | Carreaux | Trefle) -> 11
| Dix (Pique | Coeur | Carreaux | Trefle) -> 10
| Roi (Pique | Coeur | Carreaux | Trefle)-> 4
| Dame (Pique | Coeur | Carreaux | Trefle) -> 3
| Valet (Pique | Coeur | Carreaux | Trefle) -> 20
| Neuf (Pique | Coeur | Carreaux | Trefle)-> 14
| Huit (Pique | Coeur | Carreaux | Trefle)-> 0
| Sept (Pique | Coeur | Carreaux | Trefle) -> 0


let remporte_pli c1 c2 c3 c4 =
if est_rouge(c1) then true else false





(* Constructeurs avec données *)

type types = Entier of int | Flottant of float


let somme a b =
match (a, b) with
| (Entier x, Entier y) -> Entier(x + y)
| (Flottant x, Entier y) -> Flottant(x +. float_of_int(y))
| (Entier x, Flottant y) -> Flottant(float_of_int(x) +. y)
| (Flottant x, Flottant y) -> Flottant(x +. y)

let difference a b =
match (a, b) with
| (Entier x, Entier y) -> Entier (x - y)
| (Flottant x, Entier y) -> Flottant(x -. float_of_int(y))
| (Entier x, Flottant y) -> Flottant(float_of_int(x) -. y)
| (Flottant x, Flottant y) -> Flottant (x -. y)

let multiplication a b =
match (a, b) with
| (Entier x, Entier y) -> Entier (x * y)
| (Flottant x, Entier y) -> Flottant(x *. float_of_int(y))
| (Entier x, Flottant y) -> Flottant(float_of_int(x) *. y)
| (Flottant x, Flottant y) -> Flottant (x *. y)

let division a b =
match (a, b) with
| (Entier x, Entier y) -> if x mod y = 0 then Entier (x / y) else Flottant (float_of_int(x) /. float_of_int(y))
| (Flottant x, Entier y) -> Flottant(x /. float_of_int(y))
| (Entier x, Flottant y) -> Flottant(float_of_int(x) /. y)
| (Flottant x, Flottant y) -> Flottant (x /. y)


(* EXO 3 *)
type temperature = Celsius of float





(* Types enregistrements *)
(* EXO 1 *)
type point = {x : float; y : float}
type couleur = Pique | Coeur | Carreaux | Trefle
type force = A | K | Q | J | Neuf | Huit | Sept | Dix
type carte = {couleur:couleur; force:force}
type carte_ou_Joker = Joker | Carte
let est_une_tete c = match c with {couleur = _ ; force = K | Q | J} -> true | _ -> false

let compare_carte c1 c2 =
let int_of_force x = match x with
A -> 7
| K -> 6
| Q -> 5
| J -> 4
| Dix -> 3
| Neuf -> 2
| Huit -> 1
| Sept -> 0
in
if c1.couleur <> c2.couleur then (true: bool)
else int_of_force c1.force > int_of_force c2.force
Empty file modified dune
100644 → 100755
Empty file.