#!/usr/bin/perl -w
#perl2exe_include Math::BigInt
#perl2exe_include Math::BigInt::Calc
#################################################################
# __________ __ __ #
# \______ \_______ ____ |__| ____ _____/ |_ #
# | ___/\_ __ \/ _ \ | |/ __ \_/ ___\ __\ #
# | | | | \( <_> ) | \ ___/\ \___| | #
# |____| |__| \____/\__| |\___ >\___ >__| #
# \______| \/ \/ #
# ___ ___ .__.__ __ #
# / | \_____ |__| | _______/ |_ ____ ____ ____ #
# / ~ \__ \ | | | / ___/\ __\/ _ \ / \_/ __ \ #
# \ Y // __ \| | |__\___ \ | | ( <_> ) | \ ___/ #
# \___|_ /(____ /__|____/____ > |__| \____/|___| /\___ > #
# \/ \/ \/ \/ \/ #
# #
#################################################################
#hailstone.pl : Checks truth of Hailstone Sequences
#Written by Luke Aaron
#Version B 14/08/06
use bignum;
$loop = 1;
$delq = 0;
while($loop eq 1) {
print "\nStart run (R) or quit(Q): ";
$cmd = <STDIN>;
chomp($cmd);
$cmd =~ tr/A-Z/a-z/;
if($cmd eq 'q') { last }
unless($cmd eq 'r') {
print "\nYou must enter either R or Q.\n";
next;
}
$loop = 2;
}
while($loop eq 2) {
print "\nInput starting integer: ";
$input = <STDIN>;
chomp($input);
unless($input eq int($input)) {
print "\nYou must enter an integer.\n";
next;
}
$loop = 3;
}
while($loop eq 3) {
$value = $input;
chdir('C:\\');
if($delq eq '1') {
unlink('hailstone.txt');
}
$delq = 1;
$frun = 1;
while($value ne 1) {
unless($frun eq 1) {
if($value / 2 eq int($value / 2)) { $value = $value / 2; }
else { $value = ( $value * 3 ) + 1 }
$file = '<hailstone.txt';
open(FILE, $file);
#Search file for $value.
#If found, print "False for $input\n", stop program, but do not delete file.
close(FILE);
}
$file = '>>hailstone.txt';
open(FILE, $file);
print FILE "$value\n";
close(FILE);
$frun = 0;
}
print "True for $input\n";
$input = $input + 1;
}
print "Program terminated.\n"