Skip to content

Commit 561c56f

Browse files
committed
Port 17 to new harness
1 parent d96aec4 commit 561c56f

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

2022/17/Javascript/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.PHONY: all
2+
all: run
3+
4+
.PHONY: clean
5+
clean:
6+
7+
.PHONY: run
8+
run:
9+
node main.js

2022/17/solution.js renamed to 2022/17/Javascript/main.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
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;
34
const WIDTH = 7;
45

56
class Shape {
@@ -423,13 +424,13 @@ fs.readFile( FILENAME, 'utf8', ( err, input ) => {
423424
console.error( err );
424425
return;
425426
}
426-
return;
427+
427428
let g = new Grid( WIDTH, input.trim() );
428429
for ( var i = 0; i < 2022; i++ ) {
429430
g.drop();
430431
}
431432
console.log( g.display() );
432-
console.log( "Height is: " + g.rock_level() );
433+
console.log( "PART1: " + g.rock_level() );
433434
} );
434435

435436
// Part 2
@@ -445,8 +446,8 @@ fs.readFile( FILENAME, 'utf8', ( err, input ) => {
445446
var last_height, height_diff, last_cycle, cycle_diff;
446447
for ( var i = 0; i < 10_000; i++ ) {
447448
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 ) {
450451
let h = g.rock_level();
451452
if ( last_height ) {
452453
height_diff = h - last_height;
@@ -465,5 +466,6 @@ fs.readFile( FILENAME, 'utf8', ( err, input ) => {
465466
for ( var i = 0; i < reduced; i++ ) {
466467
g2.drop();
467468
}
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 );
469471
} );

2022/17/day.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
solutions:
2+
Javascript:
3+
env:
4+
test:
5+
ADVENT_INPUT: input-test.txt
6+
ADVENT_RANDOM_SHAPE: ABBBBFF
7+
real:
8+
ADVENT_INPUT: input.txt
9+
ADVENT_RANDOM_SHAPE: GFAAHHF
10+
expect:
11+
test:
12+
PART1: 3068
13+
PART2: 1514285714288
14+
real:
15+
PART1: 3130
16+
PART2: 1556521739139

0 commit comments

Comments
 (0)