text: I:
  #!/usr/bin/perl
  use strict;
  use warnings;
  my ($i, $j, $inum, $jnum, $left);
  my $file = $ARGV[0] || 'targets.txt';
  open (INPUT, '<', $file) or die "Unable to open $file for reading : $!
  +";
  while ( chomp( my $inp = <INPUT> ) ) {
  BING:
  for ($i = tget($inp); $i; $i--) {
  $inum = tmake($i);
  $left = tget($inp - $inum - 1) + 1;
  for ($j = 1; $j < $left; $j++) {
  $jnum = tmake($j);
  last BING if (tis($inp - $inum - $jnum));
  }
  }
  }
  sub tget { return int(sqrt(1 + $_[0] * 2) - .5); }
  sub tmake { return (.5 * $_[0] * ($_[0] + 1)); }
  sub tis { my $n = shift; return ($n == tmake(tget($n))); }
  [download]
  Cheers - L~R
  In reply to Re^2: Triangle Numbers Revisited
  by Limbic~Region
  in thread Triangle Numbers Revisited