Day 2 Part 2 stuff

master
gnomerd 5 years ago
parent 8f0b6f102c
commit 6a685af00c
  1. 12
      2019/Day2/Part1.cs
  2. 46
      2019/Day2/Part2.cs
  3. 6
      2019/Day2/Program.cs
  4. BIN
      2019/Day2/bin/Debug/netcoreapp2.2/Day2.dll
  5. BIN
      2019/Day2/bin/Debug/netcoreapp2.2/Day2.pdb
  6. 2
      2019/Day2/input.txt
  7. 2
      2019/Day2/obj/Debug/netcoreapp2.2/Day2.csproj.CoreCompileInputs.cache
  8. BIN
      2019/Day2/obj/Debug/netcoreapp2.2/Day2.dll
  9. BIN
      2019/Day2/obj/Debug/netcoreapp2.2/Day2.pdb

@ -11,7 +11,7 @@ namespace Part1 {
}
public class compile {
public const int NEXT = 4; // steps per opcode
public bool writedebug = true;
public bool writedebug = !false;
public vars.intcode getOpcode( int opcode ) {
return (vars.intcode)opcode; // return the opcode, if 1 then return "ADD" etc
@ -29,15 +29,15 @@ namespace Part1 {
if( opcode == vars.intcode.ADD ) {
int sum = array[array[i+1]] + array[array[i+2]]; // get the two values
writepos = array[i+3]; // get the write pos
writepos = Math.Clamp( array[i+3], 0, array.Length - 1 ); // get the write pos
Debug( "ADD (" + i.ToString() + "/" + array.Length.ToString() + ") " + "Sum=" + sum.ToString() + " at i=" + writepos.ToString() );
array[writepos] = sum; // write the value
} else if( opcode == vars.intcode.MULT ) {
int product = array[array[i+1]] * array[array[i+2]]; // get the two values
writepos = array[i+3];
int product = array[array[i+1]] * array[array[i+2]]; // get the product
writepos = Math.Clamp( array[i+3], 0, array.Length - 1 );
Debug( "MULT (" + i.ToString() + "/" + array.Length.ToString() + ") " + "Product=" + product.ToString() + " at i=" + writepos.ToString() );
array[writepos] = product; // write the value
@ -51,13 +51,13 @@ namespace Part1 {
public int[] intcode( int[] input ) {
int[] output = input; // make an instanse of the input where we can change stuff
Console.WriteLine( "\n----Running Intcode----" );
Debug( "\n----Running Intcode----" );
for( int i = 0; i < output.Length; i+= NEXT ) {
vars.intcode opcode = getOpcode(input[i]);
output = runopcode( output, i, opcode );
if( (int)output[i] == 99 ) { break; }
}
Console.WriteLine( "----Intcode finished----\n" );
Debug( "----Intcode finished----\n" );
return output;
}
}

@ -0,0 +1,46 @@
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;
}
}
}
}

@ -30,6 +30,12 @@ namespace Day2 {
Console.WriteLine( "--End of Intcode result--\n" );
Console.WriteLine( "Part 1 result: " + output[0].ToString() ); // get the pos 0
//// Part 2 stuff ////
Part2.calcInputs calcInputs = new Part2.calcInputs();
calcInputs.bruteforce( intcodes, 9801 );
}
}
}

@ -1 +1 @@
1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,1,10,19,1,19,6,23,2,23,13,27,1,27,5,31,2,31,10,35,1,9,35,39,1,39,9,43,2,9,43,47,1,5,47,51,2,13,51,55,1,55,9,59,2,6,59,63,1,63,5,67,1,10,67,71,1,71,10,75,2,75,13,79,2,79,13,83,1,5,83,87,1,87,6,91,2,91,13,95,1,5,95,99,1,99,2,103,1,103,6,0,99,2,14,0,0
2,0,0,0,99,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

@ -1 +1 @@
9fe783133b7f321bdac60ee865e123f6adce08e3
f79d1ed33da9ca6da7e131988eb0964470e8edf6

Loading…
Cancel
Save