You are viewing an archive of Victory Road.
Victory Road closed on January 8, 2018. Thank you for making us a part of your lives since 2006! Please read this thread for details if you missed it.
I wrote this as a solution to my math homework; the problem was figuring out what the greatest number was that could not be made by adding 6, 9, and 20.
#!/usr/bin/perl
# (c) J Parsons
# V.02.2 (1/6/09)
# math.pl [int1] [int2] [int3] [length]
sub check {
# $x is the value to be tested, $int1 is the first integer to test for, and so on.
my($x,$int1,$int2,$int3) = @_;
# Copy $x into $y.
$y = $x;
for ($z = $y; $z >= 0; $z -= $int1) {
$v1 += 1;
}
for ($v1; $v1 >= 0; $v1 -= 1) {
$y -= ($v1 * $int1);
$a = $y;
if ($y == 0) {
return "$int1 × $v1 $int2 × 0 $int3 × 0";
}
if ($int2) {
for ($z = $y; $z >= 0; $z -= $int2) {
$v2 += 1;
}
for ($v2; $v2 >= 0; $v2 -= 1) {
$y -= ($v2 * $int2);
if ($y == 0) {
return "$int1 × $v1 $int2 × $v2 $int3 × 0";
}
if ($int3 > 1) {
for ($z = $y; $z >= 0; $z -= $int3) {
$v3 += 1;
}
for ($v3; $v3 >= 0; $v3 -= 1) {
$y -= ($v3 * $int3);
if ($y == 0) {
return "$int1 × $v1 $int2 × $v2 $int3 × $v3";
}
}
}
$y = $a;
}
}
$y = $x;
}
}
if (!$ARGV[0]) {
die ("math.pl [Integer 1] [Integer 2 = false] [Integeer 3 = false] [Length = 100] [Number = false]\nInteger 1 - The first integer that will be checked for.\nInteger 2 - The second integer that will be checked for.\nInteger 3 - The third integer that will be checked for.\nLength - The duration numbers will be checked for.\nNumber - Overrides length by checking for a specific number.");
}
if (!$ARGV[4]) {
for ($b = 0; $b <= (($ARGV[3]) ? $ARGV[3] : 100); $b += 1) {
if ($combo = check($b,$ARGV[0],$ARGV[1],$ARGV[2])) {
print "$b - true $combo\n";
}
else {
print "$b - false\n";
}
}
}
else {
if ($combo = check($ARGV[4],$ARGV[0],$ARGV[1],$ARGV[2])) {
print "$ARGV[4] - true $combo\n";
}
else {
print "$ARGV[4] - false\n";
}
}
1 – KingOfKYA