Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 01. The Imitation Game!!!
- function solve(input) {
- let message = input.shift().split('');
- for (let key of input) {
- let line = key.split('|');
- if (line[0] === "Move") {
- let numbersOfLetters = Number(line[1]);
- let copySymbol = message.slice(0, numbersOfLetters);
- message.splice(0, numbersOfLetters);
- for (let x in copySymbol) {
- let symbolPush = copySymbol[x]
- message.push(symbolPush);
- }
- } else if (line[0] === 'ChangeAll') {
- message = message.map(x => x.replace(line[1], line[2]));
- } else if (line[0] === 'Insert') {
- let index = Number(line[1]);
- let value = line[2];
- message.splice(index, 0, value);
- } else if (line[0] === 'Decode') {
- console.log(`The decrypted message is: ${message.join('')}`);
- }
- }
- }
- solve(['zzHe', 'ChangeAll|z|l', 'Insert|2|o', 'Move|3', 'Decode']);
- solve(['owyouh', 'Move|2', 'Move|3', 'Insert|3|are', 'Insert|9|?', 'Decode']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement