some-advent-of-code: 5f7a6503dcf8b9cfd158e58b3908ae965119146c

     1: 
     2: import java.io.IOException;
     3: import java.nio.file.Files;
     4: import java.nio.file.InvalidPathException;
     5: import java.nio.file.Path;
     6: import java.nio.file.Paths;
     7: import java.util.LinkedList;
     8: import java.util.List;
     9: import java.util.Map;
    10: import java.util.TreeMap;
    11: 
    12: public class Exercise19011
    13: {
    14: 
    15: 	public static void main( String args[] )
    16: 	{
    17: 		final String here = "e19011.m ";
    18: 		if ( args.length < 1 )
    19: 		{
    20: 			throw new RuntimeException( here +"add a filename argument" );
    21: 		}
    22: 		String userSaysFile = args[ 0 ];
    23: 		List<String> fileLines = new LinkedList<>();
    24: 		try
    25: 		{
    26: 			Path where = Paths.get( userSaysFile );
    27: 			fileLines = Files.readAllLines( where );
    28: 		}
    29: 		catch ( IOException | InvalidPathException ie )
    30: 		{
    31: 			System.err.println( here +"couldn't read file "+ userSaysFile +" because "+ ie );
    32: 			return;
    33: 		}
    34: 		/*
    35: 		- interpretation of spec -
    36: 		for values in file
    37: 			total += floor(x / 3) -2
    38: 		*/
    39: 		long total = 0;
    40: 		int lineNum = 0;
    41: 		for ( String line : fileLines )
    42: 		{
    43: 			lineNum += 1;
    44: 			int moduleWeight = 0;
    45: 			try
    46: 			{
    47: 				moduleWeight = Integer.parseInt( line );
    48: 			}
    49: 			catch ( NumberFormatException nfe )
    50: 			{
    51: 				System.err.println( here +"handed a non int "+ line +" on "+ lineNum +" because "+ nfe );
    52: 				continue;
    53: 			}
    54: 			total += Math.floor( moduleWeight / 3 ) -2;
    55: 		}
    56: 		System.out.println( here +"total is "+ total );
    57: 	}
    58: }
    59: 
    60: 
    61: 
    62: 
    63: 
    64: 
    65: 
    66: 
    67: 
    68: 
    69: 
    70: 
    71: 
    72: 
    73: 
    74: 
    75: 
    76: 
    77: 
    78: 
    79: 
    80: 
    81: 
    82: 
    83: 
    84: 
    85: 

Generated by git2html.