Last active
December 13, 2015 21:39
-
-
Save ggtools/4979015 to your computer and use it in GitHub Desktop.
Version en perl pour http://thecodersbreakfast.net/index.php?post/2013/02/18/Coding-challenge-maman-les-petits-avions
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
#!/usr/bin/perl | |
use strict; | |
use Data::Dumper; | |
my $initialNumber = 0; | |
$initialNumber += $_ for map { ord($_) } split //, shift || die "No word supplied"; | |
my ( $tempVol, $volEnAltitude, $altitudeMax, $descendu ); | |
my $number = $initialNumber; | |
my @sequence; | |
while (1) { | |
push @sequence, $number; | |
$descendu = $descendu || $number < $initialNumber; | |
$volEnAltitude += !$descendu; | |
$tempVol++; | |
$altitudeMax = $number if ( $number > $altitudeMax ); | |
last if $number == 1; | |
$number = $number % 2 ? $number * 3 + 1 : $number / 2; | |
} | |
print "[", join( ", ", @sequence ), "]\n"; | |
print "temps de vol $tempVol\n"; | |
print "temps de vol en altitude $volEnAltitude\n"; | |
print "altitude max $altitudeMax\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment