some-advent-of-code: a04b9654c4cce0e69f1afae43137ccb89e4a091f

     1: 
     2: import java.io.IOException;
     3: import java.nio.file.*;
     4: import java.util.*;
     5: 
     6: public class Exercise210801
     7: {
     8: 
     9: 	public static void main(
    10: 			String args[]
    11: 	) {
    12: 		final String here = "e210801.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 -52
    31: 		*/
    32: 		Exercise210801.countSegments( fileLines );
    33: 	}
    34: 
    35: 
    36: 	private static void countSegments(
    37: 			List<String> fileLines
    38: 	) {
    39: 		Collection<String> outputs = new LinkedList<>();
    40: 		for ( String line : fileLines )
    41: 		{
    42: 			if ( line.isEmpty() )
    43: 				continue;
    44: 			String[] minusDivider = line.split( " \\| " );
    45: 			String[] outputsOfLine = minusDivider[ 1 ].split( " " );
    46: 			for ( String output : outputsOfLine )
    47: 			{
    48: 				if( output.length() == 2 // 1
    49: 						|| output.length() == 4 // 4
    50: 						|| output.length() == 3 // 7
    51: 						|| output.length() == 7 ) // 8
    52: 					outputs.add( output );
    53: 			}
    54: 		}
    55: 		int segments = outputs.size();
    56: 		System.out.println( "\t"+ segments );
    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: 
    86: 
    87: 

Generated by git2html.