mirror of
https://github.com/ckaczor/Advent2019.git
synced 2026-02-17 02:51:35 -05:00
Day 7 - Part 1
This commit is contained in:
51
Day7/Day7.cs
Normal file
51
Day7/Day7.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Advent
|
||||
{
|
||||
public static class Day7
|
||||
{
|
||||
public static void Execute()
|
||||
{
|
||||
var program = "3,8,1001,8,10,8,105,1,0,0,21,34,43,64,85,98,179,260,341,422,99999,3,9,1001,9,3,9,102,3,9,9,4,9,99,3,9,102,5,9,9,4,9,99,3,9,1001,9,2,9,1002,9,4,9,1001,9,3,9,1002,9,4,9,4,9,99,3,9,1001,9,3,9,102,3,9,9,101,4,9,9,102,3,9,9,4,9,99,3,9,101,2,9,9,1002,9,3,9,4,9,99,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,2,9,4,9,99,3,9,101,1,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,1,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1002,9,2,9,4,9,99,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,99,3,9,101,1,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,99,3,9,101,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,99";
|
||||
|
||||
var phaseList = GetPhaseList();
|
||||
|
||||
int? max = 0;
|
||||
|
||||
var amp = new IntcodeComputer();
|
||||
|
||||
foreach (var phases in phaseList)
|
||||
{
|
||||
var output = amp.Execute(new[] { phases[0], 0 }, program);
|
||||
output = amp.Execute(new[] { phases[1], output.GetValueOrDefault(0) }, program);
|
||||
output = amp.Execute(new[] { phases[2], output.GetValueOrDefault(0) }, program);
|
||||
output = amp.Execute(new[] { phases[3], output.GetValueOrDefault(0) }, program);
|
||||
output = amp.Execute(new[] { phases[4], output.GetValueOrDefault(0) }, program);
|
||||
|
||||
if (output > max)
|
||||
max = output;
|
||||
}
|
||||
|
||||
Console.WriteLine(max);
|
||||
}
|
||||
|
||||
private static IEnumerable<int[]> GetPhaseList()
|
||||
{
|
||||
// This is a stupid brute force way to do it but I'm lazy and it is fast so good enough
|
||||
|
||||
var phaseList = new List<int[]>();
|
||||
|
||||
for (var i = 0; i <= 99999; i++)
|
||||
{
|
||||
var phases = i.ToString("00000").ToCharArray().Select(c => int.Parse(c.ToString())).ToArray();
|
||||
|
||||
if (phases.All(p => p <= 4) && phases.Distinct().Count() == 5)
|
||||
phaseList.Add(phases);
|
||||
}
|
||||
|
||||
return phaseList;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user