Author: Nicholas Prado <nmprado@nzen.ws>
Date: Thu Dec 5 07:54:56 UTC 2019
Parent: 5fbc9413961c899e3f31fc0c2ff33911c706ad82
Log message:
tmpf i1904-1 ensures initial value satisfies both constraints
1: diff --git a/src/java/Exercise19041.java b/src/java/Exercise19041.java 2: index eb94b75..4f24915 100644 3: --- a/src/java/Exercise19041.java 4: +++ b/src/java/Exercise19041.java 5: @@ -81,10 +81,30 @@ public class Exercise19041 6: // System.out.println( " ; now "+ valueOfRegister( register ) ); 7: } 8: currentResolvedValue = valueOfRegister( register ); 9: - System.out.println( "initial value is "+ currentResolvedValue ); 10: + System.out.println( "initial value with neighbor "+ currentResolvedValue ); 11: + // ensure registers begin with pair constraint 12: + int leftSideOfPair = 4; 13: + boolean initialSatisfiedPairConstraint = false; 14: + for ( int ind = leftSideOfPair; ind >= 0; ind-- ) 15: + { 16: + if ( register[ ind ].ownValue == register[ ind +1 ].ownValue ) 17: + { 18: + leftSideOfPair = ind; 19: + initialSatisfiedPairConstraint = true; 20: + break; 21: + } 22: + } 23: + if ( ! initialSatisfiedPairConstraint ) 24: + { 25: + // make the last two a pair 26: + leftSideOfPair = 4; 27: + register[ leftSideOfPair ].ownValue += 1; 28: + register[ leftSideOfPair +1 ].ownValue = register[ leftSideOfPair ].ownValue; 29: + } 30: + currentResolvedValue = valueOfRegister( register ); 31: + System.out.println( "initial value with n& pair "+ currentResolvedValue ); 32: // 33: /* 34: - int leftSideOfPair = 4; 35: Set<WholeN> candidates = new HashSet<>(); 36: for ( ; leftSideOfPair >= 0; leftSideOfPair-- ) 37: { 38: @@ -95,6 +115,7 @@ public class Exercise19041 39: } 40: return -1; 41: */ 42: + throw new RuntimeException( "unfinished" ); 43: } 44: 45: 46: @@ -182,6 +203,62 @@ public class Exercise19041 47: } 48: } 49: 50: + public int greaterLeft() 51: + { 52: + return greaterLeft( ownValue ); 53: + } 54: + 55: + public int greaterLeft( int value ) 56: + { 57: + switch ( value ) 58: + { 59: + case 0 : 60: + { 61: + return 9; 62: + } 63: + case 1 : 64: + { 65: + return 8; 66: + } 67: + case 2 : 68: + { 69: + return 7; 70: + } 71: + case 3 : 72: + { 73: + return 6; 74: + } 75: + case 4 : 76: + { 77: + return 5; 78: + } 79: + case 5 : 80: + { 81: + return 4; 82: + } 83: + case 6 : 84: + { 85: + return 3; 86: + } 87: + case 7 : 88: + { 89: + return 2; 90: + } 91: + case 8 : 92: + { 93: + return 1; 94: + } 95: + case 9 : 96: + { 97: + return 0; 98: + } 99: + default : 100: + { 101: + return -1; 102: + } 103: + } 104: + } 105: + 106: public String toString() 107: { 108: return Integer.valueOf( ownValue ).toString();