Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions puzzles/puzzle_11.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"code": "6001600054141560155736153460001415166075575B3460001415601F57FD5B6001600055366000803736600036348152603B81602001526064565B9050803403813652604E36602001526064565B01929190f0600080808080945AF1504714607557FD5B600536518181069003043660200151565B00",
"askForValue": true,
"askForData": true,
"askNeedHint": [5, 8, 10],
"hints": [
"TG9vayBmb3IgYSBmdW5jdGlvbiAoYWthIEpVTVBzIHRvIHRoZSBzYW1lIGxvY2F0aW9uKSBpbiB0aGUgaW5zdHJ1Y3Rpb25zIGFib3Zl",
"VGhlcmUgaXMgYSBDUkVBVEUgb3Bjb2RlIGluIHRoZSBpbnN0cnVjdGlvbnMgYWJvdmUuIE1heWJlIHlvdSBuZWVkIHRvIHN1cHBseSBhIGNvbnRyYWN0J3MgYnl0ZWNvZGU/",
"cHJhZ21hIHNvbGlkaXR5IDAuOC4xMDsKCmNvbnRyYWN0IEZsb29yMjBQZXJjZW50IHsKICAgIGNvbnN0cnVjdG9yKCkgcGF5YWJsZSB7fQoKICAgIGZhbGxiYWNrICgpIGV4dGVybmFsIHBheWFibGUgewogICAgICAgIHVpbnQyNTYgYmFsYW5jZSA9IGFkZHJlc3ModGhpcykuYmFsYW5jZTsKICAgICAgICB1aW50MjU2IHZhbCA9ICgoYmFsYW5jZS0oYmFsYW5jZSAlIDUpKS81KTsKICAgICAgICAoYm9vbCBzdWNjZXNzLCApID0gbXNnLnNlbmRlci5jYWxse3ZhbHVlOiB2YWx9KCIiKTsKICAgIH0KfQ=="
]
}
29 changes: 29 additions & 0 deletions src/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const chalk = require("chalk");
const { getOpcode } = require("./opcodes");

module.exports.play = async function play() {
let attempts = 0;
while (true) {
const puzzle = getNextPuzzle();

Expand All @@ -17,6 +18,7 @@ module.exports.play = async function play() {
const solution = await playPuzzle(puzzle);

if (solution) {
attempts = 0;
saveSolution(puzzle.number, solution);

if (await askPlayNext()) {
Expand All @@ -25,6 +27,8 @@ module.exports.play = async function play() {
process.exit(0);
}
} else {
await checkHints(puzzle, ++attempts);

if (!(await askTryAgain())) {
console.log("Thanks for playing!");
process.exit(0);
Expand Down Expand Up @@ -86,6 +90,31 @@ async function askTryAgain() {
return answers.tryAgain;
}

async function askNeedHint() {
const answers = await inquirer.prompt([
{
type: "confirm",
name: "needHint",
message: "Would you like a hint?"
}
]);

console.log();

return answers.needHint;
}

async function checkHints(puzzle, attempts) {
const numHints = puzzle.hints ? puzzle.hints.length : 0 ;
if (numHints > 0 &&
puzzle.askNeedHint.includes(attempts) &&
await askNeedHint()) {
const hintIndex = puzzle.askNeedHint.indexOf(attempts);
console.log(`This is hint ${chalk.yellow(`#${hintIndex+1}`)} out of ${chalk.blueBright(numHints)}. Base64 decode the following:\n`);
console.log(chalk.green(puzzle.hints[hintIndex]), "\n");
}
}

function printCode(code) {
code = code.toUpperCase();
let i = 0;
Expand Down