Skip to content

Instantly share code, notes, and snippets.

M=document.querySelector('pre').innerText.trim().split('\n').map(l=>l.split('')),h=M.length
sqr=(x,y,r)=>[...Array(r?h-y:1)].reduce((s,_,Y)=>M[y+Y].slice(x+1,h-y-Y+x).reduce((s,c,d)=>s+(c+M[y+1+d][x-Y]+M[y+Y+1+d][x+1+d-Y]=='###'),s),0)
M.reduce((s,l,y)=>l.reduce((s,c,x)=>c=='#'?s.map((a,i)=>a+sqr(x,y,i)):s,s),[0,0])
P=document.querySelector('pre').innerText.trim().split('').map(c=>`rvbgyo`.indexOf(c));
[P,[...P].sort()].map(p=>p.reduce((i,c,_,__,j=6-c,I=i%6,n=(j>I?0:6)+j-I)=>i+n,0))
// shorter:
[P,[...P].sort()].map(p=>p.reduce((i,c)=>i+(11-c-i%6)%6+1,0))
[0,0].map((_,i)=>Object.entries(document.querySelector('pre').innerText.trim().split('\n').reduce((o,e)=>({...o,[e]:(o[e]??0)+1}),{})).sort(([_,a],[__,b])=>i==0?b-a:a-b).slice(0,3).map(([k])=>parseInt(k)).reduce((a,b)=>a*b,1))
@dkaraush
dkaraush / ChunkOcclusion.cs
Created December 25, 2025 16:15
Occlusion Culling Angle Check Helper
public struct AngleRange {
const float HalfPi = MathF.PI * 0.5f;
public float Min, Max;
public AngleRange(int run, int rise) {
Min = MathF.Atan2(rise - 1, run + 1).Clamp(0, HalfPi);
Max = MathF.Atan2(rise + 1, run - 1).Clamp(0, HalfPi);
}
const input = Object.fromEntries(document.querySelector('pre').innerText.trim().split('\n').map(L => [L.substring(0, 3), L.substring(5).split(' ')]))
function traverse(
path = ['you'],
count = {},
last = path[path.length - 1],
dac = path.indexOf('dac') >= 0,
fft = path.indexOf('fft') >= 0,
key = last + dac + fft
) {
input = document.querySelector('pre').innerText.trim().split('\n').map(line => line.substring(1,line.length-1).split(/\] \(|\) \{/g)).map(([a,b,c]) => [a.split('').map(c=>c=='#'), b.split(') (').map(b => b.split(',').map(x=>parseInt(x))), c.split(',').map(x=>parseInt(x))])
const sumOfValues = o => Object.values(o).reduce((a,b)=>a+b,0)
const matrix = (buttons, joltage) =>
joltage.map((r, i) => [...buttons.map(btn => btn.indexOf(i) >= 0 ? 1 : 0), r])
// Gaussian elimination
// https://en.wikipedia.org/wiki/Gaussian_elimination
function gaussian(
M,
EPS = 1e-8,
Object.getOwnPropertyNames(Math).map(k => window[k] = Math[k])
const input = document.querySelector('pre').innerText.trim().split(`\n`).map(l => l.split(',').map(x => parseInt(x)))
const maxArea = (filter = () => true) =>
input.reduce((acc, [x1,y1], i) => max(acc, input.slice(i+1).reduce((acc, [x2,y2]) =>
max(acc, filter(x1,y1,x2,y2) ? (abs(x2-x1)+1) * (abs(y1-y2)+1) : 0), 0)
), 0)
const xs = input.reduce((arr, [x,y]) => arr.indexOf(x) >= 0 ? arr : [...arr, x], []).sort((a,b)=>a-b)
const ys = input.reduce((arr, [x,y]) => arr.indexOf(y) >= 0 ? arr : [...arr, y], []).sort((a,b)=>a-b)
import java.io.File
import java.util.SortedSet
fun main() {
val FIRST_SAMPLES_COUNT = 1000
val input = File("input.txt").readLines()
.map { it.split(',').map(String::toLong) }
val circuits = input.withIndex().mapTo(ArrayList())
{ (idx, _) -> hashSetOf(idx) }
package main
import (
"bytes"
"fmt"
"os"
)
type Beam struct {
X int
#include <iostream>
#include <fstream>
#include <sstream>
int main() {
std::ifstream file("input.txt");
std::string A, B, C, D, O;
std::getline(file, A);
std::getline(file, B);
std::getline(file, C);