11using System ;
22using System . Collections . Generic ;
33using System . Linq ;
4+ using System . Numerics ;
5+ using System . Runtime . Intrinsics ;
46using AdventOfCode . Util ;
57
68namespace AdventOfCode2024
79{
810internal class Day25
911{
10- private static ( List < int [ ] > Locks , List < int [ ] > Keys ) Load ( )
12+ private static ( List < short [ ] > Locks , List < short [ ] > Keys ) Load ( )
1113{
1214List < string > list = new List < string > ( ) ;
13- List < int [ ] > locks = new ( ) ;
14- List < int [ ] > keys = new ( ) ;
15+ List < short [ ] > locks = new ( ) ;
16+ List < short [ ] > keys = new ( ) ;
1517
1618foreach ( string s in Data . Enumerate ( ) . Append ( "" ) )
1719{
1820if ( string . IsNullOrEmpty ( s ) )
1921{
20- int [ ] lockOrKey = new int [ 5 ] ;
22+ short [ ] lockOrKey = new short [ Vector < short > . Count ] ;
2123
2224if ( list [ 0 ] . IndexOf ( '.' ) == - 1 )
2325{
24- for ( int x = 0 ; x < lockOrKey . Length ; x ++ )
26+ for ( int x = 0 ; x < 5 ; x ++ )
2527{
2628for ( int y = 1 ; y < list . Count ; y ++ )
2729{
@@ -36,7 +38,7 @@ private static (List<int[]> Locks, List<int[]> Keys) Load()
3638}
3739else
3840{
39- for ( int x = 0 ; x < lockOrKey . Length ; x ++ )
41+ for ( int x = 0 ; x < 5 ; x ++ )
4042{
4143for ( int y = list . Count - 2 ; y >= 0 ; y -- )
4244{
@@ -63,12 +65,12 @@ private static (List<int[]> Locks, List<int[]> Keys) Load()
6365
6466internal static void Problem1 ( )
6567{
66- ( List < int [ ] > locks , List < int [ ] > keys ) = Load ( ) ;
68+ ( List < short [ ] > locks , List < short [ ] > keys ) = Load ( ) ;
6769long ret = 0 ;
6870
69- foreach ( int [ ] lck in locks )
71+ foreach ( short [ ] lck in locks )
7072{
71- foreach ( int [ ] key in keys )
73+ foreach ( short [ ] key in keys )
7274{
7375bool add = true ;
7476
@@ -91,8 +93,26 @@ internal static void Problem1()
9193Console . WriteLine ( ret ) ;
9294}
9395
94- internal static void Problem2x ( )
96+ internal static void Problem3 ( )
9597{
98+ ( List < short [ ] > locks , List < short [ ] > keys ) = Load ( ) ;
99+ long ret = 0 ;
100+ Vector128 < short > safeLimit = Vector128 . Create < short > ( 5 ) ;
101+
102+ foreach ( short [ ] lck in locks )
103+ {
104+ foreach ( short [ ] key in keys )
105+ {
106+ Vector128 < short > sum = Vector128 . Create < short > ( lck ) + Vector128 . Create < short > ( key ) ;
107+
108+ if ( Vector128 . LessThanOrEqualAll ( sum , safeLimit ) )
109+ {
110+ ret ++ ;
111+ }
112+ }
113+ }
114+
115+ Console . WriteLine ( ret ) ;
96116}
97117}
98118}