--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+
+my @prev;
+my $len = 25;
+
+while (my $num = <>) {
+ chomp $num;
+ if (@prev >= $len) {
+ shift @prev if @prev > $len;
+ for my $i (0 .. $len-2) {
+ for my $j ($i+1 .. $len-1) {
+ if ($prev[$i]+$prev[$j] == $num) {
+ goto FOUND;
+ }
+ }
+ }
+ print "$num is not a sum of ", join(', ', @prev), "\n";
+ exit 0;
+ FOUND:
+ }
+ push @prev, $num;
+}
+
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+
+my @prev;
+
+my $target = 375054920;
+
+my $sum = 0;
+while (my $num = <>) {
+ chomp $num;
+
+ $sum += $num;
+ push @prev, $num;
+
+ print "Adding $num, sum=$sum\n";
+
+ while ($sum > $target) {
+ my $n1 = shift @prev;
+ $sum -= $n1;
+ print "Removing $n1, sum=$sum\n";
+ }
+
+ if ($sum == $target) {
+ print "found $sum = ", join('+', @prev), "\n";
+ my ($min, $max);
+ for my $n1 (@prev) {
+ $min = $n1 if !defined $min || $min > $n1;
+ $max = $n1 if !defined $max || $max < $n1;
+ }
+ print "$min+$max=", $min+$max, "\n";
+ last;
+ }
+}
+