Skip to content

Instantly share code, notes, and snippets.

@anthonykozar
anthonykozar / throwback.py
Created September 5, 2022 19:58
Implementation of the THROWBACK procedure for rearranging sequences of numbers
# THROWBACK procedure from
# "Coding Fun: Rearranging All The Numbers" in
# Popular Computing #55, Oct. 1977, Vol. 5, No. 10
# See <https://oeis.org/A155167/a155167.pdf> for a copy.
import math
# Display the array at each step and stop when the "leader" (the initial
# value in the array) is stopAtFirst or when maxsteps is reached.
def showprocess(stopAtFirst, maxsteps = 1000):
@anthonykozar
anthonykozar / Adar.py
Created September 5, 2022 19:44
Example Adar programs that generate OEIS sequences
# Adar implementation from
# https://esolangs.org/wiki/Adar
adar = lambda l: (lambda n: list(map(lambda x: (x[0] + n, x[1]), l)))(sum(map(lambda x: (x[0] >= 0) * x[1], l)))
# Basic code that I wrote to run & trace Adar programs
# prints only the value of the first register at each step
def run(prog, steps=10, outputInitial = False, adar=adar):
output = []
@anthonykozar
anthonykozar / GaotppTranslator.py
Created November 30, 2021 16:57
A translator for the esoteric programming language Gaot++
# Gaot++ Translator
#
# Converts Gaot++ code to and from Forth-like code
# that is easier to understand.
#
# See description of Gaot++ at
# https://esolangs.org/wiki/Gaot%2B%2B
#
# Anthony Kozar
# Nov. 24-27, 2021
@anthonykozar
anthonykozar / Std-MIDI-file.tcl
Created October 6, 2020 13:39
Binary template for Hex Fiend to interpret Standard MIDI files (.mid).
# Standard MIDI file template (extension .mid)
# by Anthony Kozar
#
# Version: 2020-10-06
#
# Supports all of the basic MIDI events (Note On, Control Change, etc.)
# but does not yet recognize some of the 0xFx events or show details for
# any meta-events. Also does not handle running status at all.
#
# The list of controller names only includes the ones that I thought would
@anthonykozar
anthonykozar / SpragueGrundy.py
Created October 12, 2018 12:21
Uses Sprague-Grundy theory to calculate the nim values of Grundy's Game and other impartial combinatorial games.
# SpragueGrundy.py
#
# A collection of functions using Sprague-Grundy theory to
# calculate the nim values of Grundy's Game and other
# impartial combinatorial games.
#
# Anthony Kozar
# October 4-11, 2018
import operator