From cff9ac2e79c50456d96afc112d22e12660b10bfe Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Wed, 2 Dec 2020 16:26:31 +0100 Subject: Renamed files for first day --- 2020/1/Makefile | 10 +++++----- 2020/1/run.cs | 59 --------------------------------------------------------- 2020/1/solve.cs | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 64 deletions(-) delete mode 100644 2020/1/run.cs create mode 100644 2020/1/solve.cs diff --git a/2020/1/Makefile b/2020/1/Makefile index c678ba8..6ed5323 100644 --- a/2020/1/Makefile +++ b/2020/1/Makefile @@ -1,10 +1,10 @@ -.PHONY: run.cs +.PHONY: solve.cs -run.exe: run.cs +solve.exe: solve.cs @mcs $+ clean: - @rm -f run.exe + @rm -f solve.exe -run: run.exe - @mono run.exe +run: solve.exe + @mono $+ diff --git a/2020/1/run.cs b/2020/1/run.cs deleted file mode 100644 index fb2f6ae..0000000 --- a/2020/1/run.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System; -using System.IO; -using System.Linq; - -namespace AOC -{ - internal class Run - { - private static int[] Double(int[] arr, int low, int result) - { - int high = arr.Length - 1; - - int sum = arr[low] + arr[high]; - while (low < high && sum != result) - { - if (sum < result) - low++; - else - high--; - - sum = arr[low] + arr[high]; - } - - if (low == high) - { - return new[] {0, 0}; - } - - return new[] {arr[low], arr[high]}; - } - - private static int[] Triple(int[] arr, int result) - { - for (int i = 0; i < arr.Length; i++) - { - int remainder = result - arr[i]; - int[] d = Double(arr, i, remainder); - if (d.Sum() != 0) - { - return new[] {arr[i], d[0], d[1]}; - } - } - - return new[] {0, 0}; - } - - public static void Main(string[] args) - { - string text = File.ReadAllText("input"); - string[] numsStr = text.Split('\n'); - numsStr[numsStr.Length - 1] = "2020"; // Some weird newline character ig - int[] nums = Array.ConvertAll(numsStr, int.Parse).OrderBy(i => i).ToArray(); - int[] d = Double(nums, 0, 2020); - int[] t = Triple(nums, 2020); - Console.WriteLine(d[0] * d[1]); - Console.WriteLine(t[0] * t[1] * t[2]); - } - } -} diff --git a/2020/1/solve.cs b/2020/1/solve.cs new file mode 100644 index 0000000..fb2f6ae --- /dev/null +++ b/2020/1/solve.cs @@ -0,0 +1,59 @@ +using System; +using System.IO; +using System.Linq; + +namespace AOC +{ + internal class Run + { + private static int[] Double(int[] arr, int low, int result) + { + int high = arr.Length - 1; + + int sum = arr[low] + arr[high]; + while (low < high && sum != result) + { + if (sum < result) + low++; + else + high--; + + sum = arr[low] + arr[high]; + } + + if (low == high) + { + return new[] {0, 0}; + } + + return new[] {arr[low], arr[high]}; + } + + private static int[] Triple(int[] arr, int result) + { + for (int i = 0; i < arr.Length; i++) + { + int remainder = result - arr[i]; + int[] d = Double(arr, i, remainder); + if (d.Sum() != 0) + { + return new[] {arr[i], d[0], d[1]}; + } + } + + return new[] {0, 0}; + } + + public static void Main(string[] args) + { + string text = File.ReadAllText("input"); + string[] numsStr = text.Split('\n'); + numsStr[numsStr.Length - 1] = "2020"; // Some weird newline character ig + int[] nums = Array.ConvertAll(numsStr, int.Parse).OrderBy(i => i).ToArray(); + int[] d = Double(nums, 0, 2020); + int[] t = Triple(nums, 2020); + Console.WriteLine(d[0] * d[1]); + Console.WriteLine(t[0] * t[1] * t[2]); + } + } +} -- cgit v1.2.3