diff --git a/Advent.csproj.DotSettings b/Advent.csproj.DotSettings
index eec121f..05fd445 100644
--- a/Advent.csproj.DotSettings
+++ b/Advent.csproj.DotSettings
@@ -1,4 +1,5 @@
True
True
- True
\ No newline at end of file
+ True
+ True
\ No newline at end of file
diff --git a/Day4/Day4.cs b/Day4/Day4.cs
new file mode 100644
index 0000000..c78f839
--- /dev/null
+++ b/Day4/Day4.cs
@@ -0,0 +1,63 @@
+using System;
+using System.Linq;
+
+namespace Advent
+{
+ public static class Day4
+ {
+ public static void Execute()
+ {
+ //Console.WriteLine(IsValidPassword("112233"));
+ //Console.WriteLine(IsValidPassword("123444"));
+ //Console.WriteLine(IsValidPassword("111122"));
+
+ var count = 0;
+
+ for (var i = 109165; i <= 576723; i++)
+ {
+ if (IsValidPassword(i.ToString()))
+ count++;
+ }
+
+ Console.WriteLine(count);
+ }
+
+ private static bool IsValidPassword(string password)
+ {
+ var digits = password.ToCharArray();
+
+ var sortedDigits = password.ToCharArray().OrderBy(c => c);
+
+ if (!digits.SequenceEqual(sortedDigits))
+ return false;
+
+ var hasDouble = false;
+ var index = 0;
+ var letter = digits[0];
+
+ while (index < 6)
+ {
+ var count = 1;
+
+ while (index < 5 && digits[index + 1] == letter)
+ {
+ count++;
+ index++;
+ }
+
+ if (count == 2)
+ {
+ hasDouble = true;
+ break;
+ }
+
+ index++;
+
+ if (index < 6)
+ letter = digits[index];
+ }
+
+ return hasDouble;
+ }
+ }
+}
diff --git a/Program.cs b/Program.cs
index 4ee98b7..9bfb434 100644
--- a/Program.cs
+++ b/Program.cs
@@ -6,7 +6,8 @@
{
//Day1.Execute();
//Day2.Execute();
- Day3.Execute();
+ //Day3.Execute();
+ Day4.Execute();
}
}
}