Java, 330 баллов
Прежде чем меня высмеют за столь высокий балл, позвольте мне уточнить, что я пытался решить эту проблему другим способом, зная, что это, вероятно, будет не столь оптимальным, как некоторые из лучших ответов здесь. Мне было более или менее любопытно, если бы я мог подобраться ближе, что, к моему удивлению, я не осознавал, насколько хуже это окажется. Вот краткое изложение того, что мой подход был здесь:
Разработайте алгоритм решения головоломки Судоку.
Разработайте алгоритм шифрования, который еще можно решить. Он делает это несколько случайным образом, удаляя подсказки, которые можно легко определить заранее. Я мог получить примерно 22 подсказки, прежде чем это заняло слишком много времени.
После скремблирования головоломка может быть представлена триплетом однозначных целых чисел для каждой подсказки, в моем случае 22 тройки из 3. Я подумал, что если бы я мог объединить их в одно 66-значное число, тогда base95 закодировал бы это, тогда у меня есть кое-что, что может быть легко расшифрованным.
Закодированная строка оказалась длиннее, чем я ожидал, обычно около 33 символов. В этот момент я попробовал альтернативный способ, чем использование Java BigInteger, где я создал большое число из 81-битной маски, представляющей 81 ячейку сетки, где 1 означает, что для этой ячейки существует подсказка. Затем я скомбинировал эту битовую маску с 4-битными представлениями каждого значения ячейки в последовательном порядке, округлил до байтов и обнаружил, что я получил примерно одинаковую длину кодированной строки после кодирования base95.
Так что, в основном, я публикую свой код на тот случай, если кто-нибудь заинтересуется другим подходом, который не сработает так хорошо.
Класс Пазз
public class Puzz {
enum By {
Row, Column, Block
}
static final List<Integer> NUMBERS = Arrays.asList(new Integer[] { 1, 2, 3,
4, 5, 6, 7, 8, 9 });
List<Square> entries = new ArrayList<Square>();
HashMap<Integer, List<Square>> squaresByRow = new HashMap<Integer, List<Square>>();
HashMap<Integer, List<Square>> squaresByColumn = new HashMap<Integer, List<Square>>();
HashMap<Integer, List<Square>> squaresByBlock = new HashMap<Integer, List<Square>>();
public Puzz(int[][] data) {
// Create squares put them in squares by row hashtable
for (int r = 0; r < 9; r++) {
List<Square> squaresInRow = new ArrayList<Square>();
for (int c = 0; c < 9; c++) {
Square square = new Square(r, c, data[r][c], this);
entries.add(square);
squaresInRow.add(square);
}
squaresByRow.put(r, squaresInRow);
}
// Put squares in column hash table
for (int c = 0; c < 9; c++) {
List<Square> squaresInColumn = new ArrayList<Square>();
for (int r = 0; r < 9; r++) {
squaresInColumn.add(squaresByRow.get(r).get(c));
}
squaresByColumn.put(c, squaresInColumn);
}
// Put squares in block hash table
for (int i = 1; i < 10; i++) {
squaresByBlock.put(i, new ArrayList<Square>());
}
for (int r = 0; r < 9; r++) {
for (int c = 0; c < 9; c++) {
int block = getBlock(r, c);
squaresByBlock.get(block).add(get(r, c));
}
}
// Discover the possibilities
updatePossibilities();
}
public void updatePossibilities() {
for (int r = 0; r < 9; r++) {
for (int c = 0; c < 9; c++) {
Square theSquare = get(r, c);
if (theSquare.value != 0) {
theSquare.possibilities.removeAll(NUMBERS);
continue;
} else {
theSquare.possibilities.addAll(NUMBERS);
}
int block = getBlock(r, c);
HashSet<Square> squares = new HashSet<Square>();
squares.addAll(squaresByRow.get(r));
squares.addAll(squaresByColumn.get(c));
squares.addAll(squaresByBlock.get(block));
for (Square s : squares) {
if (s == theSquare)
continue;
theSquare.possibilities.remove(s.value);
}
}
}
}
public int getValue(int row, int column) {
return squaresByRow.get(row).get(column).value;
}
public Square get(int row, int column) {
return squaresByRow.get(row).get(column);
}
public boolean set(int row, int column, int value) {
if (value == 0) {
squaresByRow.get(row).get(column).value = 0;
updatePossibilities();
return true;
}
if (isValid(row, column, value)) {
squaresByRow.get(row).get(column).value = value;
updatePossibilities();
return true;
} else {
return false;
}
}
public boolean isValidSubset(By subset, int row, int column, int value) {
List<Dubs> dubss = new ArrayList<Dubs>();
List<Trips> tripss = new ArrayList<Trips>();
Square theSquare = get(row, column);
int block = getBlock(row, column);
List<Square> squares = new ArrayList<Square>();
switch (subset) {
case Row:
squares.addAll(squaresByRow.get(row));
break;
case Column:
squares.addAll(squaresByColumn.get(column));
break;
default:
squares.addAll(squaresByBlock.get(block));
break;
}
for (Square r : squares) {
if (r == theSquare)
continue;
// if any of the impacted squares have this value then it is not a
// valid value
if (r.value == value)
return false;
if (r.possibilities.size() == 3) {
List<Integer> poss = new ArrayList<Integer>(r.possibilities);
tripss.add(new Trips(poss.get(0), poss.get(1), poss.get(2),
r.row, r.col));
}
if (r.possibilities.size() == 2) {
List<Integer> poss = new ArrayList<Integer>(r.possibilities);
dubss.add(new Dubs(poss.get(0), poss.get(1), r.row, r.col));
}
}
// Find the trips and rule out the value if a triplet exists in squares
List<Trips> tripsCopy = new ArrayList<Trips>(tripss);
for (Trips trips : tripsCopy) {
int countOfOccurrences = 0;
for (Trips tr : tripss) {
if (tr.equals(trips) && !(tr.row == row && tr.col == column))
countOfOccurrences++;
}
for (Dubs dubs : dubss) {
if (trips.containedWithin(dubs)
&& !(dubs.row == row && dubs.col == column))
countOfOccurrences++;
}
if (countOfOccurrences == 3 && trips.containedWithin(value))
return false;
}
// Find the dubs and rule out the value if a double exists in squares
List<Dubs> dubsCopy = new ArrayList<Dubs>(dubss);
for (Dubs dubs : dubsCopy) {
int countOfOccurrences = 0;
for (Dubs du : dubss) {
// Count occurrences of Dubs that are not the tested square
if (du.equals(dubs) && !(du.row == row && du.col == column))
countOfOccurrences++;
}
if (countOfOccurrences == 2 && dubs.containedWithin(value))
return false;
}
return true;
}
public boolean isValid(int row, int column, int value) {
return isValidSubset(By.Row, row, column, value)
&& isValidSubset(By.Column, row, column, value)
&& isValidSubset(By.Block, row, column, value);
}
public int getBlock(int row, int column) {
int blockRow = (int) Math.floor(row / 3);
int columnRow = (int) Math.floor(column / 3) + 1;
return (blockRow * 3) + columnRow;
}
public Puzz solve(Puzz arg, boolean top) throws Exception {
// Make an original copy of the array
Puzz p = (Puzz) arg.clone();
for (int i = 1; i < 10; i++) {
for (Square s : p.squaresByBlock.get(i)) {
if (s.value == 0) {
for (Integer number : NUMBERS) {
if (p.set(s.row, s.col, number)) {
// System.out.println(p);
Puzz solved = solve(p, false);
if (solved != null)
return solved;
}
}
// no numbers fit here, return null and backtrack
p.set(s.row, s.col, 0);
return null;
}
}
}
// Check for remaining 0's
for (Square s : p.entries) {
if (s.value == 0)
return null;
}
return p;
}
public Puzz scramble(int clues) throws Exception {
Puzz p = (Puzz) clone();
Random rand = new Random();
int removed = 0;
//Remove the last row, it is a freebie
int toRemove = 81 - clues - 15;
for (int c = 0; c < 9; c++) {
p.set(8, c, 0);
}
p.set(0, 0, 0);
p.set(0, 3, 0);
p.set(0, 6, 0);
p.set(3, 0, 0);
p.set(3, 3, 0);
p.set(3, 6, 0);
// Keeping track of this because randomly removing squares can potentially create an
// unsolvable situation
HashSet<Square> alreadyTried = new HashSet<Square>();
while (removed < toRemove) {
if (alreadyTried.size() >= ((toRemove + clues) - removed)) {
// Start over
removed = 0;
alreadyTried = new HashSet<Square>();
p = (Puzz)clone();
for (int c = 0; c < 9; c++) {
p.set(8, c, 0);
}
p.set(0, 0, 0);
p.set(0, 3, 0);
p.set(0, 6, 0);
p.set(3, 0, 0);
p.set(3, 3, 0);
p.set(3, 6, 0);
}
int randX = rand.nextInt((7) + 1);
int randY = rand.nextInt((8) + 1);
int existingValue = p.getValue(randX, randY);
if (existingValue != 0) {
p.set(randX, randY, 0);
// confirm it is still solvable after removing this item
Puzz psol = solve(p, true);
if (psol != null && psol.equals(this)) {
removed++;
alreadyTried = new HashSet<Square>();
System.out.println("Clues Remaining: " + (81 - 15 - removed));
} else {
// otherwise set it back to what it was and try again
p.set(randX, randY, existingValue);
Square s = new Square(randX, randY, existingValue, p);
alreadyTried.add(s);
}
}
}
p.updatePossibilities();
return p;
}
public static String encode(Puzz p) { // Remove all zero'ed items
StringBuffer sb = new StringBuffer();
for (int i = 0; i < 9; i++) {
for (Square s : p.squaresByRow.get(i)) {
if (s.value == 0)
continue;
sb.append(s.row).append(s.col).append(s.value);
}
}
// number mod 95 gives lowest digit, subtract that from original number
BigInteger num = new BigInteger(sb.toString());
byte[] numBytes = num.toByteArray();
StringBuffer retVal = new StringBuffer();
while (num.compareTo(BigInteger.ZERO) > 0) {
int modu = num.mod(new BigInteger("95")).intValue();
retVal.append((char) (modu + 32));
num = num.subtract(new BigInteger("" + modu));
num = num.divide(new BigInteger("95"));
}
return retVal.toString();
}
@Override
public boolean equals(Object arg0) {
if (arg0 == null || !(arg0 instanceof Puzz))
return false;
Puzz p = (Puzz) arg0;
for (int r = 0; r < 9; r++) {
for (int c = 0; c < 9; c++) {
int val1 = getValue(r, c);
int val2 = p.getValue(r, c);
if (val1 != val2)
return false;
}
}
return true;
}
@Override
protected Object clone() throws CloneNotSupportedException {
int[][] data = new int[9][9];
for (Square square : entries) {
data[square.row][square.col] = square.value;
}
return new Puzz(data);
}
@Override
public String toString() {
if (entries == null)
return "";
StringBuffer sb = new StringBuffer();
for (int r = 0; r < 9; r++) {
for (int c = 0; c < 9; c++) {
sb.append(getValue(r, c)).append(' ');
}
sb.append('\n');
}
return sb.toString();
}
}
class Square {
public Square(int row, int col, Puzz p) {
this.row = row;
this.col = col;
this.p = p;
}
public Square(int row, int col, int value, Puzz p) {
this(row, col, p);
this.value = value;
}
int row;
int col;
int value;
HashSet<Integer> possibilities = new HashSet<Integer>(Puzz.NUMBERS);
Puzz p;
@Override
protected Object clone() throws CloneNotSupportedException {
Square s = new Square(row, col, value, p);
s.possibilities = new HashSet<Integer>();
for (Integer val : possibilities) {
s.possibilities.add(new Integer(val));
}
return s;
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Square))
return false;
Square s = (Square) obj;
return row == s.row && col == s.col && value == s.value
&& p.equals(s.p);
}
@Override
public int hashCode() {
return row ^ col ^ value ^ p.hashCode();
}
}
class Dubs {
int p1;
int p2;
int row, col;
public Dubs(int p1, int p2) {
this.p1 = p1;
this.p2 = p2;
}
public Dubs(int p1, int p2, int row, int col) {
this(p1, p2);
this.row = row;
this.col = col;
}
public boolean containedWithin(int value) {
return (p1 == value || p2 == value);
}
@Override
public boolean equals(Object arg0) {
if (!(arg0 instanceof Dubs))
return false;
Dubs d = (Dubs) arg0;
return (this.p1 == d.p1 || this.p1 == d.p2)
&& (this.p2 == d.p1 || this.p2 == d.p2);
}
}
class Trips {
int p1;
int p2;
int p3;
int row, col;
public Trips(int p1, int p2) {
this.p1 = p1;
this.p2 = p2;
}
public Trips(int p1, int p2, int p3) {
this(p1, p2);
this.p3 = p3;
}
public Trips(int p1, int p2, int p3, int row, int col) {
this(p1, p2, p3);
this.row = row;
this.col = col;
}
public boolean containedWithin(int value) {
return (p1 == value || p2 == value || p3 == value);
}
public boolean containedWithin(Dubs d) {
return (d.p1 == p1 || d.p1 == p2 || d.p1 == p3)
&& (d.p2 == p1 || d.p2 == p2 || d.p2 == p3);
}
public boolean equals(Object arg0) {
if (!(arg0 instanceof Trips))
return false;
Trips t = (Trips) arg0;
return (this.p1 == t.p1 || this.p1 == t.p2 || this.p1 == t.p3)
&& (this.p2 == t.p1 || this.p2 == t.p2 || this.p2 == t.p3)
&& (this.p3 == t.p1 || this.p3 == t.p2 || this.p3 == t.p3);
}
}
Мой тестовый кейс
public class TestCompression extends TestCase {
public static int[][] test1 = new int[][] {
new int[] { 9, 7, 3, 5, 8, 1, 4, 2, 6 },
new int[] { 5, 2, 6, 4, 7, 3, 1, 9, 8 },
new int[] { 1, 8, 4, 2, 9, 6, 7, 5, 3 },
new int[] { 2, 4, 7, 8, 6, 5, 3, 1, 9 },
new int[] { 3, 9, 8, 1, 2, 4, 6, 7, 5 },
new int[] { 6, 5, 1, 7, 3, 9, 8, 4, 2 },
new int[] { 8, 1, 9, 3, 4, 2, 5, 6, 7 },
new int[] { 7, 6, 5, 9, 1, 8, 2, 3, 4 },
new int[] { 4, 3, 2, 6, 5, 7, 9, 8, 1 } };
public static int[][] test2 = new int[][] {
new int[] { 7, 2, 4, 8, 6, 5, 1, 9, 3 },
new int[] { 1, 6, 9, 2, 4, 3, 8, 7, 5 },
new int[] { 3, 8, 5, 1, 9, 7, 2, 4, 6 },
new int[] { 8, 9, 6, 7, 2, 4, 3, 5, 1 },
new int[] { 2, 7, 3, 9, 5, 1, 6, 8, 4 },
new int[] { 4, 5, 1, 3, 8, 6, 9, 2, 7 },
new int[] { 5, 4, 2, 6, 3, 9, 7, 1, 8 },
new int[] { 6, 1, 8, 5, 7, 2, 4, 3, 9 },
new int[] { 9, 3, 7, 4, 1, 8, 5, 6, 2 } };
public static int[][] test3 = new int[][] {
new int[] { 1, 5, 7, 6, 8, 2, 3, 4, 9 },
new int[] { 4, 3, 2, 5, 1, 9, 6, 8, 7 },
new int[] { 6, 9, 8, 3, 4, 7, 2, 5, 1 },
new int[] { 8, 2, 5, 4, 7, 6, 1, 9, 3 },
new int[] { 7, 1, 3, 9, 2, 8, 4, 6, 5 },
new int[] { 9, 6, 4, 1, 3, 5, 7, 2, 8 },
new int[] { 5, 4, 1, 2, 9, 3, 8, 7, 6 },
new int[] { 2, 8, 9, 7, 6, 1, 5, 3, 4 },
new int[] { 3, 7, 6, 8, 5, 4, 9, 1, 2 } };
public static int[][] test4 = new int[][] {
new int[] { 8, 3, 5, 4, 1, 6, 9, 2, 7 },
new int[] { 2, 9, 6, 8, 5, 7, 4, 3, 1 },
new int[] { 4, 1, 7, 2, 9, 3, 6, 5, 8 },
new int[] { 5, 6, 9, 1, 3, 4, 7, 8, 2 },
new int[] { 1, 2, 3, 6, 7, 8, 5, 4, 9 },
new int[] { 7, 4, 8, 5, 2, 9, 1, 6, 3 },
new int[] { 6, 5, 2, 7, 8, 1, 3, 9, 4 },
new int[] { 9, 8, 1, 3, 4, 5, 2, 7, 6 },
new int[] { 3, 7, 4, 9, 6, 2, 8, 1, 5 } };
public static int[][] test5 = new int[][] {
new int[] { 6, 2, 8, 4, 5, 1, 7, 9, 3 },
new int[] { 5, 9, 4, 7, 3, 2, 6, 8, 1 },
new int[] { 7, 1, 3, 6, 8, 9, 5, 4, 2 },
new int[] { 2, 4, 7, 3, 1, 5, 8, 6, 9 },
new int[] { 9, 6, 1, 8, 2, 7, 3, 5, 4 },
new int[] { 3, 8, 5, 9, 6, 4, 2, 1, 7 },
new int[] { 1, 5, 6, 2, 4, 3, 9, 7, 8 },
new int[] { 4, 3, 9, 5, 7, 8, 1, 2, 6 },
new int[] { 8, 7, 2, 1, 9, 6, 4, 3, 5 } };
public static int[][] test6 = new int[][] {
new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 },
new int[] { 4, 5, 6, 7, 8, 9, 1, 2, 3 },
new int[] { 7, 8, 9, 1, 2, 3, 4, 5, 6 },
new int[] { 2, 1, 4, 3, 6, 5, 8, 9, 7 },
new int[] { 3, 6, 5, 8, 9, 7, 2, 1, 4 },
new int[] { 8, 9, 7, 2, 1, 4, 3, 6, 5 },
new int[] { 5, 3, 1, 6, 4, 8, 9, 7, 2 },
new int[] { 6, 4, 8, 9, 7, 2, 5, 3, 1 },
new int[] { 9, 7, 2, 5, 3, 1, 6, 4, 8 } };
public static int[][] test7 = new int[][] {
new int[] { 1, 4, 5, 7, 9, 2, 8, 3, 6 },
new int[] { 3, 7, 6, 5, 8, 4, 1, 9, 2 },
new int[] { 2, 9, 8, 3, 6, 1, 7, 5, 4 },
new int[] { 7, 3, 1, 9, 2, 8, 6, 4, 5 },
new int[] { 8, 5, 9, 6, 4, 7, 3, 2, 1 },
new int[] { 4, 6, 2, 1, 3, 5, 9, 8, 7 },
new int[] { 6, 2, 4, 8, 7, 3, 5, 1, 9 },
new int[] { 5, 8, 7, 4, 1, 9, 2, 6, 3 },
new int[] { 9, 1, 3, 2, 5, 6, 4, 7, 8 } };
public static int[][] test8 = new int[][] {
new int[] { 5, 2, 7, 4, 1, 6, 9, 3, 8 },
new int[] { 8, 6, 4, 3, 2, 9, 1, 5, 7 },
new int[] { 1, 3, 9, 5, 7, 8, 6, 4, 2 },
new int[] { 2, 9, 1, 8, 5, 4, 3, 7, 6 },
new int[] { 3, 4, 8, 6, 9, 7, 5, 2, 1 },
new int[] { 6, 7, 5, 1, 3, 2, 4, 8, 9 },
new int[] { 7, 1, 2, 9, 4, 5, 8, 6, 3 },
new int[] { 4, 8, 3, 2, 6, 1, 7, 9, 5 },
new int[] { 9, 5, 6, 7, 8, 3, 2, 1, 4 } };
public static int[][] test9 = new int[][] {
new int[] { 2, 4, 6, 7, 1, 3, 9, 8, 5 },
new int[] { 1, 8, 5, 4, 9, 6, 7, 3, 2 },
new int[] { 9, 3, 7, 8, 2, 5, 1, 4, 6 },
new int[] { 6, 7, 8, 5, 4, 2, 3, 9, 1 },
new int[] { 4, 9, 3, 1, 6, 8, 2, 5, 7 },
new int[] { 5, 1, 2, 3, 7, 9, 4, 6, 8 },
new int[] { 8, 2, 4, 9, 5, 7, 6, 1, 3 },
new int[] { 7, 5, 9, 6, 3, 1, 8, 2, 4 },
new int[] { 3, 6, 1, 2, 8, 4, 5, 7, 9 } };
public static int[][] test10 = new int[][] {
new int[] { 8, 6, 1, 2, 9, 4, 5, 7, 3 },
new int[] { 4, 7, 5, 3, 1, 8, 6, 9, 2 },
new int[] { 3, 9, 2, 5, 6, 7, 8, 1, 4 },
new int[] { 2, 3, 6, 4, 5, 9, 7, 8, 1 },
new int[] { 1, 5, 4, 7, 8, 3, 2, 6, 9 },
new int[] { 9, 8, 7, 6, 2, 1, 3, 4, 5 },
new int[] { 5, 2, 9, 1, 7, 6, 4, 3, 8 },
new int[] { 6, 4, 8, 9, 3, 2, 1, 5, 7 },
new int[] { 7, 1, 3, 8, 4, 5, 9, 2, 6 } };
@Test
public void test2() throws Exception {
int encodedLength = 0;
Puzz expected = new Puzz(test1);
Puzz test = (Puzz) expected.clone();
long start = System.currentTimeMillis();
test = test.scramble(22);
long duration = System.currentTimeMillis() - start;
System.out.println("Duration of scramble for 22 clue puzzle: " + duration);
System.out.println("Scrambled");
System.out.println(test);
String encoded = Puzz.encode(test);
System.out.println("Encoded Length with BigInteger: " + encoded.length());
encodedLength += encoded.length();
expected = new Puzz(test2);
test = (Puzz) expected.clone();
start = System.currentTimeMillis();
test = test.scramble(22);
duration = System.currentTimeMillis() - start;
System.out.println("Duration of scramble for 22 clue puzzle: " + duration);
System.out.println("Scrambled");
System.out.println(test);
encoded = Puzz.encode(test);
System.out.println("Encoded Length with BigInteger: " + encoded.length());
encodedLength += encoded.length();
expected = new Puzz(test3);
test = (Puzz) expected.clone();
start = System.currentTimeMillis();
test = test.scramble(22);
duration = System.currentTimeMillis() - start;
System.out.println("Duration of scramble for 22 clue puzzle: " + duration);
System.out.println("Scrambled");
System.out.println(test);
encoded = Puzz.encode(test);
System.out.println("Encoded Length with BigInteger: " + encoded.length());
encodedLength += encoded.length();
expected = new Puzz(test4);
test = (Puzz) expected.clone();
start = System.currentTimeMillis();
test = test.scramble(22);
duration = System.currentTimeMillis() - start;
System.out.println("Duration of scramble for 22 clue puzzle: " + duration);
System.out.println("Scrambled");
System.out.println(test);
encoded = Puzz.encode(test);
System.out.println("Encoded Length with BigInteger: " + encoded.length());
encodedLength += encoded.length();
expected = new Puzz(test5);
test = (Puzz) expected.clone();
start = System.currentTimeMillis();
test = test.scramble(22);
duration = System.currentTimeMillis() - start;
System.out.println("Duration of scramble for 22 clue puzzle: " + duration);
System.out.println("Scrambled");
System.out.println(test);
encoded = Puzz.encode(test);
System.out.println("Encoded Length with BigInteger: " + encoded.length());
encodedLength += encoded.length();
expected = new Puzz(test6);
test = (Puzz) expected.clone();
start = System.currentTimeMillis();
test = test.scramble(22);
duration = System.currentTimeMillis() - start;
System.out.println("Duration of scramble for 22 clue puzzle: " + duration);
System.out.println("Scrambled");
System.out.println(test);
encoded = Puzz.encode(test);
System.out.println("Encoded Length with BigInteger: " + encoded.length());
encodedLength += encoded.length();
expected = new Puzz(test7);
test = (Puzz) expected.clone();
start = System.currentTimeMillis();
test = test.scramble(22);
duration = System.currentTimeMillis() - start;
System.out.println("Duration of scramble for 22 clue puzzle: " + duration);
System.out.println("Scrambled");
System.out.println(test);
encoded = Puzz.encode(test);
System.out.println("Encoded Length with BigInteger: " + encoded.length());
encodedLength += encoded.length();
expected = new Puzz(test8);
test = (Puzz) expected.clone();
start = System.currentTimeMillis();
test = test.scramble(22);
duration = System.currentTimeMillis() - start;
System.out.println("Duration of scramble for 22 clue puzzle: " + duration);
System.out.println("Scrambled");
System.out.println(test);
encoded = Puzz.encode(test);
System.out.println("Encoded Length with BigInteger: " + encoded.length());
encodedLength += encoded.length();
expected = new Puzz(test9);
test = (Puzz) expected.clone();
start = System.currentTimeMillis();
test = test.scramble(22);
duration = System.currentTimeMillis() - start;
System.out.println("Duration of scramble for 22 clue puzzle: " + duration);
System.out.println("Scrambled");
System.out.println(test);
encoded = Puzz.encode(test);
System.out.println("Encoded Length with BigInteger: " + encoded.length());
encodedLength += encoded.length();
expected = new Puzz(test10);
test = (Puzz) expected.clone();
start = System.currentTimeMillis();
test = test.scramble(22);
duration = System.currentTimeMillis() - start;
System.out.println("Duration of scramble for 22 clue puzzle: " + duration);
System.out.println("Scrambled");
System.out.println(test);
encoded = Puzz.encode(test);
encodedLength += encoded.length();
System.out.println("Final Result: " + encodedLength);
}
}
Тестовый вывод
Duration of scramble for 22 clue puzzle: 427614
Scrambled
0 0 3 0 0 0 0 0 6
0 2 0 0 0 0 0 9 0
0 0 0 0 9 6 7 5 0
0 4 0 0 0 5 0 1 0
0 0 0 1 0 0 0 0 0
0 5 0 0 0 0 8 4 0
0 0 0 3 0 0 5 0 7
7 0 0 9 0 8 0 3 0
0 0 0 0 0 0 0 0 0
Building encoded string: U5[XZ+C6Bgf)}O."gDE)`\)kNv7*6}1w+
Encoded Length with BigInteger: 33
Duration of scramble for 22 clue puzzle: 167739
Scrambled
0 2 4 0 0 0 0 0 0
1 6 0 0 4 0 8 0 5
0 0 5 0 9 7 2 0 0
0 0 0 0 2 4 0 0 1
0 0 3 9 0 0 0 0 0
0 0 0 0 0 0 0 0 7
0 4 0 0 0 0 0 0 8
0 1 0 5 0 0 0 3 0
0 0 0 0 0 0 0 0 0
Building encoded string: 7\c^oE}`H6@P.&E)Zu\t>B"k}Vf<[0a3&
Encoded Length with BigInteger: 33
Duration of scramble for 22 clue puzzle: 136364
Scrambled
0 0 7 0 8 0 0 0 0
0 3 2 0 0 9 6 0 0
0 0 0 0 0 0 2 5 0
0 2 0 0 0 6 0 0 0
0 0 0 9 0 0 0 0 0
0 0 4 1 0 5 7 2 0
5 0 1 0 0 0 0 7 0
2 8 9 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
Building encoded string: [S#bHlTDwS,&w,moQ{WN}Z9!{1C>.vN{-
Encoded Length with BigInteger: 33
Duration of scramble for 22 clue puzzle: 392150
Scrambled
0 0 0 0 0 6 0 0 0
0 9 0 0 0 0 0 0 1
4 0 0 0 0 3 6 0 8
0 0 0 0 0 0 0 8 0
0 0 3 0 7 8 0 0 9
7 0 0 0 0 0 0 0 3
6 0 2 0 0 0 0 9 0
9 0 1 3 4 0 2 0 0
0 0 0 0 0 0 0 0 0
Building encoded string: T-yKJ2<d)Dj~[~>]334*9YpxM<JQNf2|<
Encoded Length with BigInteger: 33
Duration of scramble for 22 clue puzzle: 169355
Scrambled
0 0 0 0 0 1 0 0 0
0 9 4 7 0 0 0 8 0
0 1 3 0 0 0 5 0 2
0 0 0 0 0 0 0 0 9
0 0 0 0 2 7 3 5 4
0 8 0 0 0 0 0 1 0
0 0 0 0 4 0 9 0 8
0 0 0 5 0 0 0 0 6
0 0 0 0 0 0 0 0 0
Building encoded string: 5@.=FmOKws7jl5*hWMQqqou\lv'e^Q}D:
Encoded Length with BigInteger: 33
Duration of scramble for 22 clue puzzle: 786
Scrambled
0 2 3 0 0 6 0 0 0
0 5 0 7 0 0 1 2 3
0 8 0 0 2 0 0 0 0
0 0 0 0 0 5 0 0 7
0 6 5 8 0 0 0 0 0
0 0 7 0 0 4 3 0 0
0 3 0 0 4 0 0 0 2
0 0 0 0 0 2 0 0 0
0 0 0 0 0 0 0 0 0
Building encoded string: wY%(O9tOSDZu-PBaFl^.f0xH7C~e)=\3&
Encoded Length with BigInteger: 33
Duration of scramble for 22 clue puzzle: 826530
Scrambled
0 0 0 0 9 0 0 0 0
0 0 0 0 0 0 0 0 0
0 9 0 3 0 1 7 0 0
0 3 0 0 0 8 0 4 5
0 0 9 0 0 7 3 0 0
0 0 2 0 3 0 0 8 0
6 0 0 0 0 0 0 0 9
5 0 0 4 1 0 2 0 3
0 0 0 0 0 0 0 0 0
Building encoded string: K|>.Aa?,8e&NRL;*ut=+Iqk8E$@&-zlF9
Encoded Length with BigInteger: 33
Duration of scramble for 22 clue puzzle: 4834
Scrambled
0 2 0 0 1 0 0 3 8
8 6 0 3 0 0 1 0 0
0 0 0 0 0 8 6 0 2
0 0 0 0 0 0 0 7 0
0 0 8 0 0 0 0 0 0
0 0 0 0 3 0 0 0 0
0 0 2 0 0 5 8 0 3
4 0 0 0 0 1 7 9 0
0 0 0 0 0 0 0 0 0
Building encoded string: GOS0!r=&HR5PZ|ezy>*l7 HWU`wIN7Q4&
Encoded Length with BigInteger: 33
Duration of scramble for 22 clue puzzle: 42126
Scrambled
0 0 0 0 0 3 0 0 5
0 0 5 4 0 0 0 3 2
9 0 0 8 0 0 0 0 0
0 0 0 0 0 2 0 0 0
0 0 0 0 6 8 2 0 7
5 1 0 0 7 0 0 0 8
8 0 0 0 5 0 0 1 0
7 0 0 0 0 0 0 0 4
0 0 0 0 0 0 0 0 0
Building encoded string: [4#9D_?I1.!h];Y_2!iqLyngbBJ&k)FF;
Encoded Length with BigInteger: 33
Duration of scramble for 22 clue puzzle: 156182
Scrambled
0 6 0 0 0 0 0 7 0
4 0 5 3 1 0 0 0 2
0 0 0 0 6 0 0 0 0
0 3 0 0 0 9 0 8 1
0 0 0 0 0 0 0 0 0
0 0 7 0 0 1 0 4 5
5 0 9 0 0 0 0 0 8
6 0 0 0 3 2 0 0 0
0 0 0 0 0 0 0 0 0
Building encoded string: r+a;I%hGj4YCA-pXz+n=ioRL:agzH'K<(
Encoded Length with BigInteger: 33
Final Result: 330