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
| const numberMap = '0234563711'; | |
| const charMap = ' BEATLS'; | |
| const reduceInput = (input) => { | |
| const lines = input.split(/\n/g); | |
| const reduced = lines.map(line => line.split('').map(char => numberMap[char]).join('')); | |
| const set = Array.from(new Set(reduced)); | |
| set.sort((a, b) => a - b); | |
| return set.join('\n'); | |
| }; |
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
| const isPrime = (n) => { | |
| if (n === 2 || n === 3 || n === 5) { | |
| return true; | |
| } | |
| if (n < 2 || (n & 1) === 0 || n % 3 === 0 || n % 5 === 0) { | |
| return false; | |
| } | |
| const sqrt = Math.trunc(Math.sqrt(n)); | |
| const deltas = [0, 4, 6, 10, 12, 16, 22, 24]; |
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
| const parseLine = /^(\w+)\s+(inc|dec)\s+(-?\d+)\s+if\s+(\w+)\s+([=!<>]+)\s+(-?\d+)$/; | |
| class Process { | |
| run(commands, onAfterOperation = () => { | |
| }) { | |
| this.registers = {}; | |
| commands.forEach((commandString) => { | |
| const [register, operation, amount, ...condition] = parseLine.exec(commandString).slice(1, 7); |
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
| const fillGroup = (group, node, nodes) => { | |
| const neighbours = nodes[node]; | |
| group[node] = true; | |
| delete nodes[node]; | |
| neighbours.forEach((neighbour) => { | |
| if (group[neighbour]) { | |
| return; | |
| } | |
| group[neighbour] = true; |
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
| class Matrix { | |
| constructor(matrix) { | |
| this.matrix = matrix; | |
| } | |
| transpose() { | |
| return new Matrix(this.matrix.map((row, y) => row.map((item, x) => this.matrix[x][y]))); | |
| } | |
| flipVertical() { |
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
| const fetch = require('node-fetch'); | |
| const { argv } = require('yargs') | |
| .options({ | |
| from: { | |
| alias: ['servers', 'servers-list', 'servers-url'], | |
| default: 'https://ecoauth.strangeloopgames.com/game/serverlist', | |
| describe: 'Source of a list of servers to ping', | |
| requiresArg: true, | |
| type: 'string', | |
| }, |
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
| const { defInput } = require('./input.js'); | |
| const parseRobot = /(\[.+?])+?/g; | |
| const parseMove = /(\(.+?\))+?/g; | |
| function addPositions([x1, y1], [x2, y2]) { | |
| return [x1 + x2, y1 + y2]; | |
| } | |
| function doRound(robots, moves) { |
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
| // Constructor function for making a node | |
| const Node = function Node(data) { | |
| this.data = data; | |
| this.next = null; | |
| }; | |
| // Constructor function for making a SinglyList | |
| const LinkedList = function LinkedList() { | |
| this.length = 0; | |
| this.head = null; |
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
| function fibonacciMatrix(n) { | |
| const matrix = []; | |
| for (let i = 0; i < n; i++) | |
| matrix.push((new Array(n)).fill(0)); | |
| let x = Math.floor(n / 2); | |
| let y = Math.floor(n / 2); | |
| let fibs = fibonacci(); | |
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
| package RI2_fla | |
| { | |
| import flash.display.Loader; | |
| import flash.display.LoaderInfo; | |
| import flash.display.MovieClip; | |
| import flash.events.Event; | |
| import flash.events.KeyboardEvent; | |
| import flash.events.MouseEvent; | |
| import flash.events.TimerEvent; | |
| import flash.media.Sound; |
NewerOlder