File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed
Filter options
Expand file tree Collapse file tree 1 file changed +24
-1
lines changed
Original file line number Diff line number Diff line change 1
1
export default function Day ( data ) {
2
2
const { stacks, instructions} = extractStacks ( data ) ;
3
- console . log ( stacks ) ;
3
+ executeInstructions ( stacks , instructions ) ;
4
+ topOfStacks ( stacks ) ;
5
+ }
6
+
7
+ function topOfStacks ( stacks ) {
8
+ let solutionString = '' ;
9
+ stacks . forEach ( stack => {
10
+ solutionString += stack [ stack . length - 1 ] . substr ( 1 , 1 ) ;
11
+ } ) ;
12
+
13
+ console . log ( solutionString ) ;
14
+ }
15
+
16
+ function executeInstructions ( stacks , instructions ) {
17
+ instructions . forEach ( row => {
18
+ const instruction = row . split ( ' ' ) ;
19
+ const amount = parseInt ( instruction [ 1 ] ) ;
20
+ const fromStack = parseInt ( instruction [ 3 ] ) - 1 ;
21
+ const toStack = parseInt ( instruction [ 5 ] ) - 1 ;
22
+
23
+ for ( let i = 0 ; i < amount ; i ++ ) {
24
+ stacks [ toStack ] . push ( stacks [ fromStack ] . pop ( ) ) ;
25
+ }
26
+ } ) ;
4
27
}
5
28
6
29
function extractStacks ( data ) {
You can’t perform that action at this time.
0 commit comments