aboutsummaryrefslogtreecommitdiff
path: root/semestre 2/informatique/tme/semaine2
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <anhgelus@anhgelus.world>2025-01-31 15:39:30 +0100
committerAnhgelus Morhtuuzh <anhgelus@anhgelus.world>2025-01-31 15:39:30 +0100
commitd7c69934248f3fab4988c0d37c11feba25d653b8 (patch)
tree6c396257cb21374e13a26b8f78c05353806220bc /semestre 2/informatique/tme/semaine2
parented631f52ee7af474625e37c6855c7c55903317fc (diff)
Ajout du début du deuxième semestre
Diffstat (limited to 'semestre 2/informatique/tme/semaine2')
-rw-r--r--semestre 2/informatique/tme/semaine2/09_lib_graphique.c15
-rw-r--r--semestre 2/informatique/tme/semaine2/10_carre.c28
-rw-r--r--semestre 2/informatique/tme/semaine2/11_propagation_epidemie.c41
-rw-r--r--semestre 2/informatique/tme/semaine2/12_droite_points.c34
-rw-r--r--semestre 2/informatique/tme/semaine2/14_tour_londres.c51
5 files changed, 169 insertions, 0 deletions
diff --git a/semestre 2/informatique/tme/semaine2/09_lib_graphique.c b/semestre 2/informatique/tme/semaine2/09_lib_graphique.c
new file mode 100644
index 0000000..d90845e
--- /dev/null
+++ b/semestre 2/informatique/tme/semaine2/09_lib_graphique.c
@@ -0,0 +1,15 @@
+#include <cini.h>
+
+void diagonale(int x){
+ for (int i = 0; i <= x; i++) {
+ CINI_draw_pixel(i, i, "orange");
+ }
+}
+
+int main(){
+ CINI_open_window(400, 300, "hello world");
+ diagonale(200);
+ CINI_loop();
+
+ return 0;
+}
diff --git a/semestre 2/informatique/tme/semaine2/10_carre.c b/semestre 2/informatique/tme/semaine2/10_carre.c
new file mode 100644
index 0000000..45029bb
--- /dev/null
+++ b/semestre 2/informatique/tme/semaine2/10_carre.c
@@ -0,0 +1,28 @@
+#include <cini.h>
+
+void carre(int c, int x, int y){
+ for (int i = 0; i<c;i++){
+ CINI_draw_pixel(x+i, y, "blue");
+ CINI_draw_pixel(x+i, y+c, "green");
+ CINI_draw_pixel(x, y+i, "red");
+ CINI_draw_pixel(x+c, y+i, "black");
+ }
+}
+
+void carres_remontant(int c, int x, int y){
+ int nx = x, ny = y;
+ while (nx >= 0 && ny >= 0){
+ carre(c, nx, ny);
+ nx -= 20;
+ ny -= 20;
+ }
+}
+
+int main() {
+ CINI_open_window(400, 400, "Carre");
+ CINI_fill_window("white");
+ carres_remontant(100, 50, 100);
+ CINI_loop();
+
+ return 0;
+}
diff --git a/semestre 2/informatique/tme/semaine2/11_propagation_epidemie.c b/semestre 2/informatique/tme/semaine2/11_propagation_epidemie.c
new file mode 100644
index 0000000..26b763e
--- /dev/null
+++ b/semestre 2/informatique/tme/semaine2/11_propagation_epidemie.c
@@ -0,0 +1,41 @@
+#include <assert.h>
+#include <stdio.h>
+
+int jours(int infected, int pop, float percentage){
+ int n = 1, c = 0;
+ while (n / (float) pop < percentage/100){
+ n += infected * n;
+ c++;
+ }
+ return c;
+}
+
+float pourcentage(int infected, int pop, int day){
+ int n = 1, c = 0;
+ while (c < day && n <= pop){
+ n += infected*n;
+ c++;
+ }
+ if (n >= pop) return 100;
+ return 100*n/ (float) pop;
+}
+
+int eps_pres(float a, float b, float eps){
+ float v = a - b;
+ if (v < 0) v = -v;
+ return v < eps;
+}
+
+int main(){
+ assert(jours(5, 10000, 100) == 6);
+ assert(jours(5, 10000, 50) == 5);
+ assert(jours(5, 10000, 25) == 5);
+ assert(jours(5, 10000, 10) == 4);
+
+ assert(eps_pres(pourcentage(5, 10000, 2), 0.36, 0.001));
+ assert(eps_pres(pourcentage(5, 10000, 3), 2.16, 0.001));
+ assert(eps_pres(pourcentage(5, 10000, 4), 12.96, 0.001));
+ assert(eps_pres(pourcentage(5, 10000, 5), 77.76, 0.001));
+ assert(eps_pres(pourcentage(5, 10000, 6), 100.00, 0.001));
+ return 0;
+}
diff --git a/semestre 2/informatique/tme/semaine2/12_droite_points.c b/semestre 2/informatique/tme/semaine2/12_droite_points.c
new file mode 100644
index 0000000..a202e24
--- /dev/null
+++ b/semestre 2/informatique/tme/semaine2/12_droite_points.c
@@ -0,0 +1,34 @@
+#include <cini.h>
+#define WIDTH 400
+#define HEIGHT 400
+
+int position(int a, int b, int x, int y){
+ // t(z) = az+b
+ // y(x) = alpha x + beta
+ int straight_line_y = a*x+b;
+ if (straight_line_y > y) return 1;
+ if (straight_line_y < y) return -1;
+ return 0;
+}
+
+void affiche(int a, int b, int width, int height){
+ for (int x = 0; x < width; x++){
+ for (int y = 0; y < height; y++){
+ int pos = position(a, b, x, y);
+ char* color;
+ if (pos == 1) color = "red";
+ else if (pos == -1) color = "blue";
+ else color = "black";
+ CINI_draw_pixel(x, y, color);
+ }
+ }
+}
+
+int main(){
+ CINI_open_window(WIDTH, HEIGHT, "Hello");
+ CINI_fill_window("white");
+ affiche(1, 0, WIDTH, HEIGHT);
+ CINI_loop();
+ return 0;
+}
+
diff --git a/semestre 2/informatique/tme/semaine2/14_tour_londres.c b/semestre 2/informatique/tme/semaine2/14_tour_londres.c
new file mode 100644
index 0000000..1c86e65
--- /dev/null
+++ b/semestre 2/informatique/tme/semaine2/14_tour_londres.c
@@ -0,0 +1,51 @@
+#include <assert.h>
+#define ADU 22.7
+#define KID 10.75
+#define FAMILLY 57.8
+#define MAX_ADU_FAMILLY 2
+#define MAX_KID_FAMILLY 3
+#define COMPARE_FLOAT_PRECISION 0.00001
+
+float prixEntree(int adus, int kids){
+ int max_familly = 0;
+ int r_adus = adus;
+ int r_kids = kids;
+ do {
+ r_adus -= MAX_ADU_FAMILLY;
+ r_kids -= MAX_KID_FAMILLY;
+ max_familly++;
+ } while (r_adus > 0 || r_kids > 0);
+ float min = -1;
+ for (int f = 0; f <= max_familly; f++){
+ int r_adus = adus - MAX_ADU_FAMILLY*f;
+ int r_kids = kids - MAX_KID_FAMILLY*f;
+ float t = f*FAMILLY;
+ if (r_adus > 0) t += r_adus * ADU;
+ if (r_kids > 0) t += r_kids * KID;
+ if (min == -1 || t < min) {
+ min = t;
+ }
+ }
+ return min;
+}
+
+int compareFloat(float f1, float f2, float eps){
+ /* Prend trois floats (f1, f2 et eps) et renvoie |f1-f2|<eps ; est une comparaison de deux
+ * floats à epsilon près */
+ float diff = f1 - f2;
+ if (diff < 0) diff = - diff;
+ return diff < eps;
+}
+
+int main(){
+ assert(compareFloat(prixEntree(2, 3), FAMILLY, COMPARE_FLOAT_PRECISION));
+ assert(compareFloat(prixEntree(2, 2), FAMILLY, COMPARE_FLOAT_PRECISION));
+ assert(compareFloat(prixEntree(2, 1), 2*ADU + KID, COMPARE_FLOAT_PRECISION));
+ assert(compareFloat(prixEntree(6, 3), 4*ADU + FAMILLY, COMPARE_FLOAT_PRECISION));
+ assert(compareFloat(prixEntree(1, 3), 1*ADU + 3*KID, COMPARE_FLOAT_PRECISION));
+ assert(compareFloat(prixEntree(5, 7), 2*FAMILLY + ADU + KID, COMPARE_FLOAT_PRECISION));
+ assert(compareFloat(prixEntree(6, 8), 3*FAMILLY, COMPARE_FLOAT_PRECISION));
+ assert(compareFloat(prixEntree(10, 0), 227, COMPARE_FLOAT_PRECISION));
+ assert(compareFloat(prixEntree(0, 4), 43, COMPARE_FLOAT_PRECISION));
+ return 0;
+}