Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit53b32b6

Browse files
committed
Add a vectorized compare for day 25
1 parentfaeafdf commit53b32b6

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

‎csharp/2024/Day25.cs‎

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
usingSystem;
22
usingSystem.Collections.Generic;
33
usingSystem.Linq;
4+
usingSystem.Numerics;
5+
usingSystem.Runtime.Intrinsics;
46
usingAdventOfCode.Util;
57

68
namespaceAdventOfCode2024
79
{
810
internalclassDay25
911
{
10-
privatestatic(List<int[]>Locks,List<int[]>Keys)Load()
12+
privatestatic(List<short[]>Locks,List<short[]>Keys)Load()
1113
{
1214
List<string>list=newList<string>();
13-
List<int[]>locks=new();
14-
List<int[]>keys=new();
15+
List<short[]>locks=new();
16+
List<short[]>keys=new();
1517

1618
foreach(stringsinData.Enumerate().Append(""))
1719
{
1820
if(string.IsNullOrEmpty(s))
1921
{
20-
int[]lockOrKey=newint[5];
22+
short[]lockOrKey=newshort[Vector<short>.Count];
2123

2224
if(list[0].IndexOf('.')==-1)
2325
{
24-
for(intx=0;x<lockOrKey.Length;x++)
26+
for(intx=0;x<5;x++)
2527
{
2628
for(inty=1;y<list.Count;y++)
2729
{
@@ -36,7 +38,7 @@ private static (List<int[]> Locks, List<int[]> Keys) Load()
3638
}
3739
else
3840
{
39-
for(intx=0;x<lockOrKey.Length;x++)
41+
for(intx=0;x<5;x++)
4042
{
4143
for(inty=list.Count-2;y>=0;y--)
4244
{
@@ -63,12 +65,12 @@ private static (List<int[]> Locks, List<int[]> Keys) Load()
6365

6466
internalstaticvoidProblem1()
6567
{
66-
(List<int[]>locks,List<int[]>keys)=Load();
68+
(List<short[]>locks,List<short[]>keys)=Load();
6769
longret=0;
6870

69-
foreach(int[]lckinlocks)
71+
foreach(short[]lckinlocks)
7072
{
71-
foreach(int[]keyinkeys)
73+
foreach(short[]keyinkeys)
7274
{
7375
booladd=true;
7476

@@ -91,8 +93,26 @@ internal static void Problem1()
9193
Console.WriteLine(ret);
9294
}
9395

94-
internalstaticvoidProblem2x()
96+
internalstaticvoidProblem3()
9597
{
98+
(List<short[]>locks,List<short[]>keys)=Load();
99+
longret=0;
100+
Vector128<short>safeLimit=Vector128.Create<short>(5);
101+
102+
foreach(short[]lckinlocks)
103+
{
104+
foreach(short[]keyinkeys)
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
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp