Last active
December 13, 2015 21:38
-
-
Save fpavageau/4978849 to your computer and use it in GitHub Desktop.
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
def fly = { String name -> | |
def initial = name.toList().inject(0, { a, b -> a + (int) b }) | |
def height = initial, flight = [] | |
def next = { (int) (it % 2) ? it * 3 + 1 : it / 2 } | |
while (true) { | |
flight << height | |
if (height > 1) { height = next(height) } | |
else { break } | |
} | |
println flight | |
def altitude = { cutoff -> | |
def altitude = true | |
return { altitude &= it >= cutoff } | |
} | |
[ tempsVolTotal: flight.size(), tempsVolAltitude: flight.grep(altitude(initial)).size(), altitudeMax: flight.max() ] | |
} | |
println fly("Enterprise") | |
// [1057, 3172, 1586, 793, 2380, 1190, 595, 1786, 893, 2680, 1340, 670, 335, 1006, 503, 1510, 755, 2266, 1133, 3400, 1700, 850, 425, 1276, 638, 319, 958, 479, 1438, 719, 2158, 1079, 3238, 1619, 4858, 2429, 7288, 3644, 1822, 911, 2734, 1367, 4102, 2051, 6154, 3077, 9232, 4616, 2308, 1154, 577, 1732, 866, 433, 1300, 650, 325, 976, 488, 244, 122, 61, 184, 92, 46, 23, 70, 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1] | |
// [tempsVolTotal:81, tempsVolAltitude:3, altitudeMax:9232] | |
println fly("FauconMillenium") | |
// [1544, 772, 386, 193, 580, 290, 145, 436, 218, 109, 328, 164, 82, 41, 124, 62, 31, 94, 47, 142, 71, 214, 107, 322, 161, 484, 242, 121, 364, 182, 91, 274, 137, 412, 206, 103, 310, 155, 466, 233, 700, 350, 175, 526, 263, 790, 395, 1186, 593, 1780, 890, 445, 1336, 668, 334, 167, 502, 251, 754, 377, 1132, 566, 283, 850, 425, 1276, 638, 319, 958, 479, 1438, 719, 2158, 1079, 3238, 1619, 4858, 2429, 7288, 3644, 1822, 911, 2734, 1367, 4102, 2051, 6154, 3077, 9232, 4616, 2308, 1154, 577, 1732, 866, 433, 1300, 650, 325, 976, 488, 244, 122, 61, 184, 92, 46, 23, 70, 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1] | |
// [tempsVolTotal:123, tempsVolAltitude:1, altitudeMax:9232] | |
println fly("A380") | |
// [220, 110, 55, 166, 83, 250, 125, 376, 188, 94, 47, 142, 71, 214, 107, 322, 161, 484, 242, 121, 364, 182, 91, 274, 137, 412, 206, 103, 310, 155, 466, 233, 700, 350, 175, 526, 263, 790, 395, 1186, 593, 1780, 890, 445, 1336, 668, 334, 167, 502, 251, 754, 377, 1132, 566, 283, 850, 425, 1276, 638, 319, 958, 479, 1438, 719, 2158, 1079, 3238, 1619, 4858, 2429, 7288, 3644, 1822, 911, 2734, 1367, 4102, 2051, 6154, 3077, 9232, 4616, 2308, 1154, 577, 1732, 866, 433, 1300, 650, 325, 976, 488, 244, 122, 61, 184, 92, 46, 23, 70, 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1] | |
// [tempsVolTotal:115, tempsVolAltitude:1, altitudeMax:9232] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment