some-advent-of-code: diff 5fbc9413 d271ce60

Branch: 1904-1

Commit: 5fbc9413961c899e3f31fc0c2ff33911c706ad82

Author: Nicholas Prado <nmprado@nzen.ws>
Date: Thu Dec 5 07:03:55 UTC 2019
Parent: d271ce605572471f42422a4d171bc2bd97fb16c8
Log message:

    temp i1904-1 partial draft that advances to the first value
    
    This can increment the first value up to one that satisfies the
    neighbor same or greater constraint. However, it doesn't check
    whether the pair constraint is satisfied. The first value does
    satisfy it, but it's better to have another pass that also
    satisfies the pair constraint, so the pair cursor is in the
    right spot before this starts incrementing.
    
    In case it's not clear from that description, I intend to
    generate the values, rather than do some combinatoric series
    analysis.

    1: diff --git a/src/java/Exercise19041.java b/src/java/Exercise19041.java
    2: new file mode 100644
    3: index 0000000..eb94b75
    4: --- /dev/null
    5: +++ b/src/java/Exercise19041.java
    6: @@ -0,0 +1,217 @@
    7: +
    8: +import java.awt.Point;
    9: +import java.io.IOException;
   10: +import java.nio.file.Files;
   11: +import java.nio.file.InvalidPathException;
   12: +import java.nio.file.Path;
   13: +import java.nio.file.Paths;
   14: +import java.util.ArrayList;
   15: +import java.util.Collection;
   16: +import java.util.LinkedList;
   17: +import java.util.List;
   18: +import java.util.HashSet;
   19: +import java.util.Map;
   20: +import java.util.Set;
   21: +import java.util.SortedSet;
   22: +import java.util.TreeMap;
   23: +import java.util.TreeSet;
   24: +
   25: +public class Exercise19041
   26: +{
   27: +	private static final String cl = "19041.";
   28: +
   29: +	public static void main( String args[] )
   30: +	{
   31: +		final String here = Exercise19041.cl +"m ";
   32: +		if ( args.length < 1 )
   33: +		{
   34: +			throw new RuntimeException( here +"add a filename argument" );
   35: +		}
   36: +		String userSaysFile = args[ 0 ];
   37: +		List<String> fileLines = new LinkedList<>();
   38: +		try
   39: +		{
   40: +			Path where = Paths.get( userSaysFile );
   41: +			fileLines = Files.readAllLines( where );
   42: +		}
   43: +		catch ( IOException | InvalidPathException ie )
   44: +		{
   45: +			System.err.println( here +"couldn't read file "+ userSaysFile +" because "+ ie );
   46: +			return;
   47: +		}
   48: +		/*
   49: +		- interpretation of spec -
   50: +		gen combinations of six digits where left is less or equal to right neighgor
   51: +		and at least two digits are of equal value
   52: +		*/
   53: +		int lowLim = Integer.parseInt( fileLines.get( 0 ) );
   54: +		int highLim = Integer.parseInt( fileLines.get( 1 ) );
   55: +		System.out.println( "answer is "+ new Exercise19041()
   56: +				.combinationsIncreasingWithPairBetween( lowLim, highLim ) );
   57: +	}
   58: +
   59: +
   60: +	private int combinationsIncreasingWithPairBetween( int lowLim, int highLim )
   61: +	{
   62: +		final String here = cl +"ciwpb ";
   63: +		String initialAsStr = Integer.toString( lowLim );
   64: +		WholeN[] register = new WholeN[ 6 ];
   65: +		register[ 0 ] = new WholeN( Integer.parseInt( initialAsStr.substring( 0, 1 ) ) );
   66: +		register[ 1 ] = new WholeN( Integer.parseInt( initialAsStr.substring( 1, 2 ) ) );
   67: +		register[ 2 ] = new WholeN( Integer.parseInt( initialAsStr.substring( 2, 3 ) ) );
   68: +		register[ 3 ] = new WholeN( Integer.parseInt( initialAsStr.substring( 3, 4 ) ) );
   69: +		register[ 4 ] = new WholeN( Integer.parseInt( initialAsStr.substring( 4, 5 ) ) );
   70: +		register[ 5 ] = new WholeN( Integer.parseInt( initialAsStr.substring( 5 ) ) );
   71: +		/*
   72: +		for ( WholeN nn : register )
   73: +				System.out.print( nn );
   74: +		System.out.println();
   75: +		*/
   76: +		int currentResolvedValue = lowLim;
   77: +		// ensure registers begin with valid neighbor same/above constraint
   78: +		for ( int ind = 1; ind < register.length; ind++ )
   79: +		{
   80: +			/*
   81: +			System.out.println( here +"iv "+ register[ ind -1 ].ownValue +" "+ register[ ind ].ownValue );
   82: +			System.out.print( here +"e if "+ register[ ind -1 ].ownValue +" > "+ register[ ind ].ownValue +" ("+ (register[ ind -1 ].ownValue > register[ ind ].ownValue) +") "+ ((register[ ind -1 ].ownValue <= register[ ind ].ownValue)
   83: +						? "stay" : "["+ register[ ind ].ownValue +"] = "+ register[ ind -1 ].ownValue ) );
   84: +			*/
   85: +			if ( register[ ind -1 ].ownValue > register[ ind ].ownValue )
   86: +				register[ ind ].ownValue = register[ ind -1 ].ownValue;
   87: +			// System.out.println( " ; now "+ valueOfRegister( register ) );
   88: +		}
   89: +		currentResolvedValue = valueOfRegister( register );
   90: +		System.out.println( "initial value is "+ currentResolvedValue );
   91: +		//
   92: +/*		
   93: +		int leftSideOfPair = 4;
   94: +		Set<WholeN> candidates = new HashSet<>();
   95: +		for ( ; leftSideOfPair >= 0; leftSideOfPair-- )
   96: +		{
   97: +			for ( int colInd = 5; colInd > leftSideOfPair +1; colInd-- )
   98: +			{
   99: +				
  100: +			}
  101: +		}
  102: +		return -1;
  103: +		*/
  104: +	}
  105: +
  106: +
  107: +	private int valueOfRegister( WholeN[] register )
  108: +	{
  109: +		int total = 0, position = 1;
  110: +		for ( int col = register.length -1; col >= 0 ; col-- )
  111: +		{
  112: +			total += register[ col ].ownValue * position;
  113: +			position *= 10;
  114: +		}
  115: +		return total;
  116: +	}
  117: +
  118: +
  119: +	private class WholeN
  120: +	{
  121: +		int ownValue;
  122: +
  123: +		public WholeN( int someValue )
  124: +		{
  125: +			// ignoring antagonistic input
  126: +			ownValue = someValue;
  127: +		}
  128: +
  129: +		public WholeN next( int value )
  130: +		{
  131: +			switch ( value )
  132: +			{
  133: +			case 0 :
  134: +			{
  135: +				ownValue = 1;
  136: +				return this;
  137: +			}
  138: +			case 1 :
  139: +			{
  140: +				ownValue = 2;
  141: +				return this;
  142: +			}
  143: +			case 2 :
  144: +			{
  145: +				ownValue = 3;
  146: +				return this;
  147: +			}
  148: +			case 3 :
  149: +			{
  150: +				ownValue = 4;
  151: +				return this;
  152: +			}
  153: +			case 4 :
  154: +			{
  155: +				ownValue = 5;
  156: +				return this;
  157: +			}
  158: +			case 5 :
  159: +			{
  160: +				ownValue = 6;
  161: +				return this;
  162: +			}
  163: +			case 6 :
  164: +			{
  165: +				ownValue = 7;
  166: +				return this;
  167: +			}
  168: +			case 7 :
  169: +			{
  170: +				ownValue = 8;
  171: +				return this;
  172: +			}
  173: +			case 8 :
  174: +			{
  175: +				ownValue = 9;
  176: +				return this;
  177: +			}
  178: +			case 9 :
  179: +			{
  180: +				ownValue = 0;
  181: +				return this;
  182: +			}
  183: +			default :
  184: +			{
  185: +				ownValue = -1;
  186: +				return this;
  187: +			}
  188: +			}
  189: +		}
  190: +
  191: +		public String toString()
  192: +		{
  193: +			return Integer.valueOf( ownValue ).toString();
  194: +		}
  195: +	}
  196: +	
  197: +}
  198: +
  199: +
  200: +
  201: +
  202: +
  203: +
  204: +
  205: +
  206: +
  207: +
  208: +
  209: +
  210: +
  211: +
  212: +
  213: +
  214: +
  215: +
  216: +
  217: +
  218: +
  219: +
  220: +
  221: +
  222: +
  223: +
  224: diff --git a/src/res/19_04_input.txt b/src/res/19_04_input.txt
  225: new file mode 100644
  226: index 0000000..dc63fd2
  227: --- /dev/null
  228: +++ b/src/res/19_04_input.txt
  229: @@ -0,0 +1,2 @@
  230: +353096
  231: +843212
  232: \ No newline at end of file

Generated by git2html.