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

45 lines
932 B

using System;
namespace Part2 {
public class calcInputs {
public void bruteforce( int[] input, int find ) {
int noun, verb;
int[] input_c; // keep a version of the original
int[] output = new int[input.Length];
bool success = false;
int min = 0; // min and max for the input values
int max = 6; //
Part1.compile compile = new Part1.compile();
for( int i = 0; i < max + 1; i++ ) {
input_c = input; // reset the intcode
noun = Math.Clamp( i, min, max );
verb = Math.Clamp( i, min, max );
input_c[1] = noun;
input_c[2] = verb;
output = compile.intcode( input_c );
Console.WriteLine( input_c[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;
}
}
}
}