Skip to content

Instantly share code, notes, and snippets.

@jabby
Created February 20, 2013 12:51
Show Gist options
  • Save jabby/4995327 to your computer and use it in GitHub Desktop.
Save jabby/4995327 to your computer and use it in GitHub Desktop.
package fr.jabbytechs;
import java.util.ArrayList;
import java.util.List;
public class Avion {
private String nomPrototype;
private List<Integer> sequence = new ArrayList<Integer>();
private int altitudeMax;
private int volEnAltitudeMax;
public Avion(String nomPrototype) {
this.nomPrototype = nomPrototype;
}
/**
* @param args
*/
public static void main(String[] args) {
Avion prototype = new Avion("Virgon Express");
prototype.calculerSequenceVol();
System.out.println(prototype.toString());
}
private void calculerSequenceVol() {
// Calcul de la valeur du prototype
char[] nomProto = this.nomPrototype.toCharArray();
int valeurPrototype = 0;
for (char c : nomProto) {
valeurPrototype += c;
}
int altitude = valeurPrototype;
altitudeMax = valeurPrototype;
int volEnAltitude = 0;
sequence.add(altitude);
while (altitude != 1) {
if ((altitude % 2) == 0) {
altitude /= 2;
} else {
altitude *= 3;
altitude++;
}
altitudeMax = altitudeMax < altitude ? altitude : altitudeMax;
if (altitude >= valeurPrototype) {
volEnAltitude++;
volEnAltitudeMax = volEnAltitude > volEnAltitudeMax ? volEnAltitude : volEnAltitudeMax;
} else {
volEnAltitude = 0;
}
sequence.add(altitude);
}
}
@Override
public String toString() {
return new StringBuffer().append("Temps de vol : ").append(sequence.size())
.append("\nVol en altitude : ").append(volEnAltitudeMax)
.append("\nAltitude max : ").append(altitudeMax)
.append("\n").append(sequence.toString()).toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment