Skip to content

Instantly share code, notes, and snippets.

View DroneBetter's full-sized avatar
💭
NameError: name 'self' is not defined

DroneBetter DroneBetter

💭
NameError: name 'self' is not defined
  • The UK (a delightful place)
  • 10:06 (UTC +01:00)
View GitHub Profile
@DroneBetter
DroneBetter / dimensional_conjugator.py
Created September 7, 2023 14:55
faster A361870 row formula finder iterating over single conjugacy class representatives
from dronery import *
def accel_asc(n): #(thank you https://jeromekelleher.net/generating-integer-partitions.html ;-)
a=lap(lambda _: 0,range(n+1))
k=1
y=n-1
while k:
k-=1
x=a[k]+1
while x<=y>>1:
@DroneBetter
DroneBetter / snake.py
Created July 13, 2023 13:33
very suspicious bitwise snake thing
from getch import getch;from functools import reduce;r=__import__('random').randrange;(lambda f: f(f)((n:=int(input('what is log(n,2)?')),__import__('sys').setrecursionlimit(1<<(n<<2)))[0],*map(lambda i: r(1<<(n<<1)),range(2)),1))(lambda f: lambda n,b,s,l: (lambda a: (lambda e: print('no') if a>>e&1 else f(f)(n,r(1<<(n<<1)) if b==e else b,s<<(n<<1)&~(~0<<(l*n<<1))|e,l+(b==e)))(s+(lambda m: (-1)**(m&1)<<n*(m>>1))('dasw'.index(((lambda m: print(m+'\n'.join(map(lambda y: '|'+''.join(map(lambda x: 's' if a>>(x|y<<n)&1 else 'o' if b==x|y<<n else ' ',range(1<<n)))+'|',range(1<<n)))+m[::-1]))('/'+'-'*(1<<n)+'\\\n'),getch())[1]))&~(~0<<(n<<1))))(reduce(lambda r,i: r|1<<(s>>(i*n<<1)&~(~0<<(n<<1))),range(l),0)))
@DroneBetter
DroneBetter / chromatic.py
Created June 24, 2023 02:19
GUI-based chromatic polynomial finder for arbitrary graphs of symmetries
from math import isqrt,lcm,dist,hypot,cos,sin,atan2,pi
from dronery import reduce,tap,starmap,tarmap,larmap,dbg,tilter,starlter,permutation,sortduct,rle #https://github.com/DroneBetter/dronery
rotate=lambda v,a: (lambda c,s: (c*v[0]-s*v[1],s*v[0]+c*v[1]))(cos(a),sin(a))
import pygame
from pygame.locals import *
clock=pygame.time.Clock()
pygame.init()
size=(2560,1050)
screen=pygame.display.set_mode(size[:2],pygame.RESIZABLE)
@DroneBetter
DroneBetter / life_unraveller.py
Created April 16, 2023 16:50
Life one-liner generator in one line in Python
from functools import reduce
from itertools import accumulate,starmap
from os import urandom
from time import sleep
redumulate=(lambda f,l,i=None: accumulate(l,f,initial=i))
strate=(lambda x,y,s,b=' ',o='o',j='\n': j.join(map(lambda i: (lambda i: ''.join(map(lambda j: o if i>>(j<<2)&1 else b,range(1,(i.bit_length()>>2)+1))))(s>>((x+2)*i<<2)&(1<<(x+2<<2))-1),range(1,y+1))))
mask=(lambda x,y: reduce(lambda b,i: b|b<<(x+2<<i+2),range(y.bit_length()),reduce(lambda b,i: b|b<<(4<<i),range(x.bit_length()),1<<(x+3<<2))&(1<<((x<<1)+3<<2))-1)&(1<<((x+2)*(y+1)<<2))-1)
OT=(lambda r,x,y: (lambda o: (lambda c: eval('lambda s: (lambda m: '+((lambda t: t and (t if len(t)==1 else '('+'|'.join(t)+')'))(tuple(filter(lambda x: x,starmap(lambda i,c: (lambda o,a: o+a if o else '')((lambda s: '('+s+')' if '|' in s else s)('|'.join(map(lambda c: '(lambda m: m&m>>2)((lambda m: m&m>>1)('+'m^'+str(hex(c))+'))',c))),(i!=2)*('&'+'~'*(not i)+'s')),enumerate(c)))))+'&'+str(hex(o))+')((lambda s: (s>>'+str(x+2<<2)+')+s+(s<<'+str(x+2<<2)+'))(
@DroneBetter
DroneBetter / dimensional_INT_enumerator.py
Last active June 15, 2023 21:33
Pólya enumeration theorem applier for closed forms for A054247 in arbitrarily many dimensions
#initially made for confirming there to be 1426144 INT transitions in 3D for https://conwaylife.com/wiki/Isotropic_non-totalistic_cellular_automaton (which was computed faster by hand (assumedly with the Pólya enumeration theorem), but twice with different results), now finds closed forms with the enumeration theorem (for hypercubes and orthoplexes)
from operator import __add__,__mul__#,__call__ #not sure how else to do this for call or how to have multi-input add
from functools import reduce #the land before time
from itertools import starmap,accumulate,groupby,product,combinations,chain,pairwise,zip_longest,islice,count #we manipulate iterables
from math import isqrt,lcm,floor,ceil
ceilsqrt=(lambda x: (lambda s: s+(s**2<x))(isqrt(x)))
A002024=(lambda n: isqrt(n<<3)+1>>1)
A002260=(lambda n,b=False: (lambda s: (lambda o: (o,s) if b else o)(n-s*(s-1)//2))(A002024(n))) #1-indexed antidiagonal coordinates
A003056=(lambda n: isqrt((n<<3)+1)-1>>1)
@DroneBetter
DroneBetter / strassen_lambda_ping_pong.py
Last active December 21, 2022 18:32
Strassen's algorithm in one line
from functools import reduce
from math import isqrt
from random import random
lap=(lambda f,*a: list(map(f,*a))) #just like Python 2 used to make (map objects are iterators)
dims=16 #any power of two
mint=(lambda m: print('\n('+"\n ".join(','.join(str(m[dims*j+i]) for i in range(dims))+',' for j in range(dims))+')')) #matrix print (frankly delicious)
strassen=(lambda a,b: tuple(( lambda f: f(a,b) if len(a)==4 else (lambda m: (lambda m,d: ((m[y*2+x][d*j+i] for y in range(2) for j in range(d) for x in range(2) for i in range(d))))(m,isqrt(len(m[0]))))(f(*map((lambda m: (lambda m,d: tuple((tuple((m[i*d+j] for i in range(d//2*y,d//(2-y)) for j in range(d//2*x,d//(2-x)))) for y in range(2) for x in range(2))))(m,isqrt(len(m)))),(a,b)))))((lambda a,b: (lambda s,n,m: (lambda a,b,c,d,e,f,g: lap(s,((a,d,n(e),g),(c,e),(b,d),(a,n(b),c,f))))(*map(m,*map(lambda x: map(s,x),(((a[0],a[3]),(a[2],a[3]),(a[0],),(a[3],),(a[0],a[1]),(a[2],n(a[0])),(a[1],n(a[3]))),((b[0],b[3]),(b[0],),(b[1],n(b[3])),(b[2],n(b[0])),(b[3],),(b[0],b
@DroneBetter
DroneBetter / gzip_swar_isotropic_non-totalistic.py
Last active April 20, 2024 19:01 — forked from DavidBuchanan314/gzip_swar_life.py
Modification of gzip_swar_life.py supporting arbitrary isotropic non-totalistic cellular automata
import os,sys
from time import time,sleep
from functools import reduce
from dronery import dbg,redumulate,expumulate,shortduce,ORsum,maph,filterh,lap,tap,taph,saph,tarmap,tarmaph,charmap,factorise,primate,revange,loduct,tilter,permutation,decompose,recompose,id,rle,Fraction,__add__,__or__,compose,minh,maxh,reshape,denest,transpose,stratrix,bitverse,sap,rgetitem,sortduct
#print('\n'.join(map(lambda n: ''.join(map(lambda x: 'o' if x else ' ',(lambda x: map(lambda i: x>>3*i+1&1,range(x.bit_length()//3+1)))(n))),redumulate(lambda x,i: (lambda x: reduce(int.__or__,map(lambda j: (lambda x: x>>1&x&x<<1)(~x^i*j),(2,3,4,5,6))))(x>>4|x|x<<4)&i<<1,redumulate(lambda x,i: x|1<<3*i,range(2,64),9),2))));exit()
from itertools import product,starmap,accumulate,groupby,chain,islice,pairwise
try:
from itertools import batched
except:
def batched(l,n):