Skip to content

Commit

Permalink
.net code 3.1
Browse files Browse the repository at this point in the history
remove newtonsoft dependency
  • Loading branch information
encse committed Dec 5, 2019
1 parent b3a2878 commit 9d3e132
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.0/adventofcode.dll",
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/adventofcode.dll",
"args": ["last"],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
Expand Down
20 changes: 11 additions & 9 deletions 2015/Day12/Solution.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json.Linq;
using System.Text.Json;

namespace AdventOfCode.Y2015.Day12 {

Expand All @@ -18,16 +17,19 @@ public IEnumerable<object> Solve(string input) {
int PartTwo(string input) => Solve(input, true);

int Solve(string input, bool skipRed) {
int Traverse(JToken t) {
return t switch {
JObject v when skipRed && v.Values().Contains("red") => 0,
JObject v => v.Values().Select(Traverse).Sum(),
JArray v => v.Select(Traverse).Sum(),
JValue v when v.Type == JTokenType.Integer => (int)v,
int Traverse(JsonElement t) {
return t.ValueKind switch
{
JsonValueKind.Object when skipRed && t.EnumerateObject().Any(
p => p.Value.ValueKind == JsonValueKind.String && p.Value.GetString() == "red") => 0,
JsonValueKind.Object => t.EnumerateObject().Select(p => Traverse(p.Value)).Sum(),
JsonValueKind.Array => t.EnumerateArray().Select(Traverse).Sum(),
JsonValueKind.Number => t.GetInt32(),
_ => 0
};
}
return Traverse(JToken.Parse(input));

return Traverse(JsonDocument.Parse(input).RootElement);
}
}
}
3 changes: 1 addition & 2 deletions Lib/Generator/ReadmeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public string Generate(int firstYear, int lastYear) {
> ## Dependencies
> - This project is based on `.NET Core 3.0`. It should work on Windows, Linux and OS X.
> - `Newtonsoft.Json` for JSON parsing
> - This project is based on `.NET Core 3.1`. It should work on Windows, Linux and OS X.
> - `HtmlAgilityPack.NetCore` is used for problem download.
> ## Running
Expand Down
4 changes: 2 additions & 2 deletions adventofcode.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis" Version="2.10.0" />
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
<PackageReference Include="System.ValueTuple" Version="4.4.0" />
<PackageReference Include="HtmlAgilityPack.NetCore" Version="1.5.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
</ItemGroup>
</Project>

0 comments on commit 9d3e132

Please sign in to comment.