11// putting the environment variables or global variables up top
22// not sure what we call these ...
33let last_output = [
4- [ 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' ] ,
5- [ 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' ] ,
6- [ 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' ] ,
7- [ 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' ] ,
8- [ 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' ] ,
9- [ 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' ] ,
10- [ 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' ] ,
11- [ 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' ] ,
12- [ 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' ] ,
13- [ 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' ] ,
14- [ 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' ] ,
15- [ 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' ] ,
16- [ 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' ] ,
17- [ 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' ] ,
18- [ 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' ] ,
19- [ 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' ] ,
20- [ 'G' , 'G' , 'G' , 'N' , 'N' , 'N' , 'G' , 'G' , 'G' , 'G' ] ,
21- [ 'G' , 'G' , 'G' , 'N' , 'N' , 'N' , 'G' , 'G' , 'G' , 'G' ] ,
22- [ 'G' , 'G' , 'G' , 'N' , 'N' , 'N' , 'G' , 'G' , 'G' , 'G' ] ,
23- [ 'G' , 'G' , 'G' , 'N' , 'N' , 'N' , 'G' , 'G' , 'G' , 'G' ] ] . reverse ( ) ;
4+ [ "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" ] ,
5+ [ "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" ] ,
6+ [ "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" ] ,
7+ [ "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" ] ,
8+ [ "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" ] ,
9+ [ "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" ] ,
10+ [ "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" ] ,
11+ [ "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" ] ,
12+ [ "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" ] ,
13+ [ "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" ] ,
14+ [ "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" ] ,
15+ [ "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" ] ,
16+ [ "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" ] ,
17+ [ "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" ] ,
18+ [ "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" ] ,
19+ [ "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" , "N" ] ,
20+ [ "G" , "G" , "G" , "N" , "N" , "N" , "G" , "G" , "G" , "G" ] ,
21+ [ "G" , "G" , "G" , "N" , "N" , "N" , "G" , "G" , "G" , "G" ] ,
22+ [ "G" , "G" , "G" , "N" , "N" , "N" , "G" , "G" , "G" , "G" ] ,
23+ [ "G" , "G" , "G" , "N" , "N" , "N" , "G" , "G" , "G" , "G" ] ,
24+ ] . reverse ( ) ;
2425
2526var weight_table = [
2627 [ 1 , 0 , 0 ] ,
@@ -37,7 +38,7 @@ var weight_table = [
3738 [ 0 , 0 , 0 ] ,
3839 [ 0 , 0 , 0 ] ,
3940 [ 0 , 0 , 0 ] ,
40- [ 0 , 0 , 0 ]
41+ [ 0 , 0 , 0 ] ,
4142] ;
4243// this is a subset of the queues that solve 3x4 box.
4344var queues = [
@@ -55,199 +56,192 @@ var queues = [
5556 [ "JLZO" , "JLZI" , "LJZI" ] , // Array with 32 elements
5657 [ "LJSO" , "SJOL" , "SJLO" ] , // Array with 32 elements
5758 [ "SLTJ" , "LSTJ" , "LTSJ" ] , // Array with 32 elements
58- [ "TJZL" , "TJLZ" , "JTLZ" ] // Array with 32 elements
59+ [ "TJZL" , "TJLZ" , "JTLZ" ] , // Array with 32 elements
5960] ;
6061
61-
6262// the variable distributedQueues keeps track of how we order the queues.
63- const distributedQueuesButton = document . getElementById ( 'toggleDistributedQueues' )
63+ const distributedQueuesButton = document . getElementById (
64+ "toggleDistributedQueues" ,
65+ ) ;
6466
6567let distributedQueues = distributedQueuesButton . checked ;
6668
67- distributedQueuesButton . addEventListener ( 'change' , function ( ) {
68- distributedQueues = distributedQueuesButton . checked ;
69- } )
70-
71-
72- document . addEventListener ( 'DOMContentLoaded' , ( ) => {
73- const fileInputMD = document . getElementById ( 'mdFile' ) ;
74-
75- fileInputMD . addEventListener ( 'change' , function ( e ) {
76- const file = e . target . files [ 0 ] ;
77- if ( ! file ) return ;
78-
79- const reader = new FileReader ( ) ;
80-
81- reader . onload = function ( e ) {
82- const text = e . target . result ;
83- const parsedData = parse_md_queues ( text ) ;
84- queues = parsedData ;
85- weight_table = setup_weight_table ( queues )
86- } ;
87-
88- reader . readAsText ( file ) ;
89- } ) ;
69+ distributedQueuesButton . addEventListener ( "change" , function ( ) {
70+ distributedQueues = distributedQueuesButton . checked ;
9071} ) ;
9172
92- document . getElementById ( 'txtFile' ) . addEventListener ( 'change' , function ( event ) {
93- const file = event . target . files [ 0 ] ;
73+ document . addEventListener ( "DOMContentLoaded" , ( ) => {
74+ const fileInputMD = document . getElementById ( "mdFile" ) ;
75+
76+ fileInputMD . addEventListener ( "change" , function ( e ) {
77+ const file = e . target . files [ 0 ] ;
9478 if ( ! file ) return ;
9579
9680 const reader = new FileReader ( ) ;
81+
9782 reader . onload = function ( e ) {
98- const text = e . target . result ;
99- //document.getElementById('output').textContent = text;
100- last_output = parse_last_output ( text ) ;
83+ const text = e . target . result ;
84+ const parsedData = parse_md_queues ( text ) ;
85+ queues = parsedData ;
86+ weight_table = setup_weight_table ( queues ) ;
10187 } ;
88+
10289 reader . readAsText ( file ) ;
90+ } ) ;
91+ } ) ;
92+
93+ document . getElementById ( "txtFile" ) . addEventListener ( "change" , function ( event ) {
94+ const file = event . target . files [ 0 ] ;
95+ if ( ! file ) return ;
96+
97+ const reader = new FileReader ( ) ;
98+ reader . onload = function ( e ) {
99+ const text = e . target . result ;
100+ //document.getElementById('output').textContent = text;
101+ last_output = parse_last_output ( text ) ;
102+ } ;
103+ reader . readAsText ( file ) ;
103104} ) ;
104105
105106function parse_last_output ( text ) {
106- const lines = text . split ( '\n' ) ;
107- const field = [ ] ;
107+ const lines = text . split ( "\n" ) ;
108+ const field = [ ] ;
108109
109- let insideField = false ;
110+ let insideField = false ;
110111
111- for ( const line of lines ) {
112- const trimmed = line . trim ( ) ;
112+ for ( const line of lines ) {
113+ const trimmed = line . trim ( ) ;
113114
114- if ( trimmed . startsWith ( ' # Setup Field' ) ) {
115- insideField = true ;
116- continue ;
117- }
115+ if ( trimmed . startsWith ( " # Setup Field" ) ) {
116+ insideField = true ;
117+ continue ;
118+ }
118119
119- if ( insideField ) {
120- if ( trimmed === '' || trimmed . startsWith ( '#' ) ) break ;
120+ if ( insideField ) {
121+ if ( trimmed === "" || trimmed . startsWith ( "#" ) ) break ;
121122
122- // Convert each line into a row of G/N
123- const row = [ ...trimmed ] . map ( char => char === 'X' ? 'G' : 'N' ) ;
124- field . push ( row ) ;
125- }
123+ // Convert each line into a row of G/N
124+ const row = [ ...trimmed ] . map ( ( char ) => ( char === "X" ? "G" : "N" ) ) ;
125+ field . push ( row ) ;
126126 }
127+ }
127128
129+ // Pad with empty rows at the top to make it 20 rows tall
130+ const totalRows = 20 ;
131+ const numColumns = 10 ;
132+ const emptyRow = Array ( numColumns ) . fill ( "N" ) ;
128133
129- // Pad with empty rows at the top to make it 20 rows tall
130- const totalRows = 20 ;
131- const numColumns = 10 ;
132- const emptyRow = Array ( numColumns ) . fill ( 'N' ) ;
133-
134- const paddedField = [ ] ;
134+ const paddedField = [ ] ;
135135
136- const paddingCount = totalRows - field . length ;
137- for ( let i = 0 ; i < paddingCount ; i ++ ) {
138- paddedField . push ( [ ...emptyRow ] ) ;
139- }
136+ const paddingCount = totalRows - field . length ;
137+ for ( let i = 0 ; i < paddingCount ; i ++ ) {
138+ paddedField . push ( [ ...emptyRow ] ) ;
139+ }
140140
141- // Then add the original rows
142- paddedField . push ( ...field ) ;
141+ // Then add the original rows
142+ paddedField . push ( ...field ) ;
143143
144- return paddedField . reverse ( ) ;
144+ return paddedField . reverse ( ) ;
145145}
146146function setup_weight_table ( queues ) {
147- let out = queues . map ( subArr => subArr . slice ( ) ) ; // copy the array queues to out
148- for ( let i = 0 ; i < out . length ; i ++ ) {
149- for ( let j = 0 ; j < out [ i ] . length ; j ++ ) {
150- out [ i ] [ j ] = 0 ;
151- }
147+ let out = queues . map ( ( subArr ) => subArr . slice ( ) ) ; // copy the array queues to out
148+ for ( let i = 0 ; i < out . length ; i ++ ) {
149+ for ( let j = 0 ; j < out [ i ] . length ; j ++ ) {
150+ out [ i ] [ j ] = 0 ;
152151 }
153- return out ;
152+ }
153+ return out ;
154154}
155155
156156function parse_md_queues ( markdown ) {
157- const regex = / ` ` ` (?: \r ? \n ) ? ( [ \s \S ] * ?) ` ` ` / g;
158- const result = [ ] ;
159- let match ;
160-
161- while ( ( match = regex . exec ( markdown ) ) !== null ) {
162- const content = match [ 1 ] . trim ( ) ; // get the content inside the code block
163- const patterns = content . split ( ',' ) . map ( p => p . trim ( ) ) ;
164- if ( patterns . length > 0 && patterns [ 0 ] ) {
165- result . push ( patterns ) ;
166- }
157+ const regex = / ` ` ` (?: \r ? \n ) ? ( [ \s \S ] * ?) ` ` ` / g;
158+ const result = [ ] ;
159+ let match ;
160+
161+ while ( ( match = regex . exec ( markdown ) ) !== null ) {
162+ const content = match [ 1 ] . trim ( ) ; // get the content inside the code block
163+ const patterns = content . split ( "," ) . map ( ( p ) => p . trim ( ) ) ;
164+ if ( patterns . length > 0 && patterns [ 0 ] ) {
165+ result . push ( patterns ) ;
167166 }
167+ }
168168
169- return result ;
169+ return result ;
170170}
171171
172172function print_log ( ) {
173- console . log ( "last_output = " + last_output )
174- console . log ( "queues = " + queues )
175- console . log ( "weight_table = " + weight_table )
173+ console . log ( "last_output = " + last_output ) ;
174+ console . log ( "queues = " + queues ) ;
175+ console . log ( "weight_table = " + weight_table ) ;
176176}
177177
178-
179178// function for parsing the path_minimal_strict_file.md and storing the
180179// information in a meaningful way
181180function parse_path_minimal_strict_file ( ) {
182- document . getElementById ( 'mdFile' ) . addEventListener ( 'change' , function ( e ) {
183-
184- } ) ;
181+ document . getElementById ( "mdFile" ) . addEventListener ( "change" , function ( e ) { } ) ;
185182}
186183
187184function get_next_queue ( ) {
188- if ( distributedQueues ) {
189- //if distributedQueues is enabled, we want to cycle throught the queues in an
190- //interesting way. Basically I want it to not repeat a 'minimal' if
191- //there has been a puzzle in that row already.
192- return get_next_queue_helper ( ) ;
193- } else {
194- //else let's just iterate through them.
195- for ( let i = 0 ; i < weight_table . length ; i ++ ) {
196- for ( let j = 0 ; j < weight_table [ i ] . length ; j ++ ) {
197- if ( weight_table [ i ] [ j ] == 0 ) {
198- weight_table [ i ] [ j ] += 1 ;
199- return queues [ i ] [ j ] . split ( '' ) ;
200- }
201- }
185+ if ( distributedQueues ) {
186+ //if distributedQueues is enabled, we want to cycle throught the queues in an
187+ //interesting way. Basically I want it to not repeat a 'minimal' if
188+ //there has been a puzzle in that row already.
189+ return get_next_queue_helper ( ) ;
190+ } else {
191+ //else let's just iterate through them.
192+ for ( let i = 0 ; i < weight_table . length ; i ++ ) {
193+ for ( let j = 0 ; j < weight_table [ i ] . length ; j ++ ) {
194+ if ( weight_table [ i ] [ j ] == 0 ) {
195+ weight_table [ i ] [ j ] += 1 ;
196+ return queues [ i ] [ j ] . split ( "" ) ;
202197 }
203-
198+ }
204199 }
200+ }
205201}
206202
207203function get_lowest_row ( arr ) {
208- let minRowIndex = 0 ;
209- let minRowSum = arr [ 0 ] . reduce ( ( acc , val ) => acc + val , 0 ) ; // Sum of the first row
210-
211- // Loop through each row to find the row with the smallest sum of its elements
212- for ( let i = 1 ; i < arr . length ; i ++ ) {
213- let rowSum = arr [ i ] . reduce ( ( acc , val ) => acc + val , 0 ) ; // Sum of current row
214- if ( rowSum < minRowSum ) {
215- minRowSum = rowSum ;
216- minRowIndex = i ;
217- }
204+ let minRowIndex = 0 ;
205+ let minRowSum = arr [ 0 ] . reduce ( ( acc , val ) => acc + val , 0 ) ; // Sum of the first row
206+
207+ // Loop through each row to find the row with the smallest sum of its elements
208+ for ( let i = 1 ; i < arr . length ; i ++ ) {
209+ let rowSum = arr [ i ] . reduce ( ( acc , val ) => acc + val , 0 ) ; // Sum of current row
210+ if ( rowSum < minRowSum ) {
211+ minRowSum = rowSum ;
212+ minRowIndex = i ;
218213 }
214+ }
219215
220- // Return the index of the row with the lowest sum of elements
221- return minRowIndex ;
216+ // Return the index of the row with the lowest sum of elements
217+ return minRowIndex ;
222218}
223219
224-
225220function get_next_queue_helper ( ) {
226221 print_log ( ) ;
227- let row = get_lowest_row ( weight_table ) ; // Get the row with the smallest minimum value
228- console . log ( "row " + row )
222+ let row = get_lowest_row ( weight_table ) ; // Get the row with the smallest minimum value
223+ console . log ( "row " + row ) ;
229224 let lowestInRow = Math . min ( ...weight_table [ row ] ) ; // Get the smallest value in that row
230- console . log ( "lowestInRow " + lowestInRow )
225+ console . log ( "lowestInRow " + lowestInRow ) ;
231226 // Find the column index of the lowest value in that row
232227 let column = weight_table [ row ] . indexOf ( lowestInRow ) ;
233- console . log ( "column " + column )
228+ console . log ( "column " + column ) ;
234229 // Increment the weight value for that queue
235230 weight_table [ row ] [ column ] += 1 ;
236231
237232 // Return the corresponding queue as a string
238- return queues [ row ] [ column ] . split ( '' ) ;
233+ return queues [ row ] [ column ] . split ( "" ) ;
239234}
240235
241-
242236function find_lowest ( ) {
243237 let lowest = 100 ;
244- for ( let i = 0 ; i < weight_table . length ; i ++ ) {
245- for ( let j = 0 ; j < weight_table [ i ] . length ; j ++ ) {
238+ for ( let i = 0 ; i < weight_table . length ; i ++ ) {
239+ for ( let j = 0 ; j < weight_table [ i ] . length ; j ++ ) {
246240 if ( weight_table [ i ] [ j ] < lowest ) {
247241 lowest = weight_table [ i ] [ j ] ;
248242 }
249243 }
250244 }
251- console . log ( "lowest = " + lowest )
245+ console . log ( "lowest = " + lowest ) ;
252246 return lowest ;
253247}
0 commit comments