@@ -4,12 +4,7 @@ function encode(input) {
4
4
var num ;
5
5
var factor ;
6
6
var str ;
7
-
8
- // cells.getColorIndex("red");
9
- // cells.getColorValue(4);
10
- // cells.blankCellColor
11
- // currentCell.element.classList
12
-
7
+ var encodingList = [ "0" , "1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , "A" , "B" , "C" , "D" , "E" , "F" , "G" , "H" , "I" , "J" , "K" , "L" , "M" , "N" , "O" , "P" , "Q" , "R" , "S" , "T" , "U" , "V" , "W" , "X" , "Y" , "Z" , "a" , "b" , "c" , "d" , "e" , "f" , "g" , "h" , "i" , "j" , "k" , "l" , "m" , "n" , "o" , "p" , "q" , "r" , "s" , "t" , "u" , "v" , "w" , "x" , "y" , "z" ] ;
13
8
14
9
for ( var i = 0 ; i < 81 ; i ++ ) {
15
10
currentCell = cells [ i ] ;
@@ -29,17 +24,24 @@ function encode(input) {
29
24
num += factor * ( currentCell . isGiven ? 1 : 0 ) ;
30
25
factor *= 2 ;
31
26
32
- str = num . toString ( 36 ) ;
27
+ num += factor * currentCell . getColor ( ) ;
28
+ factor *= 5 ;
29
+
30
+ str = encodingList [ num / 3844 | 0 ] ;
31
+ str += encodingList [ ( num / 62 | 0 ) % 62 ] ;
32
+ str += encodingList [ num % 62 ] ;
33
33
34
34
while ( str . length < 3 ) {
35
35
str = "0" + str ;
36
36
}
37
37
38
38
result += str ;
39
39
}
40
+
41
+ result += cells . blankCellColor ;
42
+
40
43
return result ;
41
44
42
-
43
45
}
44
46
45
47
function decode ( input ) {
@@ -48,16 +50,31 @@ function decode(input) {
48
50
var str ;
49
51
var num ;
50
52
var factor ;
53
+ var values = "" ;
54
+ var decodingList = { "0" :0 , "1" :1 , "2" :2 , "3" :3 , "4" :4 , "5" :5 , "6" :6 , "7" :7 , "8" :8 , "9" :9 , "A" :10 , "B" :11 , "C" :12 , "D" :13 , "E" :14 , "F" :15 , "G" :16 , "H" :17 , "I" :18 , "J" :19 , "K" :20 , "L" :21 , "M" :22 , "N" :23 , "O" :24 , "P" :25 , "Q" :26 , "R" :27 , "S" :28 , "T" :29 , "U" :30 , "V" :31 , "W" :32 , "X" :33 , "Y" :34 , "Z" :35 , "a" :36 , "b" :37 , "c" :38 , "d" :39 , "e" :40 , "f" :41 , "g" :42 , "h" :43 , "i" :44 , "j" :45 , "k" :46 , "l" :47 , "m" :48 , "n" :49 , "o" :50 , "p" :51 , "q" :52 , "r" :53 , "s" :54 , "t" :55 , "u" :56 , "v" :57 , "w" :58 , "x" :59 , "y" :60 , "z" :61 } ;
55
+ var colorsEncoded = true ;
56
+
57
+ input = input . replace ( / [ ^ 0 - 9 A - Z a - z ] / g, "" )
51
58
52
- if ( input . length !== 243 ) {
59
+ if ( input . length !== 243 && input . length !== 244 ) {
60
+ alert ( "Invalid input." ) ;
53
61
return ;
54
62
}
55
63
64
+ colorsEncoded = input . length === 244 ;
65
+
56
66
for ( var i = 0 ; i < 81 ; i ++ ) {
57
67
currentCell = cells [ i ] ;
58
68
59
69
factor = 1 ;
60
- num = parseInt ( input . slice ( i * 3 , i * 3 + 3 ) , 36 ) ;
70
+
71
+ if ( colorsEncoded ) {
72
+ num = decodingList [ input . charAt ( i * 3 ) ] * 3844 ;
73
+ num += decodingList [ input . charAt ( i * 3 + 1 ) ] * 62 ;
74
+ num += decodingList [ input . charAt ( i * 3 + 2 ) ] ;
75
+ } else {
76
+ num = parseInt ( input . slice ( i * 3 , i * 3 + 3 ) , 36 ) ;
77
+ }
61
78
62
79
for ( var j = 0 ; j < 9 ; j ++ ) {
63
80
factor = 2 ;
@@ -69,28 +86,68 @@ function decode(input) {
69
86
70
87
factor = 10 ;
71
88
currentCell . setValue ( num % factor ) ;
89
+ values += num % factor + "" ;
72
90
num = ( num / factor ) | 0 ;
73
91
74
92
factor = 2 ;
75
93
currentCell . isGiven = ! ! ( num % factor ) ;
76
94
num = ( num / factor ) | 0 ;
77
95
96
+ factor = 5 ;
97
+ currentCell . setColor ( num % factor ) ;
98
+ num = ( num / factor ) | 0 ;
99
+
78
100
if ( currentCell . isGiven ) {
79
101
currentCell . element . innerHTML = currentCell . value ;
102
+ currentCell . candidatesElement . innerHTML = currentCell . value ;
80
103
} else {
81
104
if ( currentCell . value ) {
82
105
currentCell . element . firstChild . value = currentCell . value ;
106
+ currentCell . candidatesElement . innerHTML = currentCell . value ;
83
107
} else {
108
+ // Update pencilmarks display.
109
+ currentCell . candidatesElement . innerHTML = currentCell . getPencilmarkString ( ) ;
84
110
currentCell . element . firstChild . value = "" ;
85
111
86
112
}
87
113
}
88
114
89
- // Update pencilmarks display.
90
- currentCell . candidatesElement . innerHTML = currentCell . getPencilmarkString ( ) ;
115
+ }
116
+
117
+ cells . blankCellColor = parseInt ( input . charAt ( 243 ) ) ;
118
+
119
+ // Highlight selected color link.
120
+ document . getElementById ( "mark_blank_cells_0" ) . style . backgroundColor = "" ;
121
+ document . getElementById ( "mark_blank_cells_" + cells . blankCellColor ) . style . backgroundColor = "#FF8" ;
122
+
123
+
124
+ var puzzle = new Puzzle ( values ) ;
125
+
126
+ if ( ! puzzle . hasSolution ( ) ) {
127
+ alert ( "There is no solution for the inputted values." ) ;
128
+ return ;
91
129
}
92
130
93
- submitGivens ( ) ;
131
+ document . getElementById ( "top_bar" ) . style . display = "none" ;
132
+ document . getElementById ( "begin_solving" ) . style . display = "none" ;
133
+ document . getElementById ( "controls" ) . style . display = "block" ;
134
+ document . getElementById ( "grid_table" ) . style . position = "static" ;
135
+ document . getElementById ( "grid_table" ) . style . marginTop = "8px" ;
136
+ document . getElementById ( "grid_table" ) . style . marginLeft = "8px" ;
137
+ document . getElementById ( "side_bar" ) . style . display = "none" ;
138
+
139
+ document . getElementById ( "import_save_button" ) . title = "This option is disabled when a sudoku puzzle is in progress." ;
140
+ document . getElementById ( "import_save_button" ) . disabled = true ;
141
+ document . getElementById ( "paste_puzzle_button" ) . title = "This option is disabled when a sudoku puzzle is in progress." ;
142
+ document . getElementById ( "paste_puzzle_button" ) . disabled = true ;
143
+ document . getElementById ( "load_cookie" ) . title = "This option is disabled when a sudoku puzzle is in progress." ;
144
+ document . getElementById ( "load_cookie" ) . disabled = true ;
145
+
146
+ cells . solution = puzzle . toString ( ) ;
147
+ for ( var i = 0 ; i < 81 ; i ++ ) {
148
+ cells [ i ] . solution = parseInt ( cells . solution . charAt ( i ) ) ;
149
+ }
150
+
94
151
showDuplicates ( ) ;
95
152
}
96
153
0 commit comments