some-advent-of-code: 5cd0763ea88101a21ff6ad4ff1a91bddfbf5e297

     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.Set;
    10: import java.util.TreeSet;
    11: 
    12: public class Exercise18022
    13: {
    14: 
    15: 	public static void main( String args[] )
    16: 	{
    17: 		final String here = "e18022.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: 		get lines
    37: 		for line
    38: 			add to set (ignoring navigable set optimization to avoid repeated comparisons later)
    39: 		for key in set
    40: 			for key in set except current key
    41: 				for letter in key (to min; though I think that they're probably similarly sized)
    42: 					if keys except this letter match
    43: 						super break, declare victory
    44: 		*/
    45: 		/*	
    46: 		// -- 4tests
    47: 		fileLines.clear();
    48: 		fileLines.add( "aaaza" );
    49: 		fileLines.add( "abb33" );
    50: 		fileLines.add( "aab33" );
    51: 		fileLines.add( "aaafa" );
    52: 		// -- 4tests
    53: 		*/
    54: 		for ( String line : fileLines )
    55: 		{
    56: 			for ( String otherLine : fileLines )
    57: 			{
    58: 				if ( line.equals( otherLine )
    59: 					|| line.length() != otherLine.length() )
    60: 				{
    61: 					continue;
    62: 				}
    63: 				for ( int ind = line.length() -1; ind >= 0; ind-- )
    64: 				{
    65: 					String lineWithout = line.substring( 0, ind ) + line.substring( ind +1, line.length() );
    66: 					String otherWithout = otherLine.substring( 0, ind ) + otherLine.substring( ind +1, otherLine.length() );
    67: 					if ( lineWithout.equals( otherWithout ) )
    68: 					{
    69: 						System.out.println( here +"match: "+ lineWithout );
    70: 						return;
    71: 					}
    72: 				}
    73: 			}
    74: 		}
    75: 	}
    76: }
    77: 
    78: 
    79: 
    80: 
    81: 
    82: 
    83: 
    84: 
    85: 
    86: 
    87: 
    88: 
    89: 
    90: 
    91: 
    92: 
    93: 
    94: 
    95: 
    96: 
    97: 
    98: 
    99: 
   100: 
   101: 
   102: 
   103: 

Generated by git2html.