Skip to content

Instantly share code, notes, and snippets.

Created February 18, 2013 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/8704321344e8d3339440 to your computer and use it in GitHub Desktop.
Save anonymous/8704321344e8d3339440 to your computer and use it in GitHub Desktop.
TheCodersBreakfast #CodingChallenge
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