summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2009-05-16 01:44:16 -0500
committerJesse Luehrs <doy@tozt.net>2009-05-16 01:44:16 -0500
commit67cb894a9ed7a752e21154282858f16f9567124d (patch)
treeae46ed29e58716048d574877fa05d2cfefb3df0b
parent1f1b9257d45b46280111379f9cf1a23e8f54c6f8 (diff)
downloadprojecteuler-67cb894a9ed7a752e21154282858f16f9567124d.tar.gz
projecteuler-67cb894a9ed7a752e21154282858f16f9567124d.zip
solution for 45
-rwxr-xr-x045.pl13
1 files changed, 13 insertions, 0 deletions
diff --git a/045.pl b/045.pl
new file mode 100755
index 0000000..a47399d
--- /dev/null
+++ b/045.pl
@@ -0,0 +1,13 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+for my $h_idx (144..100000) {
+ my $hex = $h_idx * (2 * $h_idx - 1);
+ my $tri_test = -1/2 + sqrt(1 + 8 * $hex) / 2;
+ next unless $tri_test == int($tri_test);
+ my $pent_test = 1/6 + sqrt(1 + 24 * $hex) / 6;
+ next unless $pent_test == int($pent_test);
+ print "$tri_test $pent_test $h_idx $hex\n";
+ last;
+}