Dag: 6
Språk: VB.Net
Imports System.IO
Module Program
Sub Main(args As String())
Dim input = File.ReadAllText("input.txt")
Console.WriteLine("Part1: " & findIndex(input, 4))
Console.WriteLine("Part1: " & findIndex(input, 14))
End Sub
Function findIndex(input As String, markerLength As Integer) As Integer
Dim window(markerLength - 1) As String
For i = 0 To input.Length - 1 Step 1
window(i Mod markerLength) = input(i)
If i >= markerLength - 1 And window.Distinct().Count = markerLength Then
Return i + 1
End If
Next
Return -1
End Function
End Module
Dold text