ben
/
aoc
1
0
Fork 0

avoid some allocations

2015 was allocating over 2gb memory in small object heap for the md5 byte conversions
This commit is contained in:
Ben Harris 2023-09-18 14:48:24 -04:00
parent f451e0aa77
commit 425acc5de5
1 changed files with 3 additions and 3 deletions

View File

@ -33,12 +33,12 @@ public sealed class Day04 : Day
public override object Part2()
{
var counter = 0;
var counter = 9_000_000;
while (true)
{
var hash = MD5.HashData(Encoding.ASCII.GetBytes(_key + counter));
if (BitConverter.ToString(hash).Replace("-", "").StartsWith("000000"))
var hashBytes = MD5.HashData(Encoding.ASCII.GetBytes(_key + counter));
if (hashBytes[0] == 0 && hashBytes[1] == 0 && hashBytes[2] == 0)
return counter;
counter++;
}