Skip to content

Commit 8ebaa61

Browse files
committed
upgrade to .net8
1 parent 5e41138 commit 8ebaa61

File tree

6 files changed

+50
-38
lines changed

6 files changed

+50
-38
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"request": "launch",
1212
"preLaunchTask": "build",
1313
// If you have changed target frameworks, make sure to update the program path.
14-
"program": "${workspaceFolder}/bin/Debug/net7.0/adventofcode.dll",
14+
"program": "${workspaceFolder}/bin/Debug/net8.0/adventofcode.dll",
1515
"args": ["${relativeFileDirname}"],
1616
"cwd": "${workspaceFolder}",
1717
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window

2015/Day04/Solution.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Concurrent;
22
using System.Linq;
3+
using System.Collections.Generic;
34
using System.Security.Cryptography;
45
using System.Text;
56
using System.Threading.Tasks;
@@ -16,7 +17,7 @@ int ParallelFind(string input, string prefix) {
1617
var q = new ConcurrentQueue<int>();
1718

1819
Parallel.ForEach(
19-
Enumerable.Range(0, int.MaxValue),
20+
Numbers(),
2021
() => MD5.Create(),
2122
(i, state, md5) => {
2223
var hashBytes = md5.ComputeHash(Encoding.ASCII.GetBytes(input + i));
@@ -33,4 +34,9 @@ int ParallelFind(string input, string prefix) {
3334
return q.Min();
3435
}
3536

37+
IEnumerable<int> Numbers() {
38+
for (int i=0; ;i++) {
39+
yield return i;
40+
}
41+
}
3642
}

2016/Day05/Solution.cs

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
using System;
12
using System.Collections.Concurrent;
23
using System.Collections.Generic;
4+
using System.Globalization;
35
using System.Linq;
46
using System.Security.Cryptography;
57
using System.Text;
@@ -8,51 +10,52 @@
810
namespace AdventOfCode.Y2016.Day05;
911

1012
[ProblemName("How About a Nice Game of Chess?")]
11-
class Solution : Solver {
13+
class Solution : Solver
14+
{
1215

13-
public object PartOne(string input) {
14-
var st = "";
15-
foreach (var hash in Hashes(input)) {
16-
st += hash[2].ToString("x");
17-
if (st.Length == 8) {
18-
break;
19-
}
20-
}
21-
return st;
16+
public object PartOne(string input)
17+
{
18+
return string.Join("", Hashes(input).Select(hash => hash[5]).Take(8));
2219
}
2320

24-
public object PartTwo(string input) {
25-
var chars = Enumerable.Range(0, 8).Select(_ => (char)255).ToArray();
21+
public object PartTwo(string input)
22+
{
23+
var res = new char[8];
2624
var found = 0;
27-
foreach (var hash in Hashes(input)) {
28-
if (hash[2] < 8) {
29-
var i = hash[2];
30-
if (chars[i] == 255) {
31-
chars[i] = hash[3].ToString("x2")[0];
32-
found++;
33-
if (found == 8) {
34-
break;
35-
}
25+
foreach (var hash in Hashes(input))
26+
{
27+
var idx = hash[5] - '0';
28+
if (0 <= idx && idx < 8 && res[idx] == 0)
29+
{
30+
res[idx] = hash[6];
31+
found++;
32+
if (found == 8) {
33+
break;
3634
}
37-
3835
}
36+
3937
}
40-
return string.Join("", chars);
38+
return string.Join("", res);
4139
}
4240

43-
public IEnumerable<byte[]> Hashes(string input) {
41+
public IEnumerable<string> Hashes(string input)
42+
{
4443

45-
for (var i = 0; i < int.MaxValue; i++) {
46-
var q = new ConcurrentQueue<(int i, byte[] hash)>();
44+
for (var i = 0; i < int.MaxValue; i++)
45+
{
46+
var q = new ConcurrentQueue<(int i, string hash)>();
4747

4848
Parallel.ForEach(
49-
Enumerable.Range(i, int.MaxValue - i),
49+
NumbersFrom(i),
5050
() => MD5.Create(),
51-
(i, state, md5) => {
51+
(i, state, md5) =>
52+
{
5253
var hash = md5.ComputeHash(Encoding.ASCII.GetBytes(input + i));
54+
var hashString = string.Join("", hash.Select(x => x.ToString("x2")));
5355

54-
if (hash[0] == 0 && hash[1] == 0 && hash[2] < 16) {
55-
q.Enqueue((i, hash));
56+
if (hashString.StartsWith("00000"))
57+
{
58+
q.Enqueue((i, hashString));
5659
state.Stop();
5760
}
5861
return md5;
@@ -64,4 +67,9 @@ public IEnumerable<byte[]> Hashes(string input) {
6467
yield return item.hash;
6568
}
6669
}
70+
71+
IEnumerable<int> NumbersFrom(int i)
72+
{
73+
for (;;) yield return i++;
74+
}
6775
}

Lib/Generator/ReadmeGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public string Generate(int firstYear, int lastYear) {
3838
>
3939
> ## Dependencies
4040
41-
> - This project is based on `.NET 7` and `C# 11`. It should work on Windows, Linux and OS-X.
41+
> - This project is based on `.NET 8` and `C# 12`. It should work on Windows, Linux and OS-X.
4242
> - `AngleSharp` is used for problem download.
4343
4444
> ## Running

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ start working on your own. The framework part is pretty stable and you get testi
3030

3131
## Dependencies
3232

33-
- This project is based on `.NET 7` and `C# 11`. It should work on Windows, Linux and OS-X.
33+
- This project is based on `.NET 8` and `C# 12`. It should work on Windows, Linux and OS-X.
3434
- `AngleSharp` is used for problem download.
3535

3636
## Running

adventofcode.csproj

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
4-
<TargetFramework>net7.0</TargetFramework>
5-
<LangVersion>11</LangVersion>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<LangVersion>12</LangVersion>
66
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
77
</PropertyGroup>
88
<ItemGroup>
99
<PackageReference Include="AngleSharp" Version="0.14.0" />
1010
<PackageReference Include="AngleSharp.Css" Version="0.14.0" />
1111
<PackageReference Include="Microsoft.CodeAnalysis" Version="3.8.0" />
12-
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
13-
<PackageReference Include="System.ValueTuple" Version="4.4.0" />
1412
</ItemGroup>
1513
</Project>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy