-
-
Save anonymous/8704321344e8d3339440 to your computer and use it in GitHub Desktop.
TheCodersBreakfast #CodingChallenge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace Avions { | |
class Program { | |
static void Main(string[] args) { | |
System.Console.Out.WriteLine(new Avion(args[0])); | |
} | |
class Avion { | |
private List<int> sequenceVol = null; | |
private string nom; | |
public string Nom { | |
get{ | |
return this.nom; | |
} | |
set{ | |
this.nom = value; | |
this.calculSequenceVol(); | |
} | |
} | |
public Avion(string nom) { | |
this.Nom = nom; | |
} | |
private void calculSequenceVol() { | |
this.sequenceVol = new List<int>(); | |
int altitude = 0; | |
foreach (char c in this.nom) { | |
altitude += c; | |
} | |
sequenceVol.Add(altitude); | |
while (altitude != 1) { | |
if ((altitude % 2) == 0) { | |
altitude /= 2; | |
} else { | |
altitude *= 3; | |
altitude++; | |
} | |
sequenceVol.Add(altitude); | |
} | |
} | |
public override string ToString() { | |
return string.Format("Avion {0}\nSéquence : [{1}]\nTemps total de vol : {2}\nTemps total de vol en altitude : {3}\nAltitude maximale : {4}", this.nom, string.Join(",", this.sequenceVol), this.getTempsDeVol(), this.getTempsDeVolEnAltitude(), this.getAltitudeMax()); | |
} | |
public int getTempsDeVol(){ | |
return this.sequenceVol.Count<int>(); | |
} | |
public int getTempsDeVolEnAltitude() { | |
return this.sequenceVol.Count<int>(n => n >= this.sequenceVol.FirstOrDefault<int>()); | |
} | |
public int getAltitudeMax() { | |
return this.sequenceVol.Max<int>(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment