View lock_problem_bfs.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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]. |
View bell-numbers.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-- 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} | |
View associahedron.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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) |
View a345267.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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.). | |
View a345262.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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). | |
View a345225.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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 |
View a345209.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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) |
View akiyama-tanigawa-bernoulli.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-- Implementation of the Akiyama-Tanigawa algorithm | |
for computing Bernoulli numbers. --} | |
{-- Implement the algorithm by: | |
1. Begin with list of reciprocals of positive integers. | |
2. Write function to get next row and iteratie it to get list of lists. | |
3. Take the head of each list in the list to get Bernoulli nums. | |
Everything evaluates lazily, so we can do this nicely with infinite lists. | |
See tkmh.space/flotsam/haskell-akiyama-tanigawa for more.--} |
View dreidel.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf8 | |
import random | |
class OutOfTimeError(Exception): | |
"""Raised when game passes maximum number of turns""" | |
pass | |
class Player: |
View partitionTrees.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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): |
NewerOlder