File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed
Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ const input = require ( 'fs' )
2+ . readFileSync ( process . platform === 'linux' ? '/dev/stdin' : './input.txt' )
3+ . toString ( )
4+ . trim ( )
5+ . split ( '\n' )
6+ . map ( e => e . split ( ' ' ) . map ( Number ) ) ;
7+
8+ function solution ( ) {
9+ const testCase = input ;
10+ let firstCase = true ;
11+
12+ for ( let i = 0 ; i < testCase . length - 1 ; i ++ ) {
13+ const k = testCase [ i ] [ 0 ] ;
14+ const arr = testCase [ i ] . slice ( 1 ) ;
15+ const result = [ ] ;
16+ const temp = [ ] ;
17+
18+ function recursive ( depth , start ) {
19+ if ( depth === 6 ) {
20+ result . push ( temp . join ( ' ' ) ) ;
21+ return ;
22+ }
23+
24+ for ( let i = start ; i < k ; i ++ ) {
25+ const curr = arr [ i ] ;
26+ temp . push ( curr ) ;
27+ recursive ( depth + 1 , i + 1 ) ;
28+ temp . pop ( ) ;
29+ }
30+
31+ }
32+
33+ if ( ! firstCase ) {
34+ console . log ( '' ) ;
35+ }
36+ firstCase = false ;
37+ recursive ( 0 , 0 ) ;
38+ console . log ( result . join ( '\n' ) ) ;
39+
40+ }
41+
42+
43+ }
44+
45+ solution ( ) ;
Original file line number Diff line number Diff line change 1+ function solution ( food ) {
2+ const result = [ ] ;
3+ for ( let i = 1 ; i < food . length ; i ++ ) {
4+ const count = Math . floor ( food [ i ] / 2 ) ;
5+ for ( let j = 0 ; j < count ; j ++ ) {
6+ result . push ( i ) ;
7+ }
8+ }
9+ const reverse = [ ...result ] . reverse ( ) ;
10+
11+ return result . join ( '' ) + '0' + reverse . join ( '' ) ;
12+ }
You can’t perform that action at this time.
0 commit comments