174 Counting the number of hollow square laminae that can form one two three distinct arrangements.pl 553 B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/perl
  2. # Daniel "Trizen" Șuteu
  3. # License: GPLv3
  4. # Date: 20 May 2017
  5. # https://github.com/trizen
  6. # https://projecteuler.net/problem=174
  7. # Runtime: 1.050s
  8. use 5.010;
  9. use strict;
  10. use warnings;
  11. my %counts;
  12. my $tiles = 1000000;
  13. foreach my $k (1 .. $tiles >> 2) {
  14. for (my ($sum, $j) = (0, $k + 2) ; ; $j += 2) {
  15. $sum += 2 * $j + 2 * ($j - 2);
  16. $sum <= $tiles ? ++$counts{$sum} : last;
  17. }
  18. }
  19. my $count = 0;
  20. foreach my $value (values %counts) {
  21. if ($value >= 1 and $value <= 10) {
  22. ++$count;
  23. }
  24. }
  25. say $count;