Skip to content

Instantly share code, notes, and snippets.

.386
.model flat, stdcall
.stack 4096
; My dad was in the computer industry for 45 years; in addition to
; his day job, he supplemented his income while my siblings and I
; were in college with teaching night classes at the local community
; college. One of the classes he taught was assembly language
; programming, and something he'd have his students do near the end
; of the term was write a program that asked the user to enter a
@fizbin
fizbin / qotw21_main.rs
Created September 26, 2022 12:12
Rust language solution to an ancient "Perl Quiz of the Week" (qotw21)
/*
* This program solves the puzzle
* https://perl.plover.com/qotw/e/021
*
* (In case that link goes away, a brief summary of the problem
* is to consider the free non-abelian group with 26 generators
* 'a' through 'z', under the equivalence relation that any two
* words found in the dictionary that are anagrams of each other
* are equivalent. Now determine which letters commute with which
* other letters, and specifically which letters are in the center.)
@fizbin
fizbin / Nim.tla
Created May 31, 2022 11:07
Pluscal algorithm to validate that the well-known Nim strategy is optimal
--------------------------- MODULE Nim ---------------------------
EXTENDS TLC, Sequences, Integers, FiniteSets
CONSTANTS INITIAL_PILES, HUMAN_STARTS
(*
--algorithm Nim
\* An n-pile version of Nim with the rules:
\* * Take as much as you want, but only from one pile
@fizbin
fizbin / git_hook_prelude
Created March 24, 2022 13:46
Launch python 3 for a git hook on any platform
#! /bin/sh
''''test x != "-*- mode: python -*-"
case "`python --version 2>/dev/null`" in
[Pp]"ython 3"*) exec python "$0" "$@" ;;
esac
case "`python3 --version 2>/dev/null`" in
[Pp]"ython 3"*) exec python3 "$0" "$@" ;;
esac
case "`py -3 --version 2>/dev/null`" in
[Pp]"ython 3"*) exec py -3 "$0" "$@" ;;
-- stack --resolver lts-18.18 script --package pqueue --package aeson --package containers
{-# LANGUAGE Haskell2010 #-}
{-# OPTIONS_GHC -Wall -O2 #-}
import Data.Aeson
import Data.List
import Data.Map (Map)
import qualified Data.Map as M
import qualified Data.PQueue.Max as MQ
@fizbin
fizbin / regexequiv.hs
Last active January 19, 2023 22:50
Code to determine whether two regular expressions are equivalent, and if not to find a distinguishing string
{-# OPTIONS_GHC -Wall #-}
module Main (main) where
-- Takes two arguments in a limited regex-like language, and tells if
-- they are equivalent. This equivalence is shown by either saying
-- "there is no string which matches one regex but not the other" or
-- by giving a string which matches one but not the other.
-- (i.e. if the distinguishing string is Just "blah", then the regexes
-- aren't equivalent and onw matches "blah" and the other doesn't. If the
@fizbin
fizbin / aoc23_2attempt5.py
Created January 2, 2019 02:25
Advent of Code 2018 day 23 solution to handle adversarial input
# AOC 2018 day 23 solution to defeat adversarial input (python3)
# Adversarial input sample can be found https://pastebin.com/raw/9eJQN836
# This will try to open the file given as the first command line argument
# or "aoc23.in.txt" if no argument is given.
# This solution transforms the given coordinates in x-y-z space into 4D
# coordinates in a space I call s-t-u-v space, even though I never actually
# deal with 's', 't', 'u', or 'v' directly.
import itertools
@fizbin
fizbin / RunTM.hs
Last active May 22, 2017 21:14
The first Haskell I have evidence of having written
-- This is the first Haskell program of any complexity that I ever wrote, back in October 2005,
-- updated (with newer imports and one changed function name) to run on modern (c. 2017)
-- GHC. It was designed to solve a perl quiz of the week problem to write a Turing
-- Machine emulator. Unfortunately, that mailing list has been defunct for so long that
-- all archives seem to have vanished from the web so I can't point to documentation of
-- the format. I can however point to one program I wrote in the Turing Machine language
-- that solved the prior quiz-of-the-week: given a number N, print out all strings
-- consisting of N '(' characters and N ')' characters such that the parens in the
-- resulting string are balanced.
--
-- SPOILER for project euler #14
-- Really, you should go do it yourself.
@fizbin
fizbin / util.hs
Last active August 29, 2015 14:05
Some simple haskell utilities
import qualified Data.Map.Strict as M
-- The code in any functions here should be too small to really be coverable by copyright, but just in case:
{-
Copyright 2014 Daniel Martin
I, Daniel Martin, license this to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at