some-advent-of-code: diff e9c85ec6 fec12b6d

Branch: 1903-2

Commit: e9c85ec6ee10e6d82a1315ae7c856804c2ef1fd5

Author: Nicholas Prado <nmprado@nzen.ws>
Date: Mon Dec 2 04:16:02 UTC 2019
Parent: fec12b6da7215098d9654d80c2d17252b79f435e
Log message:

    Solved day one of 2019
    
    Yay, super easy. Loop over input and apply a simple function.

    1: diff --git a/src/java/Exercise19011.java b/src/java/Exercise19011.java
    2: new file mode 100644
    3: index 0000000..5f7a650
    4: --- /dev/null
    5: +++ b/src/java/Exercise19011.java
    6: @@ -0,0 +1,85 @@
    7: +
    8: +import java.io.IOException;
    9: +import java.nio.file.Files;
   10: +import java.nio.file.InvalidPathException;
   11: +import java.nio.file.Path;
   12: +import java.nio.file.Paths;
   13: +import java.util.LinkedList;
   14: +import java.util.List;
   15: +import java.util.Map;
   16: +import java.util.TreeMap;
   17: +
   18: +public class Exercise19011
   19: +{
   20: +
   21: +	public static void main( String args[] )
   22: +	{
   23: +		final String here = "e19011.m ";
   24: +		if ( args.length < 1 )
   25: +		{
   26: +			throw new RuntimeException( here +"add a filename argument" );
   27: +		}
   28: +		String userSaysFile = args[ 0 ];
   29: +		List<String> fileLines = new LinkedList<>();
   30: +		try
   31: +		{
   32: +			Path where = Paths.get( userSaysFile );
   33: +			fileLines = Files.readAllLines( where );
   34: +		}
   35: +		catch ( IOException | InvalidPathException ie )
   36: +		{
   37: +			System.err.println( here +"couldn't read file "+ userSaysFile +" because "+ ie );
   38: +			return;
   39: +		}
   40: +		/*
   41: +		- interpretation of spec -
   42: +		for values in file
   43: +			total += floor(x / 3) -2
   44: +		*/
   45: +		long total = 0;
   46: +		int lineNum = 0;
   47: +		for ( String line : fileLines )
   48: +		{
   49: +			lineNum += 1;
   50: +			int moduleWeight = 0;
   51: +			try
   52: +			{
   53: +				moduleWeight = Integer.parseInt( line );
   54: +			}
   55: +			catch ( NumberFormatException nfe )
   56: +			{
   57: +				System.err.println( here +"handed a non int "+ line +" on "+ lineNum +" because "+ nfe );
   58: +				continue;
   59: +			}
   60: +			total += Math.floor( moduleWeight / 3 ) -2;
   61: +		}
   62: +		System.out.println( here +"total is "+ total );
   63: +	}
   64: +}
   65: +
   66: +
   67: +
   68: +
   69: +
   70: +
   71: +
   72: +
   73: +
   74: +
   75: +
   76: +
   77: +
   78: +
   79: +
   80: +
   81: +
   82: +
   83: +
   84: +
   85: +
   86: +
   87: +
   88: +
   89: +
   90: +
   91: +
   92: diff --git a/src/java/Exercise19012.java b/src/java/Exercise19012.java
   93: new file mode 100644
   94: index 0000000..150fa11
   95: --- /dev/null
   96: +++ b/src/java/Exercise19012.java
   97: @@ -0,0 +1,96 @@
   98: +
   99: +import java.io.IOException;
  100: +import java.nio.file.Files;
  101: +import java.nio.file.InvalidPathException;
  102: +import java.nio.file.Path;
  103: +import java.nio.file.Paths;
  104: +import java.util.LinkedList;
  105: +import java.util.List;
  106: +import java.util.Map;
  107: +import java.util.TreeMap;
  108: +
  109: +public class Exercise19012
  110: +{
  111: +
  112: +	public static void main( String args[] )
  113: +	{
  114: +		final String here = "e19011.m ";
  115: +		if ( args.length < 1 )
  116: +		{
  117: +			throw new RuntimeException( here +"add a filename argument" );
  118: +		}
  119: +		String userSaysFile = args[ 0 ];
  120: +		List<String> fileLines = new LinkedList<>();
  121: +		try
  122: +		{
  123: +			Path where = Paths.get( userSaysFile );
  124: +			fileLines = Files.readAllLines( where );
  125: +		}
  126: +		catch ( IOException | InvalidPathException ie )
  127: +		{
  128: +			System.err.println( here +"couldn't read file "+ userSaysFile +" because "+ ie );
  129: +			return;
  130: +		}
  131: +		/*
  132: +		- interpretation of spec -
  133: +		for values in file
  134: +			total += floor(x / 3) -2
  135: +		*/
  136: +		long total = 0;
  137: +		int lineNum = 0;
  138: +		for ( String line : fileLines )
  139: +		{
  140: +			lineNum += 1;
  141: +			int moduleWeight = 0;
  142: +			try
  143: +			{
  144: +				moduleWeight = Integer.parseInt( line );
  145: +			}
  146: +			catch ( NumberFormatException nfe )
  147: +			{
  148: +				System.err.println( here +"handed a non int "+ line +" on "+ lineNum +" because "+ nfe );
  149: +				continue;
  150: +			}
  151: +			int fuelWeight = fuelRequiredFor( moduleWeight );
  152: +			while ( fuelWeight > 0 )
  153: +			{
  154: +				total += fuelWeight;
  155: +				fuelWeight = fuelRequiredFor( fuelWeight );
  156: +			}
  157: +		}
  158: +		System.out.println( here +"total is "+ total );
  159: +	}
  160: +
  161: +
  162: +	private static int fuelRequiredFor( int mass )
  163: +	{
  164: +		return mass /3 -2;
  165: +	}
  166: +}
  167: +
  168: +
  169: +
  170: +
  171: +
  172: +
  173: +
  174: +
  175: +
  176: +
  177: +
  178: +
  179: +
  180: +
  181: +
  182: +
  183: +
  184: +
  185: +
  186: +
  187: +
  188: +
  189: +
  190: +
  191: +
  192: +
  193: +
  194: diff --git a/src/res/19_01_input.txt b/src/res/19_01_input.txt
  195: new file mode 100644
  196: index 0000000..3b18d8c
  197: --- /dev/null
  198: +++ b/src/res/19_01_input.txt
  199: @@ -0,0 +1,100 @@
  200: +73365
  201: +84016
  202: +98122
  203: +114871
  204: +111575
  205: +130294
  206: +59341
  207: +102810
  208: +92986
  209: +81275
  210: +83155
  211: +74530
  212: +67858
  213: +54107
  214: +62099
  215: +82535
  216: +122085
  217: +139127
  218: +131939
  219: +130125
  220: +96285
  221: +70572
  222: +129325
  223: +132261
  224: +69597
  225: +93574
  226: +70089
  227: +130711
  228: +109220
  229: +50155
  230: +98250
  231: +51054
  232: +100028
  233: +86985
  234: +106638
  235: +116993
  236: +95130
  237: +115571
  238: +56707
  239: +105988
  240: +123358
  241: +95470
  242: +71094
  243: +126310
  244: +66153
  245: +128788
  246: +51605
  247: +70044
  248: +70180
  249: +141905
  250: +96494
  251: +89332
  252: +96688
  253: +131936
  254: +83782
  255: +108218
  256: +60650
  257: +91289
  258: +126406
  259: +112939
  260: +76303
  261: +115774
  262: +135382
  263: +116478
  264: +77898
  265: +98611
  266: +89155
  267: +114878
  268: +110085
  269: +114482
  270: +61585
  271: +103480
  272: +99198
  273: +81082
  274: +113501
  275: +100167
  276: +100085
  277: +128747
  278: +79731
  279: +93289
  280: +121516
  281: +116380
  282: +56592
  283: +146611
  284: +132595
  285: +60483
  286: +105828
  287: +118923
  288: +141972
  289: +126450
  290: +77214
  291: +97406
  292: +77745
  293: +101982
  294: +120919
  295: +71085
  296: +118300
  297: +92440
  298: +115184
  299: +142447

Generated by git2html.