Created
May 9, 2015 07:41
-
-
Save robstryker/9ec091409ae9f7f5121e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void test5() { | |
ArrayList<String> list = new ArrayList<String>(); | |
for( int loop = 0; loop < 65536; loop ++ ) { | |
StringBuffer line = new StringBuffer(); | |
boolean previousOperator = true; // plus | |
int bitmask = loop; | |
int total = 0; | |
String working = ""; | |
for( int i = 0; i < 8; i++ ) { | |
working += (i+1); | |
line.append((i+1)); | |
boolean putOperator = ((bitmask & (1 << i)) != 0); | |
boolean nextOperator = ((bitmask & (1 << (i+8))) != 0); | |
if( putOperator ) { | |
total += (Integer.parseInt(working) * (previousOperator ? 1 : -1)); // multiple -1 if previousOperator is minus | |
working = ""; | |
line.append(nextOperator ? "+" : "-"); | |
previousOperator = nextOperator; | |
} | |
} | |
line.append(9); | |
working += (9); | |
total += (Integer.parseInt(working) * (previousOperator ? 1 : -1)); // multiply -1 if previousOperator is minus | |
working = ""; | |
line.append("=" + total); | |
if( total == 100 ) { | |
if( !list.contains(line.toString())) { | |
list.add(line.toString()); | |
System.out.println(line.toString()); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment