Last active
December 2, 2018 09:25
-
-
Save jyarbro/85edf50a3ff71246158e80741579813a to your computer and use it in GitHub Desktop.
Advent of Code 2018 Day 1
This file contains hidden or 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
class Day1_2018 { | |
public void Part1() { | |
var input = File.ReadAllLines(@"2018\day1.txt"); | |
var output = 0; | |
foreach (var line in input) { | |
var number = Convert.ToInt32(line); | |
output += number; | |
} | |
Console.WriteLine(output); | |
} | |
public void Part2() { | |
var input = File.ReadAllLines(@"2018\day1.txt"); | |
var frequency = 0; | |
var frequencies = new List<int>(); | |
var output = 0; | |
while (output == 0) { | |
foreach (var line in input) { | |
var number = Convert.ToInt32(line); | |
frequency += number; | |
if (frequencies.Contains(frequency)) { | |
output = frequency; | |
break; | |
} | |
frequencies.Add(frequency); | |
} | |
} | |
Console.WriteLine(output); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment