Skip to content

Instantly share code, notes, and snippets.

View goofballLogic's full-sized avatar
👔
Still counting things

Andrew Stewart Gibson goofballLogic

👔
Still counting things
View GitHub Profile
const replaceRepeats = (input, number) =>
input.replaceAll(
new RegExp(`${number}+`, "g"),
x => x.length);
// test
[
replaceRepeats('1234500362000440', 0) === "1234523623441",
replaceRepeats('000000000000', 0) == "12",
/* solution */
const validate = ([y, z, ...rest]) =>
rest.length
? (rest.shift() === y && validate([z, y, ...rest]))
: true;
/* testing */
/* solution */
function process([y, z, ...rest] = []) {
while (rest.length) {
if (rest.shift() !== y) return false;
[z, y] = [y, z];
}
return true;
}
const rotate = ([ head, ...tail]) => [...tail, head];
const explode = (num, acc = []) =>
num === 0 ? acc
: explode(num - 1, [num, ...acc])
;
const build = (num, input, lines = []) =>
num === 0 ? lines
: build(num - 1, rotate(input), [...lines, input])
;
// below here we can use functional structures again
const suits = ["♠", "♥", "♣", "♦"];
const cards = ["A", "K", "Q", "J", "9", "8", "7", "6", "5", "4", "3", "2"];
function new_deck() {
return suits.flatMap(suit =>
cards.map(card => `${card}${suit}`));
}
const maybeAdd = (prev, candidate) =>
prev.endsAt <= candidate[1]
? [prev, {
chosen: [...prev.chosen, candidate[0]],
endsAt: candidate[2]
}]
: [prev];
const combine = ts =>
ts.reduce(
const taskListEndsAt = ts =>
Math.max(...ts.map(t => t[2]));
const maybeAdd = (ts, candidate) =>
(taskListEndsAt(ts) <= candidate[1])
? [ts, [...ts, candidate]]
: [ts]
;
const combinations = ts =>
@goofballLogic
goofballLogic / cassidoo.js
Last active November 24, 2025 20:24
Cassidoo Nov 17 2025
function repeatedIntegers_0(n) {
    const ret = []; 
    for(let i = 0; i <= n; i++)
        ret.push(...String(i).repeat(i).split("").map(i => Number(i)));
    return ret;
}
function* repeatedIntegers_1(n) {
    let i = 0;
    while(++i <= n)
// Set up:
// - dotnet new console
// - dotnet add package OneOf
// Implement each of the methods below so that they all compile
// There only one valid implementation for each function (apart from f5 & f6)
using OneOf;
A F1<A>(A a) {
class Cat {
speak() { return "meow"; }
}
function process(cat) {
return cat.speak();
}
class Ball {
}