AOC_2022/1/adventofcode1/Form1.vb

56 lines
1.9 KiB
VB.net
Raw Normal View History

2022-12-03 02:49:05 +01:00
Public Class Form1
Dim input As String = My.Computer.FileSystem.ReadAllText("./input.txt")
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim linesArr As String() = input.Split(Environment.NewLine)
Dim tmpMarker As Integer = 0
Dim elves As New List(Of Integer)
For i As Integer = 0 To linesArr.Length - 1
If linesArr(i) = "" Then
Dim tmpSum As Integer = 0
For j As Integer = tmpMarker To i - 1
'MsgBox("DEBUG: i=" + CStr(i) + ", j=" + CStr(j) + "; " + linesArr(j))
tmpSum += Convert.ToInt32(linesArr(j))
Next
elves.Add(tmpSum)
tmpMarker = i + 1
End If
Next
MsgBox("Der krankste Huhn im Stall: " + CStr(Me.findMax(elves)))
MsgBox("Summe der tollsten drei Hengste im Hanger: " + CStr(findTopThreeSum(elves)))
End Sub
Public Function findMax(inputArr As List(Of Integer)) As Integer
Dim out As Integer = 0
For i As Integer = 0 To inputArr.Count - 1
If inputArr(i) > out Then out = inputArr(i)
Next
Return out
End Function
Public Function findTopThreeSum(inputArr As List(Of Integer)) As Integer
Dim erster As Integer = 0
Dim zweiter As Integer = 0
Dim dritter As Integer = 0
For i As Integer = 0 To inputArr.Count - 1
If inputArr(i) > erster Then erster = inputArr(i)
Next
For i As Integer = 0 To inputArr.Count - 1
If inputArr(i) > zweiter And inputArr(i) < erster Then zweiter = inputArr(i)
Next
For i As Integer = 0 To inputArr.Count - 1
If inputArr(i) > dritter And inputArr(i) < zweiter Then dritter = inputArr(i)
Next
Return erster + zweiter + dritter
End Function
End Class