diff options
author | Jesse Luehrs <doy@tozt.net> | 2009-05-16 01:44:16 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2009-05-16 01:44:16 -0500 |
commit | 67cb894a9ed7a752e21154282858f16f9567124d (patch) | |
tree | ae46ed29e58716048d574877fa05d2cfefb3df0b /045.pl | |
parent | 1f1b9257d45b46280111379f9cf1a23e8f54c6f8 (diff) | |
download | projecteuler-67cb894a9ed7a752e21154282858f16f9567124d.tar.gz projecteuler-67cb894a9ed7a752e21154282858f16f9567124d.zip |
solution for 45
Diffstat (limited to '045.pl')
-rwxr-xr-x | 045.pl | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -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; +} |