1
1
const fs = require ( 'fs' ) ;
2
- const FILENAME = 'input.txt' ;
2
+ const FILENAME = process . env . ADVENT_INPUT ;
3
+ const RANDOM_SHAPE = process . env . ADVENT_RANDOM_SHAPE ;
3
4
const WIDTH = 7 ;
4
5
5
6
class Shape {
@@ -423,13 +424,13 @@ fs.readFile( FILENAME, 'utf8', ( err, input ) => {
423
424
console . error ( err ) ;
424
425
return ;
425
426
}
426
- return ;
427
+
427
428
let g = new Grid ( WIDTH , input . trim ( ) ) ;
428
429
for ( var i = 0 ; i < 2022 ; i ++ ) {
429
430
g . drop ( ) ;
430
431
}
431
432
console . log ( g . display ( ) ) ;
432
- console . log ( "Height is : " + g . rock_level ( ) ) ;
433
+ console . log ( "PART1 : " + g . rock_level ( ) ) ;
433
434
} ) ;
434
435
435
436
// Part 2
@@ -445,8 +446,8 @@ fs.readFile( FILENAME, 'utf8', ( err, input ) => {
445
446
var last_height , height_diff , last_cycle , cycle_diff ;
446
447
for ( var i = 0 ; i < 10_000 ; i ++ ) {
447
448
g . drop ( ) ;
448
- // Random shapes which are known to occur in test input and real input
449
- if ( g . surface_shape ( ) == "ABBBBFF" || g . surface_shape ( ) == "GFAAHHF" ) {
449
+ // Random shape which is known to occur in input
450
+ if ( g . surface_shape ( ) == RANDOM_SHAPE ) {
450
451
let h = g . rock_level ( ) ;
451
452
if ( last_height ) {
452
453
height_diff = h - last_height ;
@@ -465,5 +466,6 @@ fs.readFile( FILENAME, 'utf8', ( err, input ) => {
465
466
for ( var i = 0 ; i < reduced ; i ++ ) {
466
467
g2 . drop ( ) ;
467
468
}
468
- console . log ( g2 . rock_level ( ) + ( plus_cycles * height_diff ) ) ;
469
+ let answer = g2 . rock_level ( ) + ( plus_cycles * height_diff ) ;
470
+ console . log ( "PART2: " + answer ) ;
469
471
} ) ;
0 commit comments