Skip to content

Instantly share code, notes, and snippets.

View mgritter's full-sized avatar

Mark Gritter mgritter

View GitHub Profile
@mgritter
mgritter / decompositions_4.txt
Created May 2, 2025 04:49
Possible decompositions of an NxNxN cube into distinct cuboids (not fully filtered)
# Possible decompositions of 4x4x4 cube into distinct cuboids
41 | [(3, 3, 3), (1, 1, 1), (2, 1, 1), (3, 3, 2), (4, 2, 2)]
42 | [(3, 3, 3), (1, 1, 1), (2, 1, 1), (3, 3, 2), (4, 4, 1)]
52 | [(3, 3, 3), (1, 1, 1), (2, 2, 1), (2, 2, 2), (4, 3, 2)]
63 | [(3, 3, 3), (1, 1, 1), (2, 2, 1), (4, 2, 1), (4, 3, 2)]
64 | [(3, 3, 3), (1, 1, 1), (2, 2, 1), (4, 2, 2), (4, 4, 1)]
65 | [(3, 3, 3), (1, 1, 1), (2, 2, 1), (4, 4, 2)]
72 | [(3, 3, 3), (1, 1, 1), (2, 2, 2), (3, 2, 2), (4, 2, 2)]
73 | [(3, 3, 3), (1, 1, 1), (2, 2, 2), (3, 2, 2), (4, 4, 1)]
76 | [(3, 3, 3), (1, 1, 1), (2, 2, 2), (4, 1, 1), (4, 3, 2)]
@mgritter
mgritter / semigroup_search.py
Created April 15, 2025 07:04
Looking for finite semigroups without identities
from constraint import *
n = 6
problem = Problem()
problem.addVariables( range( 0, n**2 ), range( 0, n ) )
# Associativity:
# v[v[a,b],c] = v[a,v[b,c]]
@mgritter
mgritter / output.txt
Last active December 4, 2024 19:15
Failing to understand Ivy at all; how can I convince it I actually want the usual numbers?
Isolate sum_absolute_pairs:
The following action implementations are present:
sum_ordered_lists.ivy: line 75: implementation of sum_absolute_pairs.get_sum
sum_ordered_lists.ivy: line 63: implementation of sum_absolute_pairs.left_val
sum_ordered_lists.ivy: line 67: implementation of sum_absolute_pairs.right_val
The following action monitors are present:
sum_ordered_lists.ivy: line 37: monitor of sum_absolute_pairs.left_val
sum_ordered_lists.ivy: line 48: monitor of sum_absolute_pairs.right_val
@mgritter
mgritter / compute.py
Created January 28, 2024 08:16
An analysis of dice mechanism by Elias Barry
outcomes = ["AS", "AF", "NS", "NF", "DS", "DF"]
# Game played with N-sided dice
# Player may reroll R times
# Success threshold is max of D dice.
def prob(N, R, D):
P = {}
EV = {}
advantage = range( 2 * N // 3 + 1, N+1 )
disadvantage = range( 1, N // 3 + 1 )
@mgritter
mgritter / draw.py
Last active September 25, 2023 03:43
Connected integer lattice points symmetric about the axes
from enumerate import visit_up_to_n
import matplotlib.pyplot as plt
import math
def draw( n ):
figures = []
def visitor( collection, cost ):
if cost == n:
figures.append( collection )
@mgritter
mgritter / janaka_problem.py
Created July 25, 2023 01:48
A combinatorial counting problem for lower-triangular sequences
# Each sequence consists of steps (0,0) (0,1) (1,0) or (1,1) as long as we
# don't hit the central diagonal. We are interested in seqeuences that end
# at (n-1,n) after 2n-1 steps.
def calculate(paths, max_n, min_k, max_k):
for k in range( min_k + 1, max_k + 1 ):
# TODO: limit y to only those reachable by a sequence of length <= k
for y in range( 1, max_n + 1 ):
# Skip diagonal and upper-triangulage entries, which are all zero
for x in range( 0, y ):
p1 = (x,y,k-1) # k'th element is (0,0)
@mgritter
mgritter / integers.dot
Created April 30, 2023 01:51
graphviz of 4-coloring integers of the form 2^x3^y when (a,2a,3a,4a) are all connected by edges
graph G {
# 0=red, 1=green, 2=blue, 3=gray
graph [nodesep="0.1", ranksep="0.1", pad="0.5"]
node [style=filled, fillcolor=white, shape=circle, width=0.4]
1 [fillcolor=red]
2 [fillcolor=green]
3 [fillcolor=gray]
4 [fillcolor=blue, fontcolor=white]
6 [fillcolor=red]
8 [fillcolor=gray]
@mgritter
mgritter / no_orthogonal.py
Created April 2, 2023 21:09
How many squares can be filled in the NxN grid such that no 5 orthogonal neighbors are all filled?
from ortools.sat.python import cp_model
import sys
# How many squares can be filled in the 10x10 grid such that no five
# orthogonally-connected squares are all filled?
m = cp_model.CpModel()
size = 10
@mgritter
mgritter / output.txt
Last active February 8, 2023 03:00
Which states have a word that uniquely identifies them? All other states have a letter shared with this word.
ALABAMA -- cover DHNOS optionally CEFGIJKPQRTUVWXYZ
ALASKA -- cover EHMNO optionally BCDFGIJPQRTUVWXYZ
ARIZONA -- cover DEGHLMSW optionally BCFJKPQTUVXY
CALIFORNIA -- cover DEGHMSWZ optionally BJKPQTUVXY
COLORADO -- cover BEHIKN optionally FGJMPQSTUVWXYZ
CONNECTICUT -- cover AGHKMS optionally BDFJLPQRVWXYZ
DELAWARE -- cover BHNOS optionally CFGIJKMPQTUVXYZ
FLORIDA -- cover BCEHNSW optionally GJKMPQTUVXYZ
GEORGIA -- cover HLNSW optionally BCDFJKMPQTUVXYZ
HAWAII -- cover LNOST optionally BCDEFGJKMPQRUVXYZ
@mgritter
mgritter / Repro.hs
Created December 21, 2022 18:56
LH file that causes Z3 to take forever
module Repro (part1) where
import qualified Data.Map as Map
import Data.List.Split
import Data.Either
import Data.Maybe
import Control.Monad.ST
import Data.STRef
{-@