Sha256: da6dceffcb125fed259d570f67b45587b0fffcae62dad13a405cc25ee77ccd98
Contents?: true
Size: 573 Bytes
Versions: 3
Compression:
Stored size: 573 Bytes
Contents
#!/usr/bin/perl my $SEPARATOR=" "; my $niterations = 0; sub siracusa { my $t = shift; $niterations ++ ; if ($t == 1 ) { return 1; } print "$t$SEPARATOR"; if ($t %2) { return siracusa(3 * $t +1); } return siracusa($t/2); } print "# Simple yet neat algorithm: if n is even, I halve it. If it's odd I triple it and add 1. Look:\n"; my $arg = 0+int($ARGV[0]); if ($arg == 0) { $arg = 42; } print siracusa($arg); #print siracusa(0 + int($ARGV[0])); print "\n"; print "# Flight time: $niterations\n"; print "# Flight pendency: " .($niterations/$arg) ."\n";
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
sakuric-2.1.3 | bin/syracuse.pl |
sakuric-2.0.3 | bin/syracuse.pl |
sakuric-2.0.1 | bin/syracuse.pl |