My solutions for Advent of Code.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
adventofcode/2019/Day2/Part2.cs

46 lines
1008 B

using System;
namespace Part2 {
public class calcInputs {
public void bruteforce( int[] input, int find ) {
int noun, verb;
int[] input_c = input; // keep a version of the original
int[] output = new int[input_c.Length];
bool success = false;
int min = 0; // min and max for the input values
int max = 99; //
Part1.compile compile = new Part1.compile();
for( int i = 0; i < max + 1; i++ ) {
input = input_c; // reset the intcode
noun = Math.Clamp( i, min, max );
verb = Math.Clamp( i, min, max );
input[1] = noun;
input[2] = verb;
Console.WriteLine( "Checking: {0}, {1} for {2}", noun, verb, find );
output = compile.intcode( input );
Console.WriteLine( input[0] );
if( output[0] == find ) {
Console.WriteLine( "({0}) Found: {1}, {2}", find, noun, verb );
success = true;
break;
}
}
Console.WriteLine("");
if( success == false ) {
Console.WriteLine( "Nothing found :(" );
return;
}
}
}
}