Last active
          December 12, 2016 19:25 
        
      - 
      
- 
        Save alexxroche/16032a7b48127ec248d91220f25d55b2 to your computer and use it in GitHub Desktop. 
    Collatz Conjecture perl
  
        
  
    
      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
    
  
  
    
  | #!/usr/bin/env perl | |
| # sudo yum install -y perl-Math-BigInt-GMP || sudo apt-get install -y libmath-bigint-gmp-perl | |
| use strict; | |
| use Math::BigInt lib => 'GMP'; | |
| my $in = $ARGV[0] || &help; | |
| $in=~s/,//g; | |
| $in = Math::BigInt->new($in); | |
| sub help{print "What number?\n"; exit;} | |
| sub col(){ | |
| my $i = shift; | |
| if ($i % 2 == 0 ){ | |
| return $i/2; | |
| }else{ | |
| return ($i*3)+1; | |
| } | |
| } | |
| my $count =0; | |
| while($in > 1){ | |
| $count++; | |
| my $r = &col($in); | |
| print "$count:"; | |
| print "$r"; | |
| print "\n"; | |
| $in=$r; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment