Skip to content

Instantly share code, notes, and snippets.

#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);
input = document.querySelector('pre').innerText;
[ranges, ids] = input.split('\n\n').map(x => x.split('\n'));
ranges = ranges.map(r => r.split('-').map(x => parseInt(x)));
console.log(ids.filter(id => ranges.some(r => id >= r[0] && id <= r[1])).length)
function mergeRanges() {
const N = ranges.length
for (let i = 0; i < N; ++i)
for (let j = 0; j < N; ++j) {
string[] lines = File.ReadAllLines("input.txt");
int W = lines[0].Length, H = lines.Length;
char[][] map = lines
.Select(l => $".{l}.")
.Prepend(new string('.', 2 + W))
.Append(new string('.', 2 + W))
.Select(l => l.ToCharArray())
.ToArray();
(int dx, int dy)[] NeighbourOffsets = {
function joltage(line, n)
local index = 1
local result = 0
for a = 1, n do
local maxDigit = line:byte(index)
for i = index, #line - (n - a) do
if line:byte(i) > maxDigit then
maxDigit = line:byte(i)
index = i
end
(module
(import "sys" "open" (func $open (param i32 i32 i32 i32) (result i32)))
(import "sys" "close" (func $close (param i32)))
(import "sys" "read" (func $read (param i32 i32 i32) (result i32)))
(import "sys" "write" (func $write (param i32 i32 i32) (result i32)))
(memory (export "memory") 1)
(data (i32.const 0) "input.txt")
(module
(import "sys" "open" (func $open (param i32 i32 i32 i32) (result i32)))
(import "sys" "close" (func $close (param i32)))
(import "sys" "read" (func $read (param i32 i32 i32) (result i32)))
(import "sys" "write" (func $write (param i32 i32 i32) (result i32)))
(memory (export "memory") 1)
(data (i32.const 0) "input.txt")
default rel
section .data
filename: db "input.txt", 0
section .bss
char: resq 1
number_string: resq 32
number: resq 1
isL: resq 1
@dkaraush
dkaraush / oklch2rgb.js
Last active November 5, 2025 15:58
conversion OKLCH into RGB and RGB into OKLCH in js, simplified
const multiplyMatrices = (A, B) => {
return [
A[0]*B[0] + A[1]*B[1] + A[2]*B[2],
A[3]*B[0] + A[4]*B[1] + A[5]*B[2],
A[6]*B[0] + A[7]*B[1] + A[8]*B[2]
];
}
const oklch2oklab = ([l, c, h]) => [
l,
@dkaraush
dkaraush / code.bf
Created April 11, 2023 01:54
advent of code 2022 first task in brainfuck
>>>,----------[--------------------------------------<[->>++++++++++<<]>[->+<]>[
-<<+>>]<,----------]<[[-<+>]>,----------[--------------------------------------<
[->>++++++++++<<]>[->+<]>[-<<+>>]<,----------]<]<[<[->>+>+<<<]>>>[-<<<+>>>]<<[->
>+>+<<<]>>>[-<<<+>>>][-]>[-]>[-]+>[-]<<<<[>+>+<<-]>[<+>-]<<[>>+<<-]+>>>[>-]>[<<<
<->>[-]>>->]<+<<[>-[>-]>[<<<<->>[-]+>>->]<+<<-][-]>[-]>[-]<<<[-][-]>[-]<<[>+>+<<
-]>[<+>-]+>[<<<<[-]>[-<+>]>>->[-]]<[-]<<[-][-]>[-]>,----------[-----------------
---------------------<[->>++++++++++<<]>[->+<]>[-<<+>>]<,----------]<[[-<+>]>,--
--------[--------------------------------------<[->>++++++++++<<]>[->+<]>[-<<+>>
]<,----------]<]<][-]>[-]+>[-]+<[>[-<-<<[->+>+<<]>[-<+>]>>]++++++++++>[-]+>[-]>[
-]>[-]<<<<<[->-[>+>>]>[[-<+>]+>+>>]<<<<<]>>-[-<<+>>]<[-]++++++++[-<++++++>]>>[-<
@dkaraush
dkaraush / fragment shader
Created July 22, 2020 16:35
a beautiful gradient shader at the main page of stripe website (https://stripe.com)
precision highp float;
uniform mat4 projectionMatrix;
uniform mat4 modelViewMatrix;
uniform vec2 resolution;
uniform float aspectRatio;
uniform float u_time;
uniform float u_shadow_power;
uniform float u_darken_top;
uniform vec4 u_active_colors;