Created
May 27, 2011 21:07
-
-
Save luelista/996169 to your computer and use it in GitHub Desktop.
perl one-liner for Collatz sequence
This file contains hidden or 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
$ perl -e "$_=shift;while($_>1){if($_%2){$_*=3;$_++;}else{$_/=2;}print++$c,\"# $_\n\"}" 12345 |
This file contains hidden or 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
# avec whitespace | |
$_=shift; | |
while($_>1){ | |
if($_%2){ | |
$_*=3;$_++; | |
}else{ | |
$_/=2; | |
} | |
print++$c,"# $_\n" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment