Skip to content

Instantly share code, notes, and snippets.

package main
import (
"bytes"
"fmt"
"os"
)
type Beam struct {
X int
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) }
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)
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,
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
) {
@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);
}