Skip to content

Commit f36bf55

Browse files
Merge pull request #228 from beakerandjake/feature/224-number-of-solvable-probles-is-49-not-50
Feature/224 number of solvable probles is 49 not 50
2 parents 4d2c1df + bef052f commit f36bf55

File tree

16 files changed

+247
-40
lines changed

16 files changed

+247
-40
lines changed

.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
jest.config.mjs
1+
jest.config.mjs
2+
templates/

.eslintrc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ module.exports = {
2929
// ignore false positive when importing v11.1.0
3030
{ ignore: ['fs-extra/esm'] },
3131
],
32+
'no-plusplus':'off'
3233
},
3334
};

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased]
99
### Added
1010
- Added support for 2023 to the config file ([#226](https://github.com/beakerandjake/advent-of-code-runner/issues/226))
11+
### Fixed
12+
- Fix number of solvable problems to be 49 not 50 (day 25 only has one level) ([#224](https://github.com/beakerandjake/advent-of-code-runner/issues/224))
13+
1114

1215
## [1.3.6] - 2023-08-23
1316
### Fixed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { logger } from '../logger.js';
2+
import { getAllPuzzlesForYear } from '../validation/validatePuzzle.js';
3+
4+
/**
5+
* Asserts that the days puzzle has the level.
6+
* All days have two levels except for the last day which has one.
7+
*/
8+
export const assertPuzzleHasLevel = ({ year, day, level } = {}) => {
9+
const hasLevel = getAllPuzzlesForYear(year).some(
10+
(x) => x.level === level && x.day === day
11+
);
12+
if (!hasLevel) {
13+
logger.error(`Day ${day} does not have level ${level}.`);
14+
}
15+
return hasLevel;
16+
};

src/actions/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { assertAnswerCorrect } from './assertAnswerCorrect.js';
22
import { assertAnswerNotPreviouslySubmitted } from './assertAnswerNotPreviouslySubmitted.js';
33
import { assertConfigValue } from './assertConfigValue.js';
44
import { assertInitialized } from './assertInitialized.js';
5+
import { assertPuzzleHasLevel } from './assertPuzzleHasLevel.js';
56
import { assertPuzzleLevelMet } from './assertPuzzleLevelMet.js';
67
import { assertPuzzleUnlocked } from './assertPuzzleUnlocked.js';
78
import { assertPuzzleUnsolved } from './assertPuzzleUnsolved.js';
@@ -37,6 +38,7 @@ export {
3738
assertInitialized,
3839
assertPuzzleUnlocked,
3940
assertPuzzleUnsolved,
41+
assertPuzzleHasLevel,
4042
assertPuzzleLevelMet,
4143
assertUserConfirmation,
4244
executeUserSolution,

src/cli/initialize.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const initializeQuestions = [
4040
name: 'year',
4141
message: festiveStyle('What year of advent of code are you doing?'),
4242
prefix: festiveEmoji(),
43-
choices: getConfigValue('aoc.validation.years')?.reverse(),
43+
choices: [...getConfigValue('aoc.validation.years')].reverse(),
4444
loop: false,
4545
},
4646
authTokenQuestion,

src/cli/solve.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { dayArgument, levelArgument } from './arguments.js';
77
* The common actions between the 'solve' and 'autosolve' commands
88
*/
99
const solveActions = [
10+
actions.assertPuzzleHasLevel,
1011
actions.outputPuzzleLink,
1112
actions.assertPuzzleUnlocked,
1213
actions.assertPuzzleLevelMet,

src/cli/submit.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { dayArgument, levelArgument } from './arguments.js';
77
* The common actions between the 'submit' and 'autosubmit' commands
88
*/
99
const submitActions = [
10+
actions.assertPuzzleHasLevel,
1011
actions.outputPuzzleLink,
1112
actions.assertPuzzleUnlocked,
1213
actions.assertPuzzleLevelMet,

src/config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,13 @@ const CONFIG = {
153153
source: join(__dirname, '..', 'templates', 'template-dataFile.json'),
154154
dest: join(cwd, 'aocr-data.json'),
155155
},
156-
solution: join(__dirname, '..', 'templates', 'template-solution.js'),
156+
solutionDefault: join(__dirname, '..', 'templates', 'template-solution.js'),
157+
solutionLastDay: join(
158+
__dirname,
159+
'..',
160+
'templates',
161+
'template-solution-last-day.js'
162+
),
157163
},
158164
},
159165
initialize: {

src/initialize/createSolutionFiles.js

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ const tokens = [
1313
{ match: '{{year}}', key: 'year' },
1414
];
1515

16+
/**
17+
* Create a solution template for each day.
18+
* @param {String} template
19+
* @param {Number[]} days
20+
* @returns {Array<Promise>}
21+
*/
22+
const doCreate = (template, year, days) =>
23+
days.map((day) =>
24+
writeFile(
25+
getSolutionFileName(day),
26+
replaceTokens(tokens, { year, day }, template),
27+
'utf-8'
28+
)
29+
);
30+
1631
/**
1732
* Creates the solution files in the cwd.
1833
*/
@@ -23,24 +38,19 @@ export const createSolutionFiles = async ({ year } = {}) => {
2338
throw new Error('null or undefined year');
2439
}
2540

26-
// create directory if doesn't exist.
27-
const solutionsDir = getConfigValue('paths.solutionsDir');
28-
await ensureDir(solutionsDir);
41+
// create solution dir if does not already exist.
42+
await ensureDir(getConfigValue('paths.solutionsDir'));
2943

30-
// load the contents of the template solution
31-
const templateSolutionFile = await readFile(
32-
getConfigValue('paths.templates.solution'),
33-
{ encoding: 'utf-8' }
34-
);
35-
36-
// create each template solution file.
37-
const createFilePromises = getConfigValue('aoc.validation.days').map((day) =>
38-
writeFile(
39-
getSolutionFileName(day),
40-
replaceTokens(tokens, { year, day }, templateSolutionFile),
41-
'utf-8'
42-
)
43-
);
44+
// load the template files (last day is special and needs a different template than default)
45+
const [basicTemplate, lastDayTemplate] = await Promise.all([
46+
readFile(getConfigValue('paths.templates.solutionDefault'), 'utf8'),
47+
readFile(getConfigValue('paths.templates.solutionLastDay'), 'utf8'),
48+
]);
4449

45-
await Promise.all(createFilePromises);
50+
return Promise.all([
51+
// all days but the last day share a default solution template.
52+
...doCreate(basicTemplate, year, getConfigValue('aoc.validation.days').slice(0, -1)),
53+
// last day is special and needs a different solution template.
54+
...doCreate(lastDayTemplate, year, getConfigValue('aoc.validation.days').slice(-1)),
55+
]);
4656
};

0 commit comments

Comments
 (0)