From 8a8af365709122fa63c7e50c746ecba7580dbea3 Mon Sep 17 00:00:00 2001
From: rick <rick@gnous.eu>
Date: Fri, 26 Mar 2021 16:53:45 +0100
Subject: [PATCH 1/4] =?UTF-8?q?Ajout=20d=C3=A9but=20partie=202=20(bugg?=
 =?UTF-8?q?=C3=A9)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 jour14/jour14.m   |  9 ++++--
 jour14/raindeer.h |  9 +++++-
 jour14/raindeer.m | 28 ++++++++++++++++++-
 jour14/troupeau.h | 15 ++++++++++
 jour14/troupeau.m | 71 +++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 128 insertions(+), 4 deletions(-)
 create mode 100644 jour14/troupeau.h
 create mode 100644 jour14/troupeau.m

diff --git a/jour14/jour14.m b/jour14/jour14.m
index a2d52c1..3d186ee 100644
--- a/jour14/jour14.m
+++ b/jour14/jour14.m
@@ -1,4 +1,5 @@
 #import "raindeer.h"
+#import "troupeau.h"
 #import <Foundation/Foundation.h>
  
 int main() 
@@ -12,6 +13,7 @@ int main()
                                         error:&err];
     NSArray *lines = [contentFile componentsSeparatedByString:@"\n"];
     NSMutableArray *listDeer = [[NSMutableArray alloc] init];
+    Troupeau *troupeau = [[Troupeau alloc] init];
 
     for (NSString *tmp in lines)
     {
@@ -22,10 +24,11 @@ int main()
                                      zatSpeed:[[parsedSpace objectAtIndex:3]  integerValue]
                                      boostTime:[[parsedSpace objectAtIndex:6] integerValue]
                                      LunchTime:[[parsedSpace objectAtIndex:13] integerValue]];
-            [listDeer addObject:rd];
+            [troupeau newDeer:rd];
         }        
     }
 
+    /*
     int ret = 0;
     int tmp = 0;
     for (Raindeer *rd in listDeer)
@@ -35,7 +38,9 @@ int main()
             ret = tmp;
         [rd release];
     }
-    NSLog(@"le résultat est : %d", ret);
+    */
+    NSLog(@"le résultat est : %d", [troupeau courseUne:1000]);
+    NSLog(@"le résultat est : %d", [troupeau courseDeux:1000]);
 
     //finir le main par ça
     [contentFile release];
diff --git a/jour14/raindeer.h b/jour14/raindeer.h
index 103b76c..3833b74 100644
--- a/jour14/raindeer.h
+++ b/jour14/raindeer.h
@@ -6,14 +6,21 @@
     int speed;
     int boostTime;
     int pause;
+    int points;
+
+    int cooldown;
+    int hypervitesse;
+    int distance;
 }
 
 // permet de générer des setters et getter selon des attributs
 // ici retain, nonatomic et assign
 @property (retain, nonatomic) NSString *name;
-@property (assign) int speed, boostTime, pause;
+@property (assign) int speed, boostTime, pause, points, cooldown, hypervitesse, distance;
 
 + (id) initWithName:(NSString*)name zatSpeed:(int)speed boostTime:(int)timeSpeed LunchTime:(int)pause;
 - (int) calculDistance:(int)time;
+- (int) updateDistance;
+- (void) updatePoints;
 
 @end
diff --git a/jour14/raindeer.m b/jour14/raindeer.m
index 177475f..7de27f8 100644
--- a/jour14/raindeer.m
+++ b/jour14/raindeer.m
@@ -4,7 +4,7 @@
 @implementation Raindeer
 
 // permet de créer les getters et setters à partir de property
-@synthesize name, speed, boostTime, pause;
+@synthesize name, speed, boostTime, pause, points, cooldown, hypervitesse, distance;
 
 + (id) initWithName:(NSString*)name zatSpeed:(int)speed boostTime:(int)boostTime LunchTime:(int)pause
 {
@@ -15,6 +15,10 @@
         new.speed = speed;
         new.boostTime = boostTime;
         new.pause = pause;
+        new.points = 0;
+        new.cooldown = 0;
+        new.hypervitesse = boostTime;
+        new.distance = 0;
     }
     return new;
 }
@@ -31,6 +35,28 @@
     return ret;
 }
 
+- (int) updateDistance
+{
+    if (cooldown > 0)
+        cooldown--;
+        if (cooldown == 0)
+            hypervitesse = boostTime;
+    else
+    {
+        distance += speed;
+        hypervitesse--;
+        if (hypervitesse == 0)
+            cooldown = pause;
+    }
+
+    return distance;
+}
+
+- (void) updatePoints
+{
+    points++;
+}
+
 - (void) dealloc
 {
     [name release];
diff --git a/jour14/troupeau.h b/jour14/troupeau.h
new file mode 100644
index 0000000..e25bd9d
--- /dev/null
+++ b/jour14/troupeau.h
@@ -0,0 +1,15 @@
+#import "raindeer.h"
+#import <Foundation/Foundation.h>
+
+@interface Troupeau : NSObject
+{
+    NSMutableArray *troupeau;
+    NSSortDescriptor *recetteTri;
+}
+
+- (id) init;
+- (void) newDeer:(Raindeer*)rd;
+- (int) courseUne:(int)time;
+- (int) courseDeux:(int)time;
+
+@end
diff --git a/jour14/troupeau.m b/jour14/troupeau.m
new file mode 100644
index 0000000..684f09a
--- /dev/null
+++ b/jour14/troupeau.m
@@ -0,0 +1,71 @@
+#import "troupeau.h"
+#import "raindeer.h"
+
+@implementation Troupeau
+
+- (id) init
+{
+    self = [super init];
+    if (self)
+    {
+       recetteTri = [[NSSortDescriptor alloc] initWithKey:@"distance"
+                                                    ascending:YES];
+       troupeau = [[NSMutableArray alloc] init];
+    } 
+    return self;
+}
+
+- (void) newDeer:(Raindeer*)rd
+{
+    [troupeau addObject:rd];
+}
+
+- (int) courseUne:(int)time
+{
+    int ret = 0, tmp = 0;
+    for (Raindeer *rd in troupeau)
+    {
+        tmp = [rd calculDistance:time];
+            if (tmp > ret)
+                ret = tmp;
+    }
+    return ret;
+}
+
+- (int) courseDeux:(int)time
+{
+    int ret = 0;
+    while (time > 0)
+    {
+        for (Raindeer *rd in troupeau)
+        {
+            int t = [rd updateDistance];
+        }
+        NSArray *tmp = [NSArray arrayWithObject:recetteTri];
+        NSArray *sortedRank = [troupeau sortedArrayUsingDescriptors:tmp];
+        [[sortedRank firstObject] updatePoints];
+        NSLog(@"%d", [[sortedRank firstObject] points]);
+        NSLog(@"Rennes : %@ pour une distance de %d", [[troupeau firstObject] name], [[troupeau firstObject] distance]);
+        // copier dans le troupeau le tableau trié
+        time--;
+    }
+    NSSortDescriptor *tt = [[NSSortDescriptor alloc] initWithKey:@"points"
+                                                    ascending:YES];
+    NSArray *tmpp = [NSArray arrayWithObject:tt];
+    NSArray *sortedPonits = [troupeau sortedArrayUsingDescriptors:tmpp];
+    NSLog(@"%d", [[sortedPonits firstObject] points]);
+    ret = [[sortedPonits firstObject] points];
+    
+    return ret;
+}
+
+- (void) dealloc
+{
+    for (Raindeer *rd in troupeau)
+        [rd dealloc];
+    [troupeau release];
+    [recetteTri release];
+    [super dealloc];
+}
+
+@end

From e2c541d9fd14e2f41070241fbe42364601393605 Mon Sep 17 00:00:00 2001
From: rick <rick@gnous.eu>
Date: Mon, 29 Mar 2021 16:26:13 +0200
Subject: [PATCH 2/4] =?UTF-8?q?Ajout=20partie=202=20(bugg=C3=A9)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 jour14/jour14.m   |  5 +++--
 jour14/raindeer.m |  5 +++--
 jour14/troupeau.h |  2 +-
 jour14/troupeau.m | 19 ++++++++-----------
 4 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/jour14/jour14.m b/jour14/jour14.m
index 3d186ee..3f37359 100644
--- a/jour14/jour14.m
+++ b/jour14/jour14.m
@@ -39,8 +39,9 @@ int main()
         [rd release];
     }
     */
-    NSLog(@"le résultat est : %d", [troupeau courseUne:1000]);
-    NSLog(@"le résultat est : %d", [troupeau courseDeux:1000]);
+    int time = 2503;
+    NSLog(@"le résultat est : %d", [troupeau courseUne:time]);
+    NSLog(@"le résultat est : %d", [troupeau courseDeux:time]);
 
     //finir le main par ça
     [contentFile release];
diff --git a/jour14/raindeer.m b/jour14/raindeer.m
index 7de27f8..0e05b28 100644
--- a/jour14/raindeer.m
+++ b/jour14/raindeer.m
@@ -38,17 +38,18 @@
 - (int) updateDistance
 {
     if (cooldown > 0)
+    {
         cooldown--;
         if (cooldown == 0)
             hypervitesse = boostTime;
+    }
     else
     {
-        distance += speed;
+        distance = distance + speed;
         hypervitesse--;
         if (hypervitesse == 0)
             cooldown = pause;
     }
-
     return distance;
 }
 
diff --git a/jour14/troupeau.h b/jour14/troupeau.h
index e25bd9d..f29b54f 100644
--- a/jour14/troupeau.h
+++ b/jour14/troupeau.h
@@ -4,7 +4,7 @@
 @interface Troupeau : NSObject
 {
     NSMutableArray *troupeau;
-    NSSortDescriptor *recetteTri;
+    NSArray *recetteTriDistance;
 }
 
 - (id) init;
diff --git a/jour14/troupeau.m b/jour14/troupeau.m
index 684f09a..62ab84a 100644
--- a/jour14/troupeau.m
+++ b/jour14/troupeau.m
@@ -8,9 +8,10 @@
     self = [super init];
     if (self)
     {
-       recetteTri = [[NSSortDescriptor alloc] initWithKey:@"distance"
-                                                    ascending:YES];
-       troupeau = [[NSMutableArray alloc] init];
+        NSSortDescriptor *recetteTri = [[NSSortDescriptor alloc] initWithKey:@"distance"
+                                                                ascending:NO];
+        recetteTriDistance = [NSArray arrayWithObject:recetteTri];
+        troupeau = [[NSMutableArray alloc] init];
     } 
     return self;
 }
@@ -41,16 +42,12 @@
         {
             int t = [rd updateDistance];
         }
-        NSArray *tmp = [NSArray arrayWithObject:recetteTri];
-        NSArray *sortedRank = [troupeau sortedArrayUsingDescriptors:tmp];
-        [[sortedRank firstObject] updatePoints];
-        NSLog(@"%d", [[sortedRank firstObject] points]);
-        NSLog(@"Rennes : %@ pour une distance de %d", [[troupeau firstObject] name], [[troupeau firstObject] distance]);
-        // copier dans le troupeau le tableau trié
+        [troupeau sortUsingDescriptors:recetteTriDistance];
+        [[troupeau firstObject] updatePoints];
         time--;
     }
     NSSortDescriptor *tt = [[NSSortDescriptor alloc] initWithKey:@"points"
-                                                    ascending:YES];
+                                                     ascending:NO];
     NSArray *tmpp = [NSArray arrayWithObject:tt];
     NSArray *sortedPonits = [troupeau sortedArrayUsingDescriptors:tmpp];
     NSLog(@"%d", [[sortedPonits firstObject] points]);
@@ -64,7 +61,7 @@
     for (Raindeer *rd in troupeau)
         [rd dealloc];
     [troupeau release];
-    [recetteTri release];
+    //[recetteTri release];
     [super dealloc];
 }
 

From 50bed585db8a61539f7404dfa324d92a850973cd Mon Sep 17 00:00:00 2001
From: rick <rick@gnous.eu>
Date: Tue, 30 Mar 2021 01:48:15 +0200
Subject: [PATCH 3/4] =?UTF-8?q?Ajout=20de=20l=E2=80=99entr=C3=A9e?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 jour14/input | 9 +++++++++
 1 file changed, 9 insertions(+)
 create mode 100644 jour14/input

diff --git a/jour14/input b/jour14/input
new file mode 100644
index 0000000..6cf5489
--- /dev/null
+++ b/jour14/input
@@ -0,0 +1,9 @@
+Dancer can fly 27 km/s for 5 seconds, but then must rest for 132 seconds.
+Cupid can fly 22 km/s for 2 seconds, but then must rest for 41 seconds.
+Rudolph can fly 11 km/s for 5 seconds, but then must rest for 48 seconds.
+Donner can fly 28 km/s for 5 seconds, but then must rest for 134 seconds.
+Dasher can fly 4 km/s for 16 seconds, but then must rest for 55 seconds.
+Blitzen can fly 14 km/s for 3 seconds, but then must rest for 38 seconds.
+Prancer can fly 3 km/s for 21 seconds, but then must rest for 40 seconds.
+Comet can fly 18 km/s for 6 seconds, but then must rest for 103 seconds.
+Vixen can fly 18 km/s for 5 seconds, but then must rest for 84 seconds.

From 1579b57608cab7f896e543027944b8621f6310be Mon Sep 17 00:00:00 2001
From: rick <rick@gnous.eu>
Date: Tue, 30 Mar 2021 01:49:26 +0200
Subject: [PATCH 4/4] =?UTF-8?q?Patch=20et=20am=C3=A9lioration?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 jour14/jour14.m   | 23 +++++++----------------
 jour14/raindeer.h |  2 +-
 jour14/raindeer.m |  5 ++---
 jour14/troupeau.m | 23 +++++++----------------
 4 files changed, 17 insertions(+), 36 deletions(-)

diff --git a/jour14/jour14.m b/jour14/jour14.m
index 3f37359..f70231e 100644
--- a/jour14/jour14.m
+++ b/jour14/jour14.m
@@ -9,8 +9,9 @@ int main()
     NSString *path = @"input";
     NSError *err;
     NSString *contentFile = [[NSString alloc] initWithContentsOfFile:path
-                                        encoding:NSUTF8StringEncoding 
-                                        error:&err];
+                                              encoding:NSUTF8StringEncoding 
+                                              error:&err];
+
     NSArray *lines = [contentFile componentsSeparatedByString:@"\n"];
     NSMutableArray *listDeer = [[NSMutableArray alloc] init];
     Troupeau *troupeau = [[Troupeau alloc] init];
@@ -28,24 +29,14 @@ int main()
         }        
     }
 
-    /*
-    int ret = 0;
-    int tmp = 0;
-    for (Raindeer *rd in listDeer)
-    {
-        tmp = [rd calculDistance:2503];
-        if (tmp > ret)
-            ret = tmp;
-        [rd release];
-    }
-    */
-    int time = 2503;
-    NSLog(@"le résultat est : %d", [troupeau courseUne:time]);
-    NSLog(@"le résultat est : %d", [troupeau courseDeux:time]);
+    const int time = 2503;
+    NSLog(@"le résultat de la première sélection est : %d", [troupeau courseUne:time]);
+    NSLog(@"le résultat de la deuxième sélection est : %d", [troupeau courseDeux:time]);
 
     //finir le main par ça
     [contentFile release];
     [listDeer release];
+    [troupeau dealloc];
     [myPool drain];
     return 0;
 }
diff --git a/jour14/raindeer.h b/jour14/raindeer.h
index 3833b74..376ee97 100644
--- a/jour14/raindeer.h
+++ b/jour14/raindeer.h
@@ -20,7 +20,7 @@
 
 + (id) initWithName:(NSString*)name zatSpeed:(int)speed boostTime:(int)timeSpeed LunchTime:(int)pause;
 - (int) calculDistance:(int)time;
-- (int) updateDistance;
+- (void) updateDistance;
 - (void) updatePoints;
 
 @end
diff --git a/jour14/raindeer.m b/jour14/raindeer.m
index 0e05b28..105ae21 100644
--- a/jour14/raindeer.m
+++ b/jour14/raindeer.m
@@ -15,7 +15,7 @@
         new.speed = speed;
         new.boostTime = boostTime;
         new.pause = pause;
-        new.points = 0;
+        new.points = 1; //pas sur que ce soit la bonne méthode mais chut
         new.cooldown = 0;
         new.hypervitesse = boostTime;
         new.distance = 0;
@@ -35,7 +35,7 @@
     return ret;
 }
 
-- (int) updateDistance
+- (void) updateDistance
 {
     if (cooldown > 0)
     {
@@ -50,7 +50,6 @@
         if (hypervitesse == 0)
             cooldown = pause;
     }
-    return distance;
 }
 
 - (void) updatePoints
diff --git a/jour14/troupeau.m b/jour14/troupeau.m
index 62ab84a..fbad31e 100644
--- a/jour14/troupeau.m
+++ b/jour14/troupeau.m
@@ -35,33 +35,24 @@
 
 - (int) courseDeux:(int)time
 {
-    int ret = 0;
-    while (time > 0)
+    while (time >= 0)
     {
         for (Raindeer *rd in troupeau)
-        {
-            int t = [rd updateDistance];
-        }
+            [rd updateDistance];
         [troupeau sortUsingDescriptors:recetteTriDistance];
         [[troupeau firstObject] updatePoints];
         time--;
     }
-    NSSortDescriptor *tt = [[NSSortDescriptor alloc] initWithKey:@"points"
-                                                     ascending:NO];
-    NSArray *tmpp = [NSArray arrayWithObject:tt];
-    NSArray *sortedPonits = [troupeau sortedArrayUsingDescriptors:tmpp];
-    NSLog(@"%d", [[sortedPonits firstObject] points]);
-    ret = [[sortedPonits firstObject] points];
-    
-    return ret;
+    NSSortDescriptor *descPoints = [[NSSortDescriptor alloc] initWithKey:@"points"
+                                                             ascending:NO];
+    NSArray *tmp = [NSArray arrayWithObject:descPoints];
+    NSArray *sortedPoints = [troupeau sortedArrayUsingDescriptors:tmp];
+    return [[sortedPoints firstObject] points];
 }
 
 - (void) dealloc
 {
-    for (Raindeer *rd in troupeau)
-        [rd dealloc];
     [troupeau release];
-    //[recetteTri release];
     [super dealloc];
 }