Solved day 1 part 2

master
AlmTech Software 5 years ago
parent fed63f7f62
commit 6794563f43
  1. 51
      2019/Day1/Part2.cs
  2. 10
      2019/Day1/Program.cs
  3. BIN
      2019/Day1/bin/Debug/netcoreapp2.2/Day1.dll
  4. BIN
      2019/Day1/bin/Debug/netcoreapp2.2/Day1.pdb
  5. BIN
      2019/Day1/obj/Debug/netcoreapp2.2/Day1.dll
  6. BIN
      2019/Day1/obj/Debug/netcoreapp2.2/Day1.pdb

@ -1,53 +1,30 @@
using System;
using System.Collections.Generic;
using System.Data;
namespace Part2 {
public class Get {
public List<int[]> AllFuelModules( int[] modules ) {
public int[,] AllFuelModules( int[] modules ) {
// declare the variables
List<int[]> returnList = new List<int[]>();
int[] modulesofmodule = new int[999]; // should be big enough xd
float mod;
int placeholder;
int[,] returnarray = new int[modules.Length, 999]; // make a 2D array, 999 is a bit overkill but it will work I guess
int count = -1; // dumb method ikr
for( int i = 0; i < modules.Length; i++ ) { // loop through the modules
Console.WriteLine("----");
mod = (float)modules[i]; // make it a double
placeholder = (int)mod;
//modulesofmodule[count] = (int)mod;
while( placeholder > 0 ) { // if the placeholder is greater than 0
count++;
placeholder = (int)Math.Floor( mod/3 ) - 2; // then do the fuel calc for the fuel module
if( placeholder < 0 ) { // if less than 0 then just make it 0
placeholder = 0;
modulesofmodule[count] = (int)placeholder; // add it to its own little list
} else {
modulesofmodule[count] = (int)placeholder; // same here
}
Console.WriteLine( count.ToString() + " val: " + placeholder.ToString() );
for( int i = 0; i < modules.Length; i++ ) { // loop through each module
// i = module index
returnarray[i, 0] = modules[i]; // set the first to be the module
for( int mod_i = 1; returnarray[i, mod_i - 1] > 0; mod_i++ ) { // start at the second since we declared the first one above
returnarray[i, mod_i] = (int)Math.Floor( (float)returnarray[i, mod_i - 1] / 3 ) - 2;
if( returnarray[i, mod_i] < 0 ) { returnarray[i, mod_i] = 0; } // if less than 0 then just make it 0
}
count = -1; // reset the count
Console.WriteLine( "ID: " + i.ToString() );
returnList.Add( modulesofmodule ); // place the array in the list for that module
}
return returnList; // return the complete list
return returnarray; // return the complete array
}
public int RealFuelSum( List<int[]> fuelmodules ) {
public int addAllArray( int[,] array ) {
int sum = 0;
for( int arrayid = 0; arrayid < fuelmodules.Count; arrayid++ ) {
for( int i = 0; i < fuelmodules[arrayid].Length; i++ ) {
sum += fuelmodules[arrayid][i];
//Console.WriteLine( "Module " + arrayid.ToString() + "/" + fuelmodules.Count.ToString() + " | " + i.ToString() + "/" + fuelmodules[arrayid].Length.ToString() + " | val: " + fuelmodules[arrayid][i].ToString() );
for( int i = 0; i < array.GetLength(0); i++ ) {
for( int mod_i = 0; mod_i < array.GetLength(1); mod_i++ ) {
sum += array[i, mod_i];
}
}
return sum;

@ -15,13 +15,11 @@ namespace Day1 {
modules = get1.FuelModules( inputs ); // get the fuel for the mass'es
Console.WriteLine( get1.FuelSum( modules ) );
List<int[]> modulesOfModules = new List<int[]>();
//int[,] modulesOfModules = new int[,];
Part2.Get get2 = new Part2.Get();
modulesOfModules = get2.AllFuelModules( modules );
Console.Write( "Real sum of fuel: " );
Console.Write( get2.RealFuelSum(modulesOfModules) );
Console.Write( "\n" );
Console.Write( "Real sum: " );
Console.Write( get2.addAllArray( get2.AllFuelModules( modules ) ) );
Console.WriteLine("");
}
}

Loading…
Cancel
Save