-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path191 Prize Strings.pl
More file actions
44 lines (29 loc) · 815 Bytes
/
191 Prize Strings.pl
File metadata and controls
44 lines (29 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/perl
# Daniel "Trizen" Șuteu
# Date: 19 October 2017
# https://github.com/trizen
# Runtime: 0.019s
# https://projecteuler.net/problem=191
use 5.022;
use strict;
use warnings;
use experimental qw(signatures);
sub p_191($days) {
my %cache;
sub ($len, $hasL, $hasA1, $hasA2) {
exists($cache{"@_"})
and return $cache{"@_"};
my $count = ($len == $days) ? 1 : 0;
if ($len < $days) {
if (!$hasA1 || !$hasA2) {
$count += __SUB__->($len + 1, $hasL, $hasA2, 1);
}
$count += __SUB__->($len + 1, $hasL, $hasA2, 0);
if (!$hasL) {
$count += __SUB__->($len + 1, 1, $hasA2, 0);
}
}
return ($cache{"@_"} = $count);
}->(0, 0, 0, 0);
}
say p_191(30);