-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproblem122.vb
61 lines (54 loc) · 1.98 KB
/
problem122.vb
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
Imports System
Public Class Problem122
Dim BestAnswers(199) as Long
Public Sub New()
Dim Index As Long
For Index = 0 To 199
BestAnswers(Index) = 300
Next Index
End Sub
Public Sub Recurse(ByVal Visited() As Long, ByVal Recent As Long)
Dim Index As Long, Jndex As Long, Kndex As Long
If Recent > 200 Then
Exit Sub
End If
BestAnswers(Recent - 1) = Math.Min(BestAnswers(Recent - 1), Visited.Length - 1)
For Each Index In Visited
For Each Jndex In Visited
If Index <= Jndex Then
Dim Okay As Boolean = True
For Each Kndex In Visited
If Kndex = Index + Jndex Then
Okay = False
End If
Next Kndex
If Okay Then
If Index + Jndex > Recent And Index + Jndex <= 200 Then
If Visited.Length - 1 < BestAnswers(Index + Jndex - 1) Then
Dim NewVisited(Visited.Length) as Long
NewVisited(0) = Index + Jndex
For Kndex = 0 To Visited.Length - 1
NewVisited(Kndex + 1) = Visited(Kndex)
Next Kndex
Recurse(NewVisited, Index + Jndex)
End If
End If
End If
End If
Next Jndex
Next Index
End Sub
Public Function Sum()
Dim Element As Long
Sum = 0
For Each Element In BestAnswers
Sum += Element
Next Element
End Function
Public Shared Sub Main()
Dim Problem As Problem122 = New Problem122()
Dim StartingPoint() As Long = {1}
Problem.Recurse(StartingPoint, 1)
Console.WriteLine(Problem.Sum())
End Sub
End Class