-
Notifications
You must be signed in to change notification settings - Fork 0
/
10.rb
130 lines (122 loc) · 747 Bytes
/
10.rb
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
data = DATA.each_line.map &:to_i
data = [0, *data.sort, data.max + 3]
puts data.each_cons(2).map { |a, b| b - a }.tally.values.inject(:*) # 2482
ways = [0] * data.size
ways[0] = 1
for i in (1...data.size) do
for j in (1..3) do
if i - j >= 0
if data[i] - data[i - j] <= 3
ways[i] += ways[i - j]
end
end
end
end
puts ways.last # 96717311574016
__END__
66
7
73
162
62
165
157
158
137
125
138
59
36
40
94
95
13
35
136
96
156
155
24
84
42
171
142
3
104
149
83
129
19
122
68
103
74
118
20
110
54
127
88
31
135
26
126
2
51
91
16
65
128
119
67
48
111
29
49
12
132
17
41
166
75
146
50
30
1
164
112
34
18
72
97
145
11
117
58
78
152
90
172
163
89
107
45
37
79
159
141
105
10
115
69
170
25
100
80
4
85
169
106
57
116
23