Skip to content

Instantly share code, notes, and snippets.

View GeneralYouri's full-sized avatar

Youri Bok GeneralYouri

View GitHub Profile
@GeneralYouri
GeneralYouri / sudoku-beatles.js
Last active January 30, 2023 22:16
A NodeJS script to find valid 9x9 latin-square grids based on a list of valid digit sequences for rows/cols
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');
};
@GeneralYouri
GeneralYouri / getFactorsFromPrimeFactors.js
Last active December 19, 2018 20:27
AoC 2018 day 19 - Runtime-optimized algorithm calculating the factor sum of a number
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];
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);
@GeneralYouri
GeneralYouri / group.js
Created August 12, 2018 16:08
RangeError test
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;
@GeneralYouri
GeneralYouri / matrixDynamic.js
Last active July 29, 2018 21:05
2D Matrix manipulation, comparing static and dynamic approaches
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() {
@GeneralYouri
GeneralYouri / index.js
Created July 13, 2018 16:13
yargs example usage
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',
},
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) {
@GeneralYouri
GeneralYouri / LinkedList.js
Created May 2, 2018 14:47
JS Linked List (code sample for code style)
// 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;
@GeneralYouri
GeneralYouri / fibonacciMatrix
Last active August 29, 2017 20:24
JS solution for the CodeFight challenge maxProdInTable
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();
@GeneralYouri
GeneralYouri / v1.6.3.as
Last active April 24, 2026 12:49
Revolution Idle 2
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;