mirror of
https://github.com/ckaczor/Advent2019.git
synced 2026-02-16 10:48:30 -05:00
Some reorg so I can have the original inputs
This commit is contained in:
61
Day2/Day2.cs
Normal file
61
Day2/Day2.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Advent
|
||||
{
|
||||
public static class Day2
|
||||
{
|
||||
public static void Execute()
|
||||
{
|
||||
for (var noun = 0; noun <= 99; noun++)
|
||||
for (var verb = 0; verb <= 99; verb++)
|
||||
{
|
||||
var result = Calculate(noun, verb);
|
||||
|
||||
if (result == 19690720)
|
||||
Console.WriteLine(100 * noun + verb);
|
||||
}
|
||||
}
|
||||
|
||||
private static int Calculate(int noun, int verb)
|
||||
{
|
||||
var lines = File.ReadAllLines(@".\Day2\input.txt");
|
||||
|
||||
var codes = lines[0].Split(',').Select(int.Parse).ToArray();
|
||||
|
||||
codes[1] = noun;
|
||||
codes[2] = verb;
|
||||
|
||||
var position = 0;
|
||||
var done = false;
|
||||
|
||||
while (!done)
|
||||
{
|
||||
switch (codes[position])
|
||||
{
|
||||
case 1:
|
||||
codes[codes[position + 3]] = codes[codes[position + 1]] + codes[codes[position + 2]];
|
||||
|
||||
position += 4;
|
||||
|
||||
break;
|
||||
|
||||
case 2:
|
||||
codes[codes[position + 3]] = codes[codes[position + 1]] * codes[codes[position + 2]];
|
||||
|
||||
position += 4;
|
||||
|
||||
break;
|
||||
|
||||
case 99:
|
||||
done = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return codes[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
1
Day2/input.txt
Normal file
1
Day2/input.txt
Normal file
@@ -0,0 +1 @@
|
||||
1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,1,9,19,1,5,19,23,1,6,23,27,1,27,10,31,1,31,5,35,2,10,35,39,1,9,39,43,1,43,5,47,1,47,6,51,2,51,6,55,1,13,55,59,2,6,59,63,1,63,5,67,2,10,67,71,1,9,71,75,1,75,13,79,1,10,79,83,2,83,13,87,1,87,6,91,1,5,91,95,2,95,9,99,1,5,99,103,1,103,6,107,2,107,13,111,1,111,10,115,2,10,115,119,1,9,119,123,1,123,9,127,1,13,127,131,2,10,131,135,1,135,5,139,1,2,139,143,1,143,5,0,99,2,0,14,0
|
||||
Reference in New Issue
Block a user