Skip to content

Instantly share code, notes, and snippets.

View tkmharris's full-sized avatar
💭
508 Loop Detected

Tom Harris tkmharris

💭
508 Loop Detected
View GitHub Profile
@tkmharris
tkmharris / lock_problem_bfs.rb
Last active January 9, 2023 19:11
Naive solution for owst's combination lock problem using BFS
# frozen_string_literal: true
# Lock Problem
# * We're given a 4-digit combination lock and a known correct unlock code.
# * The allowed moves are to rotate any dial, or any two, three or four
# adjacent dials by one place in either direction.
# * We're looking for an efficient algorithm that returns the least number
# of "moves" required to get to the unlock code. We'd also like the path.
# * e.g.
# - It takes 5 moves to get from [1,2,3,4] to [6,6,6,6].
@tkmharris
tkmharris / associahedron.py
Last active December 26, 2021 19:41
Gist for generating Loday's integer-coordinate realisation of the the Stasheff polytope (associahedron) https://arxiv.org/abs/math/0212126
"""
Script to generate the (integer) vertices of Loday's realisation
of the n-associahedron in (n-1)-dimensional associahedron
as calculated using planar binary trees in:
https://arxiv.org/abs/math/0212126
(Realisation of the Stasheff Polytope)
Loday construction is as follows:
- each planar binary tree has a canonical "left to right" labelling of its internal nodes
- given a planar binary tree so labelled, Loday prescribes a rule for generating a vector (of integers)
@tkmharris
tkmharris / bell-numbers.hs
Last active February 17, 2022 22:31
Generate Bell numbers using the Bell triangle
{-- Haskell function for getting the Bell numbers via the Bell triangle --}
{-- Bell number B_n is the number of partitions of {1,...,n} into nonempty subsets.
The Bell triangle A_{i,j}, 0<=j<=i is defined as follows:
1. A_{0,0} = 1
2. A_{i+1,0} = A_{i,i}
3. A_{i+1,j+1} = A_{i+1,j} + A_{i,j}
The Bell numbers can then be read off as B_n = A_{n,0}
@tkmharris
tkmharris / a345267.py
Last active June 13, 2021 20:46
Code for OEIS sequence A345267
"""
Function to calculate terms of the order of the torsion part of the algebraic K-theory of the integers.
"""
from sympy import bernoulli
def a345267(n):
"""
Calculate the terms of OEIS entry A345267.
(Order of the image of the torsion part of the algebraib K-theory of the integers.).
@tkmharris
tkmharris / a345262.py
Last active June 13, 2021 20:23
Code for OEIS sequence A345262
"""
Function to calculate terms of the order of the image of the J-homomorphism.
"""
from sympy import bernoulli
def a345262(n):
"""
Calculate the terms of OEIS entry A345262.
(Order of the image of the J-homomorphism in the stable homotopy group π_n^S).
@tkmharris
tkmharris / a345225.py
Last active June 11, 2021 23:04
Code for OEIS sequence 345225
"""
Function to calculate terms of OEIS sequence A345225.
"""
def a345225(n):
"""
Calculate OEIS entry A345225(n)
(Orders of 2-primary subgroups of K_n(Z), the algebraic K-theory of the integers.)
n: int, >=0
@tkmharris
tkmharris / a345209.py
Last active June 11, 2021 22:14
Code for OEIS sequence A345209
"""
Function to calculate terms of OEIS sequence A345209.
"""
from sympy import primefactors
def a345209(n):
"""
Calculate OEIS entry A345209(n)
(Number of Petrie polygons on regular triangular map corresponding to the principal congruence subgroup Γ(n) of the mmodular group)
@tkmharris
tkmharris / dreidel.py
Last active May 24, 2021 22:53
Simulate a game of Dreidel
# coding: utf8
import random
class OutOfTimeError(Exception):
"""Raised when game passes maximum number of turns"""
pass
class Player:
@tkmharris
tkmharris / partitionTrees.py
Last active May 15, 2021 14:33
Quick implementation of the two trees for partitions discussed here: https://11011110.github.io/blog/2005/08/07/two-trees-on.html
"""
Quick implementation of the two trees for partitions discussed here:
https://11011110.github.io/blog/2005/08/07/two-trees-on.html
"""
from treelib import Node, Tree
# partition class
class InvalidPartitionError(Exception):
@tkmharris
tkmharris / hydrogen-orbitals.ipynb
Last active December 24, 2019 16:37
Functions for creating images of hydrogen orbitals
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.