Skip to content

Instantly share code, notes, and snippets.

@danielvarga
danielvarga / main.py
Created May 24, 2025 01:28
Endre Csóka's optimization task over symmetric monotone functions. toy variant.
import torch
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D # registers the 3-D projection
from matplotlib import cm
# ───────────────────────── optimiser ──────────────────────────────────────
def solve_monotone_symmetric(
n: int,
lr: float = 5e-3,
@danielvarga
danielvarga / grid_slicing.py
Last active May 13, 2025 15:20
slicing the chessboard
# now at https://github.com/danielvarga/grid-slicing/blob/master/main_complete_set_system.py
# use that instead!
import numpy as np
import cvxpy as cp
from fractions import Fraction
import matplotlib.pyplot as plt
import sys
from pysat.formula import WCNF
from pysat.examples.rc2 import RC2
@danielvarga
danielvarga / main.py
Created January 23, 2025 00:06
Squid Game Dalgona Challenge
import pygame
import math
import random
# Initialize Pygame
pygame.init()
# Screen dimensions
WIDTH, HEIGHT = 800, 800
screen = pygame.display.set_mode((WIDTH, HEIGHT))
@danielvarga
danielvarga / tensor_network.py
Created November 22, 2024 21:25
Tensor network defining subject-relation-object triplets
import torch
import torch.nn as nn
class TensorNetworkBase(nn.Module):
def __init__(self, d, k):
super(TensorNetworkBase, self).__init__()
self.d = d
self.k = k
@danielvarga
danielvarga / main.py
Last active November 3, 2024 03:02
Croft-Moser manim, work in progress
import numpy as np
from numpy import ndarray
from manim import *
from shapely.geometry import Point as ShapelyPoint
from shapely.geometry import Polygon as ShapelyPolygon
from shapely.ops import unary_union # To compute the union of multiple geometries
def moser_spindle():
delta = np.exp(np.pi * 1j / 3) # 60 degrees
@danielvarga
danielvarga / main.py
Last active July 19, 2024 17:04
looking into the 160 element solution for 2-Hamming-triangle free 10d cubes
# all code written by ChatGPT
# https://chatgpt.com/share/44f5f3c4-3213-445c-a824-13acd249e91b
import sys
import numpy as np
import matplotlib.pyplot as plt
import networkx as nx
from collections import Counter
@danielvarga
danielvarga / isoscales.py
Created July 9, 2024 09:20
Subsets of the square grid without isoscales right triangles
import numpy as np
import cvxpy as cp
import matplotlib.pyplot as plt
import matplotlib.patches as patches
def enumerate_isoscales(n):
triangles = []
for x1 in range(n):
for y1 in range(n):
@danielvarga
danielvarga / ode.py
Created May 29, 2024 19:16
ChatGPT numerically solves ODE
# https://chatgpt.com/share/a06552d3-778a-4bfc-b411-3cb5bee4d6d3
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
# Define the system of ODEs
def system(y, t):
f, g = y
dfdt = g
@danielvarga
danielvarga / balancing_game.py
Created May 25, 2024 13:50
some plots for Imre Bárány about Victor Grinberg's balancing game
# https://users.renyi.hu/~geza/GeoSzem/imre24
import numpy as np
import matplotlib.pyplot as plt
def F(a, g):
numerator = np.sin(g)**2 * ((a + 1)**2 * np.tan(g)**2 + a**2)
denominator = (a + 1)**2 - (a + 1) * np.sin(g)
return numerator / denominator
@danielvarga
danielvarga / slicing_the_hypercube.py
Created December 23, 2023 11:21
slicing the hypercube, a set cover problem
import numpy as np
import cvxpy as cp
import itertools
def collect_vertices(n):
if n <= 0:
return np.array([])
# Generate all possible combinations of +1 and -1 using meshgrid