38 lines
1,013 B
JavaScript
38 lines
1,013 B
JavaScript
const { Glib } = require('../../lib');
|
|
|
|
module.exports = {
|
|
'1': (input) =>
|
|
Glib.fromSequence(1, Infinity)
|
|
.flatMap((i) => {
|
|
const md5 = `${input}${i}`.md5;
|
|
return md5.startsWith('00000') ? [md5[5]] : [];
|
|
})
|
|
.take(8).string,
|
|
'2': (input) =>
|
|
Glib.fromSequence(1, Infinity)
|
|
.flatMap((i) => {
|
|
const md5 = `${input}${i}`.md5;
|
|
if (!md5.startsWith('00000')) {
|
|
return [];
|
|
}
|
|
const position = parseInt(md5[5], 10);
|
|
if (md5[5] != position.toString()) {
|
|
return [];
|
|
}
|
|
return [{ position, character: md5[6] }];
|
|
})
|
|
.partialReduce(
|
|
(accumulator, { position, character }, index, done, undone) => {
|
|
if (accumulator[position] !== ' ') {
|
|
return accumulator;
|
|
}
|
|
|
|
return accumulator.splice(position, 1, character);
|
|
},
|
|
(accumulator) => {
|
|
return accumulator.indexOf(' ') !== -1;
|
|
},
|
|
' ',
|
|
),
|
|
};
|