Shlomi Fish avatar Shlomi Fish committed de37b38

Start writing the Perl code.

Comments (0)

Files changed (1)

project-euler/189/euler_189.pl

+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use bytes;
+use integer;
+
+use List::Util qw(sum);
+use List::MoreUtils qw();
+
+my @by_height;
+
+sub init_by_height
+{
+    @by_height = ();
+
+    $by_height[0] =
+    {
+        seq => { '' => 1, },
+        derived =>
+        {
+            '' =>
+            {
+                '0' => 1,
+                '1' => 1,
+                '2' => 1,
+            }
+        },
+    };
+    $by_height[1] =
+    {
+        seq => {'0' => 1, '1' => 1, '2' => 1,},
+        count => 3,
+    };
+
+    return;
+}
+
+init_by_height();
+
+sub my_find
+{
+    my ($wanted_h) = @_;
+
+    for my $h (1 .. $wanted_h-1)
+    {
+        # Now $by_height[$h-1]{seq} is ready.
+        my $this_seq = $by_height[$h]{seq};
+        my $prev_derived = $by_height[$h-1]{derived};
+
+        my $count = 0;
+        my $next_derived = {};
+        my $next_seq = {};
+
+        $by_height[$h+1]{seq} = $next_seq;
+        $by_height[$h+1]{count} = $count;
+        $by_height[$h]{derived} = $next_derived;
+    }
+
+    return $by_height[$wanted_h]{count};
+}
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.