some-advent-of-code: 6578c9cae6b9f16826be63423c80738180f8aa75

     1: 
     2: import java.io.IOException;
     3: import java.nio.file.*;
     4: import java.util.*;
     5: 
     6: public class Exercise210102
     7: {
     8: 
     9: 	public static void main(
    10: 			String args[]
    11: 	) {
    12: 		final String here = "e210102.m ";
    13: 		if ( args.length < 1 )
    14: 		{
    15: 			throw new RuntimeException( here +"add a filename argument" );
    16: 		}
    17: 		String userSaysFile = args[ 0 ];
    18: 		List<String> fileLines = new LinkedList<>();
    19: 		try
    20: 		{
    21: 			Path where = Paths.get( userSaysFile );
    22: 			fileLines = Files.readAllLines( where );
    23: 		}
    24: 		catch ( IOException | InvalidPathException ie )
    25: 		{
    26: 			System.err.println( here +"couldn't read file "+ userSaysFile +" because "+ ie );
    27: 			return;
    28: 		}
    29: 		/*
    30: 		- interpretation of spec -
    31: 		*/
    32: 		Exercise210102.findDepth( fileLines );
    33: 	}
    34: 
    35: 	public static void findDepth(
    36: 			List<String> fileLines
    37: 	) {
    38: 		int currentSum = 0, previousDepthSum = 0, previousDepth = 0, ancientDepth = 0, qualifiedDrops = 0;
    39: 		for ( String line : fileLines )
    40: 		{
    41: 			if ( line.isEmpty() )
    42: 				continue;
    43: 			int currDepth = Integer.parseInt( line );
    44: 			currentSum = currDepth + previousDepth + ancientDepth;
    45: 			if ( ancientDepth != 0 && currentSum > previousDepthSum )
    46: 			{	qualifiedDrops += 1; System.out.print( "+" ); }
    47: 			System.out.println( "cs "+ currentSum +" ad"+ ancientDepth );
    48: 			previousDepthSum = currentSum;
    49: 			ancientDepth = previousDepth;
    50: 			previousDepth = currDepth;
    51: 		}
    52: 		System.out.println( "\tanswer "+ qualifiedDrops );
    53: 	}
    54: 
    55: }
    56: 
    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: 

Generated by git2html.