Skip to content

Commit

Permalink
make c# from 2016 run in dotnet 9
Browse files Browse the repository at this point in the history
  • Loading branch information
Magiczne committed Nov 17, 2024
1 parent 76528de commit 6200a15
Show file tree
Hide file tree
Showing 93 changed files with 365 additions and 1,575 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"name": "Launch Go Package",
"type": "go",
"request": "launch",
"mode": "auto",
Expand Down
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

10 changes: 10 additions & 0 deletions 2016/01/01.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
File renamed without changes.
2 changes: 1 addition & 1 deletion 2016/Day 01/Point.cs → 2016/01/Point.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public Point(int x, int y)
Y = y;
}

public bool Equals(Point other)
public bool Equals(Point? other)
{
return other != null && (X == other.X && Y == other.Y);
}
Expand Down
154 changes: 76 additions & 78 deletions 2016/Day 01/Program.cs → 2016/01/Program.cs
Original file line number Diff line number Diff line change
@@ -1,79 +1,77 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AdventOfCode
{
internal static class Program
{
private static string _input;

private static Direction _currentDirection = Direction.North;

private static int _distanceVertical;
private static int _distanceHorizontal;

private static bool _crossingFound;
private static Point _firstCrossed;
private static readonly List<Point> Visited = new List<Point>();

private static void Main()
{
_input = File.ReadAllText("../../input.txt");

var instructions = _input.Split(new[] {", "}, StringSplitOptions.None);

foreach (var i in instructions)
{
if (i[0] == 'R') _currentDirection++;
else _currentDirection--;

if (_currentDirection > (Direction) 4) _currentDirection = Direction.North;
if (_currentDirection < (Direction) 1) _currentDirection = Direction.West;

var steps = int.Parse(i.Substring(1));

for (var j = 1; j <= steps; j++)
{
switch (_currentDirection)
{
case Direction.North:
_distanceVertical++;
break;
case Direction.West:
_distanceHorizontal--;
break;
case Direction.South:
_distanceVertical--;
break;
case Direction.East:
_distanceHorizontal++;
break;
default:
throw new ArgumentOutOfRangeException();
}

var point = new Point(_distanceHorizontal, _distanceVertical);

if (!_crossingFound)
{
if (Visited.Contains(point))
{
_firstCrossed = point;
_crossingFound = true;
}
}

Visited.Add(point);
}
}

Console.WriteLine("Answers: ");
Console.WriteLine("*: " + Visited.Last().Distance);
Console.Write("**: " + _firstCrossed.Distance);

Console.Read();
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AdventOfCode
{
internal static class Program
{
private static string _input = "";

private static Direction _currentDirection = Direction.North;

private static int _distanceVertical;
private static int _distanceHorizontal;

private static bool _crossingFound;
private static Point? _firstCrossed;
private static readonly List<Point> Visited = new List<Point>();

private static void Main()
{
_input = File.ReadAllText("2016/01/input.txt");

var instructions = _input.Split(new[] {", "}, StringSplitOptions.None);

foreach (var i in instructions)
{
if (i[0] == 'R') _currentDirection++;
else _currentDirection--;

if (_currentDirection > (Direction) 4) _currentDirection = Direction.North;
if (_currentDirection < (Direction) 1) _currentDirection = Direction.West;

var steps = int.Parse(i.Substring(1));

for (var j = 1; j <= steps; j++)
{
switch (_currentDirection)
{
case Direction.North:
_distanceVertical++;
break;
case Direction.West:
_distanceHorizontal--;
break;
case Direction.South:
_distanceVertical--;
break;
case Direction.East:
_distanceHorizontal++;
break;
default:
throw new ArgumentOutOfRangeException();
}

var point = new Point(_distanceHorizontal, _distanceVertical);

if (!_crossingFound)
{
if (Visited.Contains(point))
{
_firstCrossed = point;
_crossingFound = true;
}
}

Visited.Add(point);
}
}

Console.WriteLine("Answers: ");
Console.WriteLine("*: " + Visited.Last().Distance);
Console.Write("**: " + _firstCrossed?.Distance);
}
}
}
File renamed without changes.
10 changes: 10 additions & 0 deletions 2016/02/02.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
4 changes: 1 addition & 3 deletions 2016/Day 02/Program.cs → 2016/02/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private static void Main()
{
Console.WriteLine("Answers: ");
Console.Write("*: ");
foreach (var key in File.ReadAllLines("../../input.txt"))
foreach (var key in File.ReadAllLines("2016/02/input.txt"))
{
Data.Add(key);
Console.Write(ProcessSequenceOneStar(key));
Expand All @@ -38,8 +38,6 @@ private static void Main()
{
Console.Write(ProcesSequenceTwoStars(key));
}

Console.Read();
}

private static int ProcessSequenceOneStar(string key)
Expand Down
File renamed without changes.
10 changes: 10 additions & 0 deletions 2016/03/03.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
6 changes: 2 additions & 4 deletions 2016/Day 03/Program.cs → 2016/03/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ private static void Main()
{
var solution = new Solution();
solution.Solve();

Console.Read();
}
}

Expand Down Expand Up @@ -52,11 +50,11 @@ public void Solve()

private void GetInput()
{
using (var stream = File.OpenRead("../../input.txt"))
using (var stream = File.OpenRead("2016/03/input.txt"))
{
using (var streamReader = new StreamReader(stream, Encoding.UTF8))
{
string line;
string? line = null;

while ((line = streamReader.ReadLine()) != null)
{
Expand Down
File renamed without changes.
10 changes: 10 additions & 0 deletions 2016/04/04.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
4 changes: 1 addition & 3 deletions 2016/Day 04/Program.cs → 2016/04/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ private static void Main()
{
var solution = new Solution();
solution.Solve();

Console.Read();
}
}

Expand Down Expand Up @@ -42,7 +40,7 @@ public void Solve()

private void GetInput()
{
var data = File.ReadAllLines("../../input.txt");
var data = File.ReadAllLines("2016/04/input.txt");

foreach (var line in data)
{
Expand Down
2 changes: 1 addition & 1 deletion 2016/Day 04/Room.cs → 2016/04/Room.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Day_4
internal class Room
{
private readonly List<string> _encryptedName = new List<string>();
private string _checksum;
private string _checksum = "";

private readonly Dictionary<char, int> _lettersFreq = new Dictionary<char, int>();

Expand Down
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions 2016/05/05.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
4 changes: 1 addition & 3 deletions 2016/Day 05/Program.cs → 2016/05/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ internal static class Program
private static void Main()
{
var solution = new Solution();
//solution.Solve();
solution.Solve();
solution.SolveTwoStars();

Console.Read();
}
}

Expand Down
File renamed without changes.
10 changes: 10 additions & 0 deletions 2016/06/06.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
4 changes: 1 addition & 3 deletions 2016/Day 06/Program.cs → 2016/06/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ private static void Main()
{
var solution = new Solution();
solution.Solve();

Console.Read();
}
}

Expand All @@ -23,7 +21,7 @@ internal class Solution

public Solution()
{
_data = File.ReadAllLines("../../input.txt").ToList();
_data = File.ReadAllLines("2016/06/input.txt").ToList();
}

public void Solve()
Expand Down
File renamed without changes.
10 changes: 10 additions & 0 deletions 2016/07/07.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
File renamed without changes.
4 changes: 1 addition & 3 deletions 2016/Day 07/Program.cs → 2016/07/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ private static void Main()

var solution = new Solution();
solution.Solve();

Console.Read();
}
}

Expand All @@ -24,7 +22,7 @@ internal class Solution

public void Solve()
{
var lines = File.ReadAllLines("../../input.txt");
var lines = File.ReadAllLines("2016/07/input.txt");

foreach (var line in lines)
{
Expand Down
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions 2016/08/08.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
File renamed without changes.
2 changes: 0 additions & 2 deletions 2016/Day 08/Program.cs → 2016/08/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ private static void Main()
{
var solution = new Solution();
solution.Solve();

Console.Read();
}
}
}
File renamed without changes.
Loading

0 comments on commit 6200a15

Please sign in to comment.