Skip to content

Instantly share code, notes, and snippets.

/*
A multi-threaded brute-force search for closed Knight's tours (used OpenMP)
Usage: knights_tours [m] [n]
to search for tour on a m x n board
rows are denoted by letters A.., columns by numbers 0..
Compile with
g++ -O3 -Wall -std=c++11 -fopenmp knight_tours.cc -o knight_tours
@jmoy
jmoy / KnightTours.hs
Created April 27, 2016 16:36
Enumerate all closed Knight's tours (multithreaded, Haskell)
{-#LANGUAGE BangPatterns #-}
{-
Enumerate all closed Knight's Tours in an
arbitrarity sized chessboard. Multi-threaded version.
Usage:
KnightTours m n +RTS -N
Compile with:
@jmoy
jmoy / CL_RBC.py
Last active October 9, 2016 19:06
Value Function Iteration Using OpenCL
# Basic RBC model with full depreciation
# U(c) = log(c)
# F(K) = Z k^\alpha
# where Z is a finite-state Markov chain
#
# Original version:
# Jesus Fernandez-Villaverde
# Haverford, July 3, 2013
# https://github.com/jesusfv/Comparison-Programming-Languages-Economics/blob/master/RBC_Python.py
#
@jmoy
jmoy / thugs_suitcase.py
Last active May 29, 2017 04:43
River crossing puzzle
import itertools as it
NTHUGS = 3
NCASES = 2
BOATCAP = 3
thugs = set()
cases = set()
owner = dict()
nresults = 0
import numpy as np
import numpy.random as nr
def gen(N):
X = nr.choice([0,1],size=N,p=[0.6,0.4])
D = nr.choice([0,1],size=N,p=[0.6,0.4])
epsi = nr.uniform(0,2,N)
Y = X+D*epsi
return X,D,epsi,Y
def estim(D,Y):
@jmoy
jmoy / CompetitiveStoragePython.ipynb
Last active August 28, 2018 19:15
Solving the competitive storage model using collocation
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jmoy
jmoy / thin-film.ipynb
Last active November 18, 2018 19:51
Why soap bubbles are colorful and windowpanes are not
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jmoy
jmoy / Friends2.thy
Last active January 29, 2019 02:51
Solving a puzzle using Isabelle: 2nd attempt
section ‹A Simple Graph Problem: Second Attempt›
text ‹
We shall prove the following: "In a finite group of people, some of whom are friends with some
of the others there must be at least two people who have the same number of friends."
theory Friends
imports Main
Finite_Set
@jmoy
jmoy / wikiwatch.py
Created February 25, 2011 04:56
Get Wikipedia watchlist as an RSS/ATOM feed
"""Get Wikipedia watchlist as an RSS/ATOM feed
(c) Jyotirmoy Bhattacharya, 2007
Usage: wikiwatch <username> <password> [format]
[format] is either 'rss' or 'atom'
"""
import sys
import xml.sax,xml.sax.handler
@jmoy
jmoy / degrees.py
Created June 6, 2019 06:06
Session 1 in Python
with open("code/test2.txt") as fin:
sbj_counts = {}
for l in fin:
l = l.strip()
m = re.fullmatch(r"((?:\w|\.)+)\s+in\s+(\w+)",l)
if m:
degree,subject = m.group(1,2)
print(f"{degree} ({subject})")
if subject in sbj_counts:
sbj_counts[subject].add(degree)