From 8bc7b2bf58c015c98c8abb93736ff7fe2211224f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20MARQUET?= Date: Wed, 18 Dec 2024 10:13:48 +0100 Subject: [PATCH] Initial commit --- .gitignore | 2 + TD/.Rhistory | 45 +++++++++++ TD/.Rproj.user/F9ECB55E/pcs/files-pane.pper | 9 +++ TD/.Rproj.user/F9ECB55E/pcs/source-pane.pper | 3 + .../F9ECB55E/pcs/windowlayoutstate.pper | 14 ++++ .../F9ECB55E/pcs/workbench-pane.pper | 5 ++ TD/.Rproj.user/F9ECB55E/rmd-outputs | 5 ++ TD/.Rproj.user/F9ECB55E/saved_source_markers | 1 + .../F9ECB55E/sources/per/t/B62E70DA | 26 ++++++ .../F9ECB55E/sources/per/t/B62E70DA-contents | 14 ++++ .../F9ECB55E/sources/per/t/C229FEB4 | 26 ++++++ .../F9ECB55E/sources/per/t/C229FEB4-contents | 4 + .../F9ECB55E/sources/per/t/DA0B538E | 26 ++++++ .../F9ECB55E/sources/per/t/DA0B538E-contents | 24 ++++++ TD/.Rproj.user/F9ECB55E/sources/prop/1489AED4 | 6 ++ TD/.Rproj.user/F9ECB55E/sources/prop/57E49702 | 6 ++ TD/.Rproj.user/F9ECB55E/sources/prop/74FBB217 | 6 ++ TD/.Rproj.user/F9ECB55E/sources/prop/INDEX | 3 + .../shared/notebooks/patch-chunk-names | 0 TD/Exo1.R | 24 ++++++ TD/Exo2.R | 4 + TD/Exo3.R | 39 +++++++++ TD/Exo4.R | 3 + TD/Exo5.R | 23 ++++++ TD/Exo6.R | 20 +++++ TD/Rplots.pdf | Bin 0 -> 4857 bytes TD/TD.Rproj | 13 +++ TD1/Exercice39.R | 17 ++++ TD1/Exercice51.R | 16 ++++ TD1/Exo1.R | 17 ++++ TD1/advent_of_code_06_12_2024.R | 75 ++++++++++++++++++ 31 files changed, 476 insertions(+) create mode 100644 .gitignore create mode 100644 TD/.Rhistory create mode 100644 TD/.Rproj.user/F9ECB55E/pcs/files-pane.pper create mode 100644 TD/.Rproj.user/F9ECB55E/pcs/source-pane.pper create mode 100644 TD/.Rproj.user/F9ECB55E/pcs/windowlayoutstate.pper create mode 100644 TD/.Rproj.user/F9ECB55E/pcs/workbench-pane.pper create mode 100644 TD/.Rproj.user/F9ECB55E/rmd-outputs create mode 100644 TD/.Rproj.user/F9ECB55E/saved_source_markers create mode 100644 TD/.Rproj.user/F9ECB55E/sources/per/t/B62E70DA create mode 100644 TD/.Rproj.user/F9ECB55E/sources/per/t/B62E70DA-contents create mode 100644 TD/.Rproj.user/F9ECB55E/sources/per/t/C229FEB4 create mode 100644 TD/.Rproj.user/F9ECB55E/sources/per/t/C229FEB4-contents create mode 100644 TD/.Rproj.user/F9ECB55E/sources/per/t/DA0B538E create mode 100644 TD/.Rproj.user/F9ECB55E/sources/per/t/DA0B538E-contents create mode 100644 TD/.Rproj.user/F9ECB55E/sources/prop/1489AED4 create mode 100644 TD/.Rproj.user/F9ECB55E/sources/prop/57E49702 create mode 100644 TD/.Rproj.user/F9ECB55E/sources/prop/74FBB217 create mode 100644 TD/.Rproj.user/F9ECB55E/sources/prop/INDEX create mode 100644 TD/.Rproj.user/shared/notebooks/patch-chunk-names create mode 100644 TD/Exo1.R create mode 100644 TD/Exo2.R create mode 100644 TD/Exo3.R create mode 100644 TD/Exo4.R create mode 100644 TD/Exo5.R create mode 100644 TD/Exo6.R create mode 100644 TD/Rplots.pdf create mode 100644 TD/TD.Rproj create mode 100644 TD1/Exercice39.R create mode 100644 TD1/Exercice51.R create mode 100644 TD1/Exo1.R create mode 100644 TD1/advent_of_code_06_12_2024.R diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7224328 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea +.idea/ \ No newline at end of file diff --git a/TD/.Rhistory b/TD/.Rhistory new file mode 100644 index 0000000..115b06b --- /dev/null +++ b/TD/.Rhistory @@ -0,0 +1,45 @@ +print("Hello World") +x+2 +print(x+2) +x+2 +(5^2+5)/3 +sum(log(32,2), 8^4, 4+5, 12/3) +sum(50, 3, 5) +log10(90+5*2) +variable2 +variable2 + 2 +mean(variable2) +variable2 <- c(12, 1, 15, 3, 20, 6, 11) +variable2 +mean(variable2) +variable2 + 2 +variable2 <- c(12, 1, 15, 3, 20, 6, 11) +variable2 +mean(variable2) +variable2 + 2 +x = c(1, 3, 5, 7, 9) +y = c(2, 3, 5, 7, 11, 13) +z = c(9, 3, 2, 5, 9, 2, 3, 9, 1) +x + 2 +y * 3 +length(x) +x + y +sum(x > 5) +sum(x[x > 5]) +sum(x > 5 | x < 3) +y[3] +y[-3] +y[x] +(y > 7) +y[y > 7] +sort(z) +sort(z, dec = TRUE) +rev(z) +order(z) +unique(z) +duplicated(z) +table(z) +rep(z, 3) +vector1 <- c(1, 2, 3) +vector2 <- c(4, 5, 6) +vector3 <- c(vector1[1:2], vector2, vector1[3:length(vector1)]) diff --git a/TD/.Rproj.user/F9ECB55E/pcs/files-pane.pper b/TD/.Rproj.user/F9ECB55E/pcs/files-pane.pper new file mode 100644 index 0000000..7d5ef91 --- /dev/null +++ b/TD/.Rproj.user/F9ECB55E/pcs/files-pane.pper @@ -0,0 +1,9 @@ +{ + "sortOrder": [ + { + "columnIndex": 2, + "ascending": true + } + ], + "path": "C:/Users/BreizhHardware/Nextcloud/Programation/R/TD" +} \ No newline at end of file diff --git a/TD/.Rproj.user/F9ECB55E/pcs/source-pane.pper b/TD/.Rproj.user/F9ECB55E/pcs/source-pane.pper new file mode 100644 index 0000000..ddca97d --- /dev/null +++ b/TD/.Rproj.user/F9ECB55E/pcs/source-pane.pper @@ -0,0 +1,3 @@ +{ + "activeTab": 2 +} \ No newline at end of file diff --git a/TD/.Rproj.user/F9ECB55E/pcs/windowlayoutstate.pper b/TD/.Rproj.user/F9ECB55E/pcs/windowlayoutstate.pper new file mode 100644 index 0000000..de81620 --- /dev/null +++ b/TD/.Rproj.user/F9ECB55E/pcs/windowlayoutstate.pper @@ -0,0 +1,14 @@ +{ + "left": { + "splitterpos": 393, + "topwindowstate": "NORMAL", + "panelheight": 945, + "windowheight": 983 + }, + "right": { + "splitterpos": 589, + "topwindowstate": "NORMAL", + "panelheight": 945, + "windowheight": 983 + } +} \ No newline at end of file diff --git a/TD/.Rproj.user/F9ECB55E/pcs/workbench-pane.pper b/TD/.Rproj.user/F9ECB55E/pcs/workbench-pane.pper new file mode 100644 index 0000000..75e70e9 --- /dev/null +++ b/TD/.Rproj.user/F9ECB55E/pcs/workbench-pane.pper @@ -0,0 +1,5 @@ +{ + "TabSet1": 0, + "TabSet2": 0, + "TabZoom": {} +} \ No newline at end of file diff --git a/TD/.Rproj.user/F9ECB55E/rmd-outputs b/TD/.Rproj.user/F9ECB55E/rmd-outputs new file mode 100644 index 0000000..3f2ff2d --- /dev/null +++ b/TD/.Rproj.user/F9ECB55E/rmd-outputs @@ -0,0 +1,5 @@ + + + + + diff --git a/TD/.Rproj.user/F9ECB55E/saved_source_markers b/TD/.Rproj.user/F9ECB55E/saved_source_markers new file mode 100644 index 0000000..2b1bef1 --- /dev/null +++ b/TD/.Rproj.user/F9ECB55E/saved_source_markers @@ -0,0 +1 @@ +{"active_set":"","sets":[]} \ No newline at end of file diff --git a/TD/.Rproj.user/F9ECB55E/sources/per/t/B62E70DA b/TD/.Rproj.user/F9ECB55E/sources/per/t/B62E70DA new file mode 100644 index 0000000..eef4266 --- /dev/null +++ b/TD/.Rproj.user/F9ECB55E/sources/per/t/B62E70DA @@ -0,0 +1,26 @@ +{ + "id": "B62E70DA", + "path": "C:/Users/BreizhHardware/Nextcloud/Programation/R/TD/Exo3.R", + "project_path": "Exo3.R", + "type": "r_source", + "hash": "340809373", + "contents": "", + "dirty": false, + "created": 1733479137294.0, + "source_on_save": false, + "relative_order": 3, + "properties": { + "source_window_id": "", + "Source": "Source", + "cursorPosition": "0,0", + "scrollLine": "0" + }, + "folds": "", + "lastKnownWriteTime": 1733479598, + "encoding": "UTF-8", + "collab_server": "", + "source_window": "", + "last_content_update": 1733479598, + "read_only": false, + "read_only_alternatives": [] +} \ No newline at end of file diff --git a/TD/.Rproj.user/F9ECB55E/sources/per/t/B62E70DA-contents b/TD/.Rproj.user/F9ECB55E/sources/per/t/B62E70DA-contents new file mode 100644 index 0000000..392f752 --- /dev/null +++ b/TD/.Rproj.user/F9ECB55E/sources/per/t/B62E70DA-contents @@ -0,0 +1,14 @@ +# Crée des vecteurs +# y0 constitué de la suite des entiers de 0 à 10 par pas de 2 +y0 <- seq(0, 10, by=2) +# y1 constitué de tous les entiers pairs entre 1 et 18 +y1 <- seq(2, 18, by=2) +# y2 constitué de 20 fois de suite la valeur 4 +y2 <- rep(4, 20) +# y3 constitué de 20 nombres entre 0 et 10 +y3 <- runif(20, 0, 10) + +# Extraire de y3 +# le troisième élément +y33 <- y3[2] +# tous les éléments sauf le troisième diff --git a/TD/.Rproj.user/F9ECB55E/sources/per/t/C229FEB4 b/TD/.Rproj.user/F9ECB55E/sources/per/t/C229FEB4 new file mode 100644 index 0000000..7ba97ca --- /dev/null +++ b/TD/.Rproj.user/F9ECB55E/sources/per/t/C229FEB4 @@ -0,0 +1,26 @@ +{ + "id": "C229FEB4", + "path": "C:/Users/BreizhHardware/Nextcloud/Programation/R/TD/Exo2.R", + "project_path": "Exo2.R", + "type": "r_source", + "hash": "3327678100", + "contents": "", + "dirty": false, + "created": 1733478990873.0, + "source_on_save": false, + "relative_order": 2, + "properties": { + "source_window_id": "", + "Source": "Source", + "cursorPosition": "3,63", + "scrollLine": "0" + }, + "folds": "", + "lastKnownWriteTime": 1733479100, + "encoding": "UTF-8", + "collab_server": "", + "source_window": "", + "last_content_update": 1733479100521, + "read_only": false, + "read_only_alternatives": [] +} \ No newline at end of file diff --git a/TD/.Rproj.user/F9ECB55E/sources/per/t/C229FEB4-contents b/TD/.Rproj.user/F9ECB55E/sources/per/t/C229FEB4-contents new file mode 100644 index 0000000..494704d --- /dev/null +++ b/TD/.Rproj.user/F9ECB55E/sources/per/t/C229FEB4-contents @@ -0,0 +1,4 @@ +vector1 <- c(1, 2, 3) +vector2 <- c(4, 5, 6) + +vector3 <- c(vector1[1:2], vector2, vector1[3:length(vector1)]) \ No newline at end of file diff --git a/TD/.Rproj.user/F9ECB55E/sources/per/t/DA0B538E b/TD/.Rproj.user/F9ECB55E/sources/per/t/DA0B538E new file mode 100644 index 0000000..16dc965 --- /dev/null +++ b/TD/.Rproj.user/F9ECB55E/sources/per/t/DA0B538E @@ -0,0 +1,26 @@ +{ + "id": "DA0B538E", + "path": "C:/Users/BreizhHardware/Nextcloud/Programation/R/TD/Exo1.R", + "project_path": "Exo1.R", + "type": "r_source", + "hash": "1460566234", + "contents": "", + "dirty": false, + "created": 1733478588935.0, + "source_on_save": false, + "relative_order": 1, + "properties": { + "source_window_id": "", + "Source": "Source", + "cursorPosition": "19,8", + "scrollLine": "0" + }, + "folds": "", + "lastKnownWriteTime": 1733478955, + "encoding": "UTF-8", + "collab_server": "", + "source_window": "", + "last_content_update": 1733478955036, + "read_only": false, + "read_only_alternatives": [] +} \ No newline at end of file diff --git a/TD/.Rproj.user/F9ECB55E/sources/per/t/DA0B538E-contents b/TD/.Rproj.user/F9ECB55E/sources/per/t/DA0B538E-contents new file mode 100644 index 0000000..4495958 --- /dev/null +++ b/TD/.Rproj.user/F9ECB55E/sources/per/t/DA0B538E-contents @@ -0,0 +1,24 @@ +x = c(1, 3, 5, 7, 9) +y = c(2, 3, 5, 7, 11, 13) +z = c(9, 3, 2, 5, 9, 2, 3, 9, 1) + +x + 2 +y * 3 +length(x) +x + y +sum(x > 5) +sum(x[x > 5]) +sum(x > 5 | x < 3) +y[3] +y[-3] +y[x] +(y > 7) +y[y > 7] +sort(z) +sort(z, dec = TRUE) +rev(z) +order(z) +unique(z) +duplicated(z) +table(z) +rep(z, 3) \ No newline at end of file diff --git a/TD/.Rproj.user/F9ECB55E/sources/prop/1489AED4 b/TD/.Rproj.user/F9ECB55E/sources/prop/1489AED4 new file mode 100644 index 0000000..421141e --- /dev/null +++ b/TD/.Rproj.user/F9ECB55E/sources/prop/1489AED4 @@ -0,0 +1,6 @@ +{ + "source_window_id": "", + "Source": "Source", + "cursorPosition": "0,0", + "scrollLine": "0" +} \ No newline at end of file diff --git a/TD/.Rproj.user/F9ECB55E/sources/prop/57E49702 b/TD/.Rproj.user/F9ECB55E/sources/prop/57E49702 new file mode 100644 index 0000000..d136f0a --- /dev/null +++ b/TD/.Rproj.user/F9ECB55E/sources/prop/57E49702 @@ -0,0 +1,6 @@ +{ + "source_window_id": "", + "Source": "Source", + "cursorPosition": "3,63", + "scrollLine": "0" +} \ No newline at end of file diff --git a/TD/.Rproj.user/F9ECB55E/sources/prop/74FBB217 b/TD/.Rproj.user/F9ECB55E/sources/prop/74FBB217 new file mode 100644 index 0000000..895734f --- /dev/null +++ b/TD/.Rproj.user/F9ECB55E/sources/prop/74FBB217 @@ -0,0 +1,6 @@ +{ + "source_window_id": "", + "Source": "Source", + "cursorPosition": "19,8", + "scrollLine": "0" +} \ No newline at end of file diff --git a/TD/.Rproj.user/F9ECB55E/sources/prop/INDEX b/TD/.Rproj.user/F9ECB55E/sources/prop/INDEX new file mode 100644 index 0000000..0603ee1 --- /dev/null +++ b/TD/.Rproj.user/F9ECB55E/sources/prop/INDEX @@ -0,0 +1,3 @@ +C%3A%2FUsers%2FBreizhHardware%2FNextcloud%2FProgramation%2FR%2FTD%2FExo1.R="74FBB217" +C%3A%2FUsers%2FBreizhHardware%2FNextcloud%2FProgramation%2FR%2FTD%2FExo2.R="57E49702" +C%3A%2FUsers%2FBreizhHardware%2FNextcloud%2FProgramation%2FR%2FTD%2FExo3.R="1489AED4" diff --git a/TD/.Rproj.user/shared/notebooks/patch-chunk-names b/TD/.Rproj.user/shared/notebooks/patch-chunk-names new file mode 100644 index 0000000..e69de29 diff --git a/TD/Exo1.R b/TD/Exo1.R new file mode 100644 index 0000000..4495958 --- /dev/null +++ b/TD/Exo1.R @@ -0,0 +1,24 @@ +x = c(1, 3, 5, 7, 9) +y = c(2, 3, 5, 7, 11, 13) +z = c(9, 3, 2, 5, 9, 2, 3, 9, 1) + +x + 2 +y * 3 +length(x) +x + y +sum(x > 5) +sum(x[x > 5]) +sum(x > 5 | x < 3) +y[3] +y[-3] +y[x] +(y > 7) +y[y > 7] +sort(z) +sort(z, dec = TRUE) +rev(z) +order(z) +unique(z) +duplicated(z) +table(z) +rep(z, 3) \ No newline at end of file diff --git a/TD/Exo2.R b/TD/Exo2.R new file mode 100644 index 0000000..494704d --- /dev/null +++ b/TD/Exo2.R @@ -0,0 +1,4 @@ +vector1 <- c(1, 2, 3) +vector2 <- c(4, 5, 6) + +vector3 <- c(vector1[1:2], vector2, vector1[3:length(vector1)]) \ No newline at end of file diff --git a/TD/Exo3.R b/TD/Exo3.R new file mode 100644 index 0000000..533e249 --- /dev/null +++ b/TD/Exo3.R @@ -0,0 +1,39 @@ +# Crée des vecteurs +# y0 constitué de la suite des entiers de 0 à 10 par pas de 2 +y0 <- seq(0, 10, by=2) +# y1 constitué de tous les entiers pairs entre 1 et 18 +y1 <- seq(2, 18, by=2) +# y2 constitué de 20 fois de suite la valeur 4 +y2 <- rep(4, 20) +# y3 constitué de 20 nombres entre 0 et 10 +y3 <- runif(20, 0, 10) + +# Extraire de y3 +# le troisième élément +y33 <- y3[3] +# tous les éléments sauf le troisième +y34 <- y3[-3] + +# Comparer les commandes suivantes +matrix(y3, nrow = 2) +matrix(y3, byrow = TRUE) + +# Construire une matrice A comportant quatre lignes et trois colonnes remplies par lignes +# successives avec les éléments du vecteur 1:12 +A <- matrix(1:12, nrow = 4, byrow = TRUE) + +# Construire une matrice B comportant quatre lignes et trois colonnes remplies par +# colonnes successives avec les éléments du vecteur 1:12 +B <- matrix(1:12, nrow = 4, byrow = FALSE) + +# Extraire l’élément situé en deuxième ligne et troisième colonne de A +A[2, 3] + +# Extraire la première colonne de A, puis la deuxième ligne de A. +A[, 1] +A[2, ] + +# Construire une matrice C constituée des lignes 1 et 4 de A. +C <- A[c(1, 4), ] +print(A) +print(C) \ No newline at end of file diff --git a/TD/Exo4.R b/TD/Exo4.R new file mode 100644 index 0000000..2df4ce3 --- /dev/null +++ b/TD/Exo4.R @@ -0,0 +1,3 @@ +# Construire une matrice comportant 9 lignes et 9 colonnes avec des 0 sur la diagonale et des 1 +# partout ailleurs (on pourra utiliser la commande diag) +D <- matrix(1, nrow = 9, ncol = 9) \ No newline at end of file diff --git a/TD/Exo5.R b/TD/Exo5.R new file mode 100644 index 0000000..afaabc5 --- /dev/null +++ b/TD/Exo5.R @@ -0,0 +1,23 @@ +# Créer un vecteur x = (x1, . . . , x11) contenant les réels compris entre 0 et 1 par pas de 0.1 +x <- seq(0, 1, by=0.1) + +# Afficher la longueur de x +print(length(x)) + +# En utilisant les opérations vectorielles, créer un vecteur y = 4x(1 − x) +y <- 4*x*(1-x) + +# Tracer la courbe rejoignant les points (x1, y1), . . . , (x11, y11) avec la commande plot +plot(x, y) + +# Calculer le maximum des y1, . . . , y11 +print(max(y)) + +# En quel point le maximum est-il atteint ? +print(x[which.max(y)]) + +# Tracer la courbe de la fonction f (x) = 4x2(1 − x), x +# ∈ [−2, 1], en rouge +x <- seq(-2, 1, by=0.1) +y <- 4*x^2*(1-x) +plot(x, y, col="red") \ No newline at end of file diff --git a/TD/Exo6.R b/TD/Exo6.R new file mode 100644 index 0000000..e734fa3 --- /dev/null +++ b/TD/Exo6.R @@ -0,0 +1,20 @@ +# Utiliser R pour donner les valeurs numériques attendues : +# Combien y-a-t-il de carrés (4 cartes de même valeur) dans un jeu de 32 cartes ? +nb_carres <- 8 +nb_carres + +# Combien d’anagrammes peut-on faire avec le mot "dinosaure" ? +anagrammes <- factorial(9) / factorial(2) +anagrammes + +# Combien de chances a-t-on de gagner le super jackpot à l’euromillion ? (donc d’avoir 5 +# bons numéros parmi 49, et 2 bons numéros étoilés parmi 10) +chances <- choose(49, 5) * choose(10, 2) +chances + +# Chaque pièce d’un nouveau jeu de domino est de la forme : a b avec (a, b) ∈ {0, . . . , 9}2 +# en sachant qu’un domino reste le même si on le tourne à 180 degrés (par exemple, 8 = 8 +# est un, et un seul domino). Déterminer le nombre de pièces différentes que contient un +# jeu complet de dominos +nb_dominos <- choose(10, 2) + 10 +nb_dominos \ No newline at end of file diff --git a/TD/Rplots.pdf b/TD/Rplots.pdf new file mode 100644 index 0000000000000000000000000000000000000000..e91b9a160982c60422801d47607de41461fb55bc GIT binary patch literal 4857 zcmZ{oc{tSV_s2z)>B+t{5kuCBS&XrSFk|1B>|`2)$(R{tWF33RmaUYm*(#4@%dQQP zWo(hMQ$(Q5 zhMar>P!I$}JbwY8rUn2beX(c?jz~bEDOivUN)-ly!J#k+0t$sHD$dF_K8X5pB!Htmx z>~}UGuyr5_3j!n26f~ab0Ro$&J+Neu0^Pt8^j`<1e>pJh7}ma60_CSU7)c~h=u0w4 z`G-5$5=$of`C{nj!T)g{!{AprjIjg{iYEvPQHFxRx;Q+A{sv%OJiRz5EQaWYW#mn! z&}-%m2*@tB=}LB1!!zS>VI+TieqrMj<`^2?H| z7DuHt3v7+g(@MO5dH^-ud!u)umyS zQ*TXdf8BSD=5PCo%j+K|=Y{z^-U~u)v3<`?)@NJUeX6qYB67L6bb95G|G6fwt}BZ> zYsc%^L?T0{I`3^ynv8~I3x9DB!%Nq13na0$8i#%Dy;yZ^QG#s-|8XMuKuzKiwMJv; zVAr_6!6(V%@fv!lF(u865Y89^{;1sI^KxmB5ZQF0Mp}0rsPbB^3D^hd zf5mZ&Ij4D{KjdDOU^-0YR(5MJw-nM*oe%Wrvcogk~eDC<@*(Y1B<4mpc zQ;{znMr~T!CC9DC8#7(Tg3C0PT#N@p+J_$Pzr0w1rYv$=m9in5Cm%%tt&Z!0RL*mQfu!=- zSm>sTIgijN*RH!)I^UV+^Olw1smQjvKfQyJj2eRJv9rd4lWpd#p0KB!Fn_1@c3!{M z5`AKJ^Fratyd5ojwTAdxFPaQ^q_6n!mL_}=kQk|Y@J>>GZpEkD#aI75b)q|CZR~Bz zoo^fCvVOboTzqe9Boz~D-p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V(%`{erMaraa}*w91= zzKmE}mnp&=D-kOac60l~=2NZM;4Al&Yp5RE&fW)V3yXM{oF-LXTpg7Bki0CSaWtT& z?pbl^TyXd5mgtbW4cX~Uz!>|J%eQ#*OyA~ZYh3kPdiQRA2-9K|w3>Zcom>uXCa&T8 z$JQ4@XgTk;-k%Aa-27U3s82B2#m)JB<2>mO`B7;8+<{$DRkmYnr(=a<8^NcYSAe-n zA+zzjSBGp{Dsr0yNFN3}zoyPCTZ|GX_3Oo2x|+T$+U%4s)R76aaeJ~LwQfFluqA#s zYfC5;zE|nI1X9;nQdeDbeH?WfGhQiu2K#*@w0TkN3%WhJ54C>$wcax+sxUH9izXjrXWJ$dGO=;D_n8y{Cn6V38MS+=6rcmLIDtNd<50Y8TgIt2Q? z9!H>08yIcte^<6Rf);^{`y~LtD4e@HmOf!%j1U|_a7C~;j^IZIIsa{x@uQLc)#d&* z%lOe|gRT6|Q+|v#7$UuYH${8Xn_qhC{UhjKHu_lnMJxq}LDReNUpX<-{rl)6z!&Qd zfPkP-0Oa=rLMSRKD1zKUzcm0SFjG({MF8uAYf0jJ*& z{;4Vb>pTbyN+0F?uN?%Y@-GdpfcRGoI2`deJBlwFhsXNT=TjiC6)p%%e_s&TfZ$G~ lUws($09z7?6cA%>^rJRp3fhh;`;6KU~ij)8V literal 0 HcmV?d00001 diff --git a/TD/TD.Rproj b/TD/TD.Rproj new file mode 100644 index 0000000..8e3c2eb --- /dev/null +++ b/TD/TD.Rproj @@ -0,0 +1,13 @@ +Version: 1.0 + +RestoreWorkspace: Default +SaveWorkspace: Default +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX diff --git a/TD1/Exercice39.R b/TD1/Exercice39.R new file mode 100644 index 0000000..d301fa0 --- /dev/null +++ b/TD1/Exercice39.R @@ -0,0 +1,17 @@ +# Question a +# Ici on cherche P(X <= 30) via une loi binomial avec 70 et 0.4 +sum(dbinom(x=0:30,size=70,prob=0.4)) + +# Question b +# Ici on cherche P(X) >= 0.9 via la même loi binomial qu'avant +i <- 0 +j <- 30 +while (i < 0.9) { + i <- sum(dbinom(x=0:j, size=70, prob=0.4)) + j <- j + 1 +} +print(i) +print(j - 1) + +# Bonus +print(dbinom(x=0:70, size=70, prob=0.4)) diff --git a/TD1/Exercice51.R b/TD1/Exercice51.R new file mode 100644 index 0000000..32ef563 --- /dev/null +++ b/TD1/Exercice51.R @@ -0,0 +1,16 @@ +# Dans une station-service, la demande hebdomadaire en essence, en milliers de litres, est +# une variable aléatoire X de densité f (x) = c(1 − x)^4 1[0,1]. +# a) Déterminer c +f <- function(x) {(1-x)^4} +result <- integrate(f, lower = 0, upper = 1) +# Je détermine C car intérale de c*f(x) = 1 +c <- 1 / result$value +print(c) +# b) La station est réapprovisionnée chaque lundi à 20h. Quelle doit être la capacité du réservoir +# d’essence pour que la probabilité d’épuiser ce réservoir soit inférieure à 10^−5 ? +F <- function(x) { + integrate(function(t) c * (1 - t)^4, lower = 0, upper = x)$value +} +cible <- 1 - 10^(-5) +capacite <- uniroot(function(x) F(x) - cible, lower = 0, upper = 1)$root +print(capacite * 1000) diff --git a/TD1/Exo1.R b/TD1/Exo1.R new file mode 100644 index 0000000..8f851d3 --- /dev/null +++ b/TD1/Exo1.R @@ -0,0 +1,17 @@ +# Une course oppose 20 concurrents, dont Émile +# a) Combien y-a-t-il de podiums possibles ? +podiums_total <- factorial(20) / factorial(20 - 3) +podiums_total + +# b) Combien y-a-t-il de podiums possibles où Émile est premier ? +emile_premier <- 1 * (factorial(19) / factorial(17)) +emile_premier + +# c) Combien y-a-t-il de podiums possibles dont Émile fait partie ? +emile_podium <- 3 * (factorial(19) / factorial(17)) +emile_podium + +# d) On souhaite récompenser les 3 premiers en leur offrant un prix identique à chacun. Combien +# y-a-t-il de distributions de récompenses possibles ? +distributions <- choose(20, 3) +distributions \ No newline at end of file diff --git a/TD1/advent_of_code_06_12_2024.R b/TD1/advent_of_code_06_12_2024.R new file mode 100644 index 0000000..9266927 --- /dev/null +++ b/TD1/advent_of_code_06_12_2024.R @@ -0,0 +1,75 @@ +simulate_guard <- function(input) { + # Transform the input into a matrix + rows <- unlist(strsplit(input, "\n")) + grid <- do.call(rbind, lapply(rows, function(row) unlist(strsplit(row, NULL)))) + + # Find the starting position and initial direction + start_pos <- which(grid %in% c("^", ">", "v", "<"), arr.ind = TRUE) + if (length(start_pos) == 0) { + stop("No starting position found in the input grid.") + } + if (is.vector(start_pos)) { + start_pos <- matrix(start_pos, nrow = 1) + } + directions <- list("^" = c(-1, 0), ">" = c(0, 1), "v" = c(1, 0), "<" = c(0, -1)) + turns <- c("^" = ">", ">" = "v", "v" = "<", "<" = "^") + + direction <- grid[start_pos[1, 1], start_pos[1, 2]] + visited <- list() # List of visited positions + + # Initialize the position + x <- start_pos[1, 1] + print(x) + y <- start_pos[1, 2] + + # Function to check the bounds of the grid + in_bounds <- function(x, y, grid) { + x > 0 && x <= nrow(grid) && y > 0 && y <= ncol(grid) + } + + # Mark the initial position as visited + visited[[paste(x, y, sep = ",")]] <- TRUE + + # Simulate the movement + repeat { + # Calculate the next position in the current direction + dx <- directions[[direction]][1] + dy <- directions[[direction]][2] + nx <- x + dx + ny <- y + dy + + # If out of bounds or obstacle ahead, turn right + if (!in_bounds(nx, ny, grid) || grid[nx, ny] == "#") { + direction <- turns[direction] + } else { + # Move forward + x <- nx + y <- ny + + # Mark the new position as visited + visited[[paste(x, y, sep = ",")]] <- TRUE + + # If out of bounds, stop the simulation + if (!in_bounds(x, y, grid)) break + } + } + + # Return the number of distinct positions visited + length(visited) +} + +# Input as a single string (provided) +input <- "....#..... +.........# +.......... +..#....... +.......#.. +.......... +.#..^..... +........#. +#......... +......#..." + +# Call the function +distinct_positions <- simulate_guard(input) +cat("Distinct positions visited:", distinct_positions, "\n") \ No newline at end of file