Shlomi Fish avatar Shlomi Fish committed 3f9235d

Add the solution to Euler #117.

Working now.

Comments (0)

Files changed (1)

project-euler/117/euler-117.pl

+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+=head1 DESCRIPTION
+
+Using a combination of black square tiles and oblong tiles chosen from: red tiles measuring two units, green tiles measuring three units, and blue tiles measuring four units, it is possible to tile a row measuring five units in length in exactly fifteen different ways.
+
+How many ways can a row measuring fifty units in length be tiled?
+
+NOTE: This is related to problem 116.
+
+=cut
+
+use Math::GMP qw(:constant);
+
+sub count
+{
+    my ($min_tile_len, $max_tile_len, $total_len) = @_;
+
+    my @counts;
+
+    foreach my $len (0 .. $min_tile_len-1)
+    {
+        push @counts, 1;
+    }
+
+    for my $len ($min_tile_len .. $total_len)
+    {
+        my $sum = 0;
+
+        foreach my $delta (1, ($min_tile_len .. $max_tile_len))
+        {
+            if ($delta <= @counts)
+            {
+                $sum += $counts[-$delta]; 
+            }
+        }
+        push @counts, $sum;
+    }
+
+    # We need to exclude the all-black-squares one which is:
+    # 1. Common.
+    # 2. Should not be included.
+    return $counts[-1];
+}
+
+print count(2, 4, 50), "\n";
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.