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 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 {
}
terraform {
required_version = ">= 0.12"
}
provider "aws" {
region = "eu-west-1"
}
resource "aws_instance" "web" {
const ordinalSuffixes = {
"en": {
"one": "st",
"two": "nd",
"few": "rd",
"other": "th"
}
};
export class OrdinalFormat {
import { OrdinalFormat } from "./ordinal-formatting.js";
const fullFormat = new Intl.DateTimeFormat("en", { dateStyle: "full" });
const now = new Date();
const parts = fullFormat.formatToParts(now);
const weekDayName = parts.find(p => p.type === "weekday").value;
const dayName = parts.find(p => p.type === "day").value;