Skip to content

Instantly share code, notes, and snippets.

View dpiponi's full-sized avatar
🧱
In material form

Dan Piponi dpiponi

🧱
In material form
View GitHub Profile
@dpiponi
dpiponi / caustic.nb
Created March 8, 2025 22:24
Path integral caustics
length = Compile[{{x, _Real}, {y, _Real}, {\[Theta], _Real}},
Sin[\[Theta]] +
Sqrt[(x + Sin[\[Theta]])^2 + (y - Cos[\[Theta]])^2]];
wavelength = 1/128;
phaseSum = Compile[
{{a, _Integer}, {b, _Integer}, {n, _Integer}, {\[Lambda], _Real}, \
{x, _Real}, {y, _Real}},
Module[{i = 0, t = 0. + 0. I},
For[i = a, i <= b, ++i,
t += \[Pi]/n Exp[I length[x, y, \[Pi]/n i]/\[Lambda]]];
@dpiponi
dpiponi / central.py
Created February 22, 2025 19:28
Ising-ish model with central gravitational force
import taichi as ti
import taichi.math as tm
import time
import random
ti.init(arch=ti.gpu)
w = 1440//2
h = 1440//2
# pixels = ti.field(dtype=float, shape=(h, w))
import taichi as ti
import taichi.math as tm
import time
import random
ti.init(arch=ti.gpu)
w = 1440//2
h = 1440//2
# pixels = ti.field(dtype=float, shape=(h, w))
@dpiponi
dpiponi / defect.py
Created February 20, 2025 19:44
Ising type model using Kawasaki type dynamics
import taichi as ti
import taichi.math as tm
import time
import random
ti.init(arch=ti.gpu)
w = 256
h = 256
# pixels = ti.field(dtype=float, shape=(h, w))
@dpiponi
dpiponi / quine.c
Created February 11, 2025 17:02
A quine that uses no operations other than +, -, *, % and /.
/*
* This is a literate quine. That means that
* 1. the comments will tell you a little about how it works and
* 2. if you compile and run it its output will be identical to its source
* code even though it doesn't look at its original source. It literally
* contains within itself a complete recipe for how to display itself.
*
* Quines are ten a penny. This one is unusual because
* 1. its main loop consists solely of a loop to print characters
* generated by a function called programChar() and
@dpiponi
dpiponi / main.cpp
Created October 22, 2024 19:51
WFT? Where's my code
//aasasddasdas
@dpiponi
dpiponi / main.cpp
Created April 11, 2024 16:46
De/serialization in C++ (not suitable when typeid not consistent)
#include <iostream>
#include <sstream>
#include <map>
template<typename T>
void ReadAndConsume(std::istringstream& s)
{
T t;
s >> t;
std::cout << t << ' ';
@dpiponi
dpiponi / tribonacci.cpp
Created April 3, 2024 17:31
Print the tribonacci numbers
#include <iostream>
// See https://arxiv.org/abs/2404.01483
long p(long x, long y, long z)
{
return x*x*x + 2*x*x*y + x*x*z + 2*x*y*y - 2*x*y*z - x*z*z + 2*y*y*y - 2*y*z*z + z*z*z;
}
const int N = 505;
data Weird = Weird { a0 :: Integer
, a1 :: Integer
, a2 :: Integer
, a3 :: Integer
, a4 :: Integer
, a5 :: Integer
, a6 :: Integer
} deriving Show
instance Num Weird where
@dpiponi
dpiponi / weird.cpp
Created March 7, 2024 21:28
solving that 2,3,7 puzzle efficiently
#include <iostream>
class Weird {
public:
float a0, a1, a2, a3, a4, a5, a6;
Weird(float b0, float b1, float b2, float b3, float b4, float b5, float b6)
: a0(b0), a1(b1), a2(b2), a3(b3), a4(b4), a5(b5), a6(b6) {}
Weird operator*(const Weird &other) const {
return Weird(