some-advent-of-code: b3db8d8e02a20b66933ae8ba822a7b75180ed1c8

     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.HashSet;
     8: import java.util.LinkedList;
     9: import java.util.List;
    10: import java.util.Map;
    11: import java.util.Set;
    12: import java.util.TreeMap;
    13: 
    14: public class Exercise200601
    15: {
    16: 
    17: 	public static void main( String args[] )
    18: 	{
    19: 		final String here = "e20011.m ";
    20: 		if ( args.length < 1 )
    21: 		{
    22: 			throw new RuntimeException( here +"add a filename argument" );
    23: 		}
    24: 		String userSaysFile = args[ 0 ];
    25: 		List<String> fileLines = new LinkedList<>();
    26: 		try
    27: 		{
    28: 			Path where = Paths.get( userSaysFile );
    29: 			fileLines = Files.readAllLines( where );
    30: 		}
    31: 		catch ( IOException | InvalidPathException ie )
    32: 		{
    33: 			System.err.println( here +"couldn't read file "+ userSaysFile +" because "+ ie );
    34: 			return;
    35: 		}
    36: 		/*
    37: 		- interpretation of spec -
    38: 		*/
    39: 		// gather
    40: 		Set<Character> groupAnswers = new HashSet<>();
    41: 		int target = 0, lineNum = 0;
    42: 		for ( String line : fileLines )
    43: 		{
    44: 			if ( line.isEmpty() )
    45: 			{
    46: 				lineNum += 1;
    47: 				target += groupAnswers.size();
    48: 				// presumably, the answers will matter in the next session
    49: 				groupAnswers.clear();
    50: 			}
    51: 			else
    52: 			{
    53: 				for ( int ind = 0; ind < line.length(); ind++ )
    54: 					groupAnswers.add( line.charAt( ind ) );
    55: 			}
    56: 		}
    57: 		if ( ! groupAnswers.isEmpty() )
    58: 			target += groupAnswers.size();
    59: 		System.out.println( here +"input had no pair that summed to "+ target );
    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: 
    86: 
    87: 
    88: 

Generated by git2html.