Last active
August 19, 2022 19:20
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// (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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ANSWER
reveal
L23 - L36 - L13 - L30 - L25 - L28 - L26 - L34 - L7 (
'N'
) - L7 ('T'
) - L9 ('R'
) - L9 ('E'
) - L20 - L32