Skip to content

Instantly share code, notes, and snippets.

@micalevisk
Last active August 19, 2022 19:20
Show Gist options
  • Save micalevisk/a24a9d6f135231a019aa7382931c026f to your computer and use it in GitHub Desktop.
Save micalevisk/a24a9d6f135231a019aa7382931c026f to your computer and use it in GitHub Desktop.
Without running the code... what message is printed? (James Snell puzzle) https://youtu.be/XV-u_Ow47s0?t=234
// (c) https://youtu.be/XV-u_Ow47s0?t=234
// run with: node --no-warnings nodejs-puzzle.js
const { promisify } = require('util');
const sleep = promisify(setTimeout);
async function bar(n, s, t) {
setImmediate(() => process.stdout.write(s));
await sleep(n);
return t;
}
async function foo() {
process.stdout.write('L');
for (const m of await Promise.all(
[bar(20, 'N', 'R'),
bar(10, 'T', 'E')]))
process.stdout.write(m);
}
sleep(50).then(() => process.stdout.write('A'));
new Promise((res) => {
process.stdout.write('H');
res('O');
}).then((m) => process.stdout.write(m))
.finally(() => process.stdout.write('M'));
queueMicrotask(() => process.stdout.write(' '));
process.nextTick(() => process.stdout.write('L'));
setTimeout(() => process.stdout.write('L'), 100);
setImmediate(() => process.stdout.write('O'));
process.stdout.write('E');
foo();
@micalevisk
Copy link
Author

micalevisk commented Aug 30, 2020

ANSWER

reveal
HELLO MONTREAL

L23 - L36 - L13 - L30 - L25 - L28 - L26 - L34 - L7 ('N') - L7 ('T') - L9 ('R') - L9 ('E') - L20 - L32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment