Skip to content

Instantly share code, notes, and snippets.

@jyarbro
Last active December 2, 2018 09:25
Show Gist options
  • Save jyarbro/85edf50a3ff71246158e80741579813a to your computer and use it in GitHub Desktop.
Save jyarbro/85edf50a3ff71246158e80741579813a to your computer and use it in GitHub Desktop.
Advent of Code 2018 Day 1
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