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
| let duet = function(instructions) { | |
| let offset = 'a'.charCodeAt(); | |
| let registers = new Array(26).fill(0); | |
| let played = 0; | |
| let recovered = 0; | |
| let index = 0; | |
| let executeInstruction = function(instruction) { | |
| let [operation, a, b] = instruction.split(' '); |
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
| let spinLock_1 = function(step, target) { | |
| let buffer = [0]; | |
| let position = 0; | |
| for (let i = 1; i <= target; i++) { | |
| position = (position + step) % buffer.length; | |
| buffer.splice(++position, 0, i); | |
| } | |
| return buffer[position + 1]; | |
| }; |
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
| let dance = function(letters, moves) { | |
| let swap = function(arr, i1, i2) { | |
| arr = arr.slice(); | |
| let hold = arr[i2]; | |
| arr[i2] = arr[i1]; | |
| arr[i1] = hold; | |
| return arr; | |
| }; |
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
| let generator = function(value, factor) { | |
| return (value * factor) % 2147483647; | |
| }; | |
| let generatorA1 = function(value) { | |
| return generator(value, 16807); | |
| }; | |
| let generatorA2 = function(value) { | |
| let found = false; |
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
| let knotHashRounds = function(lengths) { | |
| let salt = [17, 31, 73, 47, 23]; | |
| let skip = 0; | |
| let currentPosition = 0; | |
| let numbers = new Array(256).fill(0).map((v, i) => i); | |
| let knotHash = function(input, lengths) { | |
| let numbers = input.slice(); | |
| lengths.forEach((v, i) => { |
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
| let test_1 = `0: 3 | |
| 1: 2 | |
| 2: 4 | |
| 4: 4 | |
| 6: 5 | |
| 8: 8 | |
| 10: 6 | |
| 12: 6 | |
| 14: 6 | |
| 16: 6 |
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
| let populateTree = function(nodesList) { | |
| let tree = nodesList | |
| .split('\n') | |
| .map(p => { | |
| let [node, children] = p.split(' <-> '); | |
| if (children) { | |
| children = children.split(', '); | |
| } | |
| return { | |
| id: parseInt(node.trim()), |
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
| // https://www.redblobgames.com/grids/hexagons/implementation.html#code | |
| function Hex(q, r, s) { | |
| return { q: q, r: r, s: s }; | |
| } | |
| function hex_add(a, b) { | |
| return Hex(a.q + b.q, a.r + b.r, a.s + b.s); | |
| } | |
| function hex_subtract(a, b) { |
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
| let knotHash = function(size, lengths) { | |
| let numbers = new Array(size).fill(0).map((v, i) => i); | |
| let skip = 0; | |
| let currentPosition = 0; | |
| lengths.forEach((v, i) => { | |
| let length = [...numbers, ...numbers] | |
| .slice(currentPosition, currentPosition + v) | |
| .reverse(); | |
| length.forEach((v, i) => { |
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
| let scoreStream = function(stream) { | |
| let increment = 0; | |
| let inGarbage = false; | |
| let lastChar = ''; | |
| let garbageCount = 0; | |
| let score = stream.reduce((acc, v, i) => { | |
| switch (v) { | |
| case '{': | |
| //acc += ++increment; | |
| //acc = !inGarbage && !ignore ? acc + ++increment : acc; |