master
gnomerd 5 years ago
parent 6432da5ed6
commit c9714949f6
  1. 32
      2019/Day2/Part1.cs
  2. BIN
      2019/Day2/bin/Debug/netcoreapp2.2/Day2.dll
  3. BIN
      2019/Day2/bin/Debug/netcoreapp2.2/Day2.pdb
  4. BIN
      2019/Day2/obj/Debug/netcoreapp2.2/Day2.dll
  5. BIN
      2019/Day2/obj/Debug/netcoreapp2.2/Day2.pdb

@ -8,25 +8,47 @@ namespace Part1 {
MULT = 2,
STOP = 99
}
public int NEXT = 4; // steps per opcode
}
public class compile {
public int NEXT = 4; // steps per opcode
public vars.intcode getOpcode( int opcode ) {
return (vars.intcode)opcode; // return the opcode, if 1 then return "ADD" etc
}
public void runopcode( int index, vars.intcode opcode ) {
public bool isOpcode( int i ) {
return false;
}
public int[] runopcode( int[] array, int i, vars.intcode opcode ) {
int writepos = array[array[i+3]]; // get the write pos
if( opcode == vars.intcode.ADD ) {
int sum = array[array[i+1]] + array[array[i+2]]; // get the two values
Console.WriteLine( "ADD (" + i.ToString() + ") " + "Sum=" + sum.ToString() + " at i=" + array[i+3].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
Console.WriteLine( "MULT (" + i.ToString() + ") " + "Product=" + product.ToString() + " at i=" + array[i+3].ToString() );
array[writepos] = product; // write the value
} else if ( opcode == vars.intcode.STOP ) {
}
return array;
}
public int[] intcode( int[] input ) {
int[] output = input; // make an instanse of the input where we can change stuff
for( int i = 0; i < input.Length; i++ ) {
//int opcode_count = 0;
for( int i = 0; i < output.Length; i+= NEXT ) {
Console.WriteLine(i);
vars.intcode opcode = getOpcode(input[i]);
//Console.WriteLine( getOpcode(input[i]).ToString() + " | " + i.ToString() );
runopcode( i, opcode );
output = runopcode( output, i, opcode );
//Console.WriteLine( getOpcode(output[i]).ToString() + " | " + i.ToString() );
}
return output;
}

Loading…
Cancel
Save