Skip to content

Instantly share code, notes, and snippets.

@dgageot
Created February 20, 2013 14:52
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 dgageot/4996069 to your computer and use it in GitHub Desktop.
Save dgageot/4996069 to your computer and use it in GitHub Desktop.
def next_syracuse(n)
return n/2 if n.even?
3*n+1
end
def syracuse(n)
etapes = [n]
while etapes.last != 1
etapes << next_syracuse(etapes.last)
end
etapes
end
avion = "R2D2"
valeur = avion.sum()
etapes = syracuse(valeur)
tempsDeVol = etapes.size
altitudeMax = etapes.max
#tempsDeVolEnAltitude = etapes.chunk {|v| v>=valeur}.map {|chunk| chunk.last.size}.max
tempsDeVolEnAltitude = etapes.index {|x| x<valeur}
puts avion
puts "valeur : [#{valeur}]"
puts "etapes : [#{etapes.join(',')}]"
puts "tempsDeVol : #{tempsDeVol}"
puts "tempsDeVolEnAltitude : #{tempsDeVolEnAltitude}"
puts "altitudeMax : #{altitudeMax}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment