-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
284c3c0
commit 1ffba41
Showing
5 changed files
with
47 additions
and
25 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
namespace AoC2018.Solutions.Day08 | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
public static class NodeExtensions | ||
{ | ||
public static int MetadataChecksum(this Node[] nodes) | ||
{ | ||
return nodes.Sum(x => x.MetadataChecksum()); | ||
} | ||
|
||
public static int MetadataChecksum(this Node node) | ||
{ | ||
return node.Metadata.Sum() + node.Children.MetadataChecksum(); | ||
} | ||
|
||
public static int Value(this Node node) | ||
{ | ||
if (node.Children.Length == 0) | ||
{ | ||
return node.Metadata.Sum(); | ||
} | ||
|
||
return node.Metadata.Sum(x => (x > 0 && x <= node.Children.Length) ? node.Children[x - 1].Value() : 0); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace AoC2018.Solutions.Day08 | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
public class Part02 : ISolution | ||
{ | ||
public string Solve(string input) | ||
{ | ||
var licenceFile = LicenceFile.Parse(input); | ||
|
||
return licenceFile.RootNodes[0].Value().ToString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters