Skip to content

Instantly share code, notes, and snippets.

View gnarf's full-sized avatar

Mx Corey Frang gnarf

View GitHub Profile
@gnarf
gnarf / 2021.21.golfed.js
Last active December 21, 2021 09:34
#AdventOfCode 2021 Day 21
I=(await(await fetch("https://adventofcode.com/2021/day/21/input")).text(w=W=0)).match(/(\d+)/g)
u=(c,...a)=>{for(let i in U=[,,,1,3,6,7,6,3,1])U[i]&&((r,c,p,P,s=0,S=0,t)=>(((s+=p=((p-1+r)%10)+1)>20)&&(t?W+=c:w+=c),s<21&&u(c,P,p,S,s,!t)))(+i,U[i]*c,...a)}
u(1,I[1],I[3])
w>W?w:W
@gnarf
gnarf / 2021.20.full.js
Created December 20, 2021 05:54
#AdventOfCode - Day 20 Part 2 (pre-golfing, but still ugly...)
// comment out top line if you are running it first time... don't blast that fetch!
// I=(await(await fetch("https://adventofcode.com/2021/day/20/input")).text());
// I=`..#.#..#####.#.#.#.###.##.....###.##.#..###.####..#####..#....#..#..##..###..######.###...####..#..#####..##..#.#####...##.#.#..#.##..#.#......#.###.######.###.####...#.##.##..#..#..#####.....#.#....###..#.##......#.....#..#..#..##..#...##.######.####.####.#.#...#.......#..#.#.#...####.##.#......#..#...##.#.##..#...##.#.##..###.#......#.#.......#.#.#.####.###.##...#.....####.#..#..#.##.#....##..#.####....##...##..#...#......#.#.......#.......##..####..#...#.#.#...##..#.#..###..#####........#..####......#..#
// #..#.
// #....
// ##..#
// ..#..
// ..###`;
[key,...rest]=I.split(/\n+/)
@gnarf
gnarf / 2021.19.js
Last active December 22, 2021 20:35
Advent of Code 2021 - Day 19 Part 2 - Console Golfing
L=JSON.stringify
Z="map"
A=(x,y)=>Math.abs(x-y)**2
X='+!!!+!!!++!!!!-!+!+!!!-!!!-+!!!!+!-!!-!+!!!!+!!++!!!+!!+!+!!!!-!!-+!!!-!-!!!-!!!+-!!!!-!-!-!!!+!!!--!!!!+!+!!+!-!!!!+!!+-!!!-!!-!-!!!!-!!--!!!+!!!-!+!+!!!+!!!++!!!!+!-!+!!!-!!!-+!!!!-!-!-!!!-!!!+-!!!!+!+!-!!!+!!!--!!'
for(T=[],x=0;x<X.length;)z=()=>(+eval(X[x++]+1)),T.push([[z(),z(),z()],[z(),z(),z()],[z(),z(),z()]])
M=(m,t)=>m.map((_,i)=>m[0]*t[i][0]+m[1]*t[i][1]+m[2]*t[i][2])
Q=[];(await(await fetch("https://adventofcode.com/2021/day/19/input")).text()).split('\n').map(i=>i.replace(/ (\d+)/,(_,n)=>(q=n,Q[n]=[])).replace(/(-?\d+),(-?\d+),(-?\d+)/,(_,x,y,z)=>Q[q].push([+x,+y,+z])))
D=D=>D.map(o=>D.map(p=>A(o[0],p[0])+A(o[1],p[1])+A(o[2],p[2])))
for(R=Q[0],R.l=[0,0,0];Q.filter(q=>!q.l).find(q=>{H=[]
for(x in (e=D(R)))for(B in (d=D(q)))d[B].filter(a=>e[x].includes(a)).length>11&&H.push([x,B])
@gnarf
gnarf / sidebar.cs
Created May 10, 2019 22:39
sidebar.cs
static void RenderAbilityStatus( GameObject Player, int xp, int yp, ScreenBuffer _Buffer )
{
if( Player.HasPart( "ActivatedAbilities" ) )
{
ActivatedAbilities pAA = Player.GetPart("ActivatedAbilities") as ActivatedAbilities;
if( pAA.AbilityByGuid != null )
if( pAA.AbilityByGuid.Count > 0 )
{
int x = xp;
@gnarf
gnarf / auto-readme-real-source.js
Last active February 18, 2019 10:39
An example of how to use storybook-addon-info with real source files and readme support
const storyFiles = require.context('../src', true, /__stories__\/.+\.js$/)
const sources = require.context('!!raw-loader!../src', true,
/__stories__\/.+\.js$/)
const readme = require.context('!!raw-loader!../src', true, /README\.md$/)
const READMES = readme.keys().reduce((memo, key) => {
const [,baseName] = key.match(/^\.\/([^\/]+)\//)
memo[baseName] = readme(key)
return memo
}, {})
"detects no available moves": {
"comment": "The board looks like this:",
"boardDesc0": "123",
"boardDesc1": "231",
"boardDesc2": "312",
"state": {
@gnarf
gnarf / Vagrantfile
Last active February 7, 2023 15:39
multi-vagrant-ansible-setup
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'yaml'
config_yml = YAML.load_file(File.open(File.expand_path(File.dirname(__FILE__)) + "/vagrant-config.yml"))
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
@gnarf
gnarf / test.js
Last active September 19, 2015 16:01 — forked from tbranyen/test.js
WebComponent Backbone-events like
class CustomElement extends HTMLElement {
constructor() {
super();
}
attachedCallback() {
this.bindEvents();
}
detachedCallback() {
sh: napa: command not found
npm ERR! Darwin 14.1.0
npm ERR! argv "node" "/usr/local/bin/npm" "install"
npm ERR! node v0.12.0
npm ERR! npm v2.7.3
npm ERR! code ELIFECYCLE
npm ERR! ember-templates-loader@1.3.0 install: `napa`
npm ERR! Exit status 127
npm ERR!
@gnarf
gnarf / err.js
Last active August 29, 2015 14:15
var clone = require("./").Clone.clone;
function errorLog(err) {
console.error(err);
}
// Look up this known commit.
function getCommit(repo) {
// Use a known commit sha from this repository.
return repo.getCommit("59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5");