Skip to content

Instantly share code, notes, and snippets.

@benrosenberg
benrosenberg / distributions.py
Created March 10, 2024 03:40
n-adic means for various distributions
# histograms of various distributions
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.rcParams['mathtext.fontset'] = 'cm'
normal_50 = np.random.normal(50, scale=13, size=100000)
normal_30 = np.random.normal(30, scale=10, size=100000)
@benrosenberg
benrosenberg / flip_game.py
Created March 10, 2024 03:26
Flip game in pygame
'''
Implementation of the "Flip" game, in which clicking on a tile flips itself and the four tiles touching it.
'''
import random
import pygame
pygame.init()
pygame.display.set_caption('flip game')
@benrosenberg
benrosenberg / integer_sequences_and_knight_walks.py
Created May 22, 2023 17:49
Some experiments with mapping integer sequences to left/right directions for a knight walk
from matplotlib import pyplot as plt
import math_pi, sympy
import math
import numpy as np
from matplotlib.collections import LineCollection
N = 10000
def first_n_fib(n):
a, b = 0, 1
@benrosenberg
benrosenberg / nbconv.py
Last active January 17, 2023 05:02
Simple IPYNB -> HTML converter script. Works with Markdown cells (and math, via KaTeX!), code cells, cell outputs (text and PNG images).
import json
import markdown
from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.formatters import HtmlFormatter
import re
import sys
help_string = '''
Format: python nbconv.py <in_filename> <out_filename> [-s]
@benrosenberg
benrosenberg / mcf.ipynb
Created January 9, 2023 00:44
GurobiPy implementation of Min Cost Flow
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@benrosenberg
benrosenberg / boggle.py
Created December 29, 2021 19:22
(Non-working) Attempt at boggle game in Python
# boggle game (another use case for words_alpha.txt)
'''IDEA'''
'''
CLI implementation of Boggle
Idea: give user a 4x4 (or maybe 5x5) boggle board as follows (letters inaccurate)
A B C D
E F G H
@benrosenberg
benrosenberg / nyt_spellingbee_solver.py
Created December 29, 2021 19:19
NYT Spelling Bee Solver
import sys, re
# read in word list
with open('words_alpha.txt') as f:
words = set(f.read().split())
def solve(puzzle, words):
# puzzle is a list of the following form:
# ['x', 'x0', 'x1', 'x2', 'x3', 'x4', 'x5']
# where x and x0..x5 are all single character strings, and
@benrosenberg
benrosenberg / good-grading-rubric.ipynb
Created October 22, 2021 06:44
good grading rubric.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@benrosenberg
benrosenberg / config
Created July 19, 2021 21:40
my i3 config file
# This file has been auto-generated by i3-config-wizard(1).
# It will not be overwritten, so edit it as you like.
#
# Should you change your keyboard layout some time, delete
# this file and re-run i3-config-wizard(1).
#
# i3 config file (v4)
#
# Please see https://i3wm.org/docs/userguide.html for a complete reference!