Skip to content

Instantly share code, notes, and snippets.

View mrdmnd's full-sized avatar

Matthew Redmond mrdmnd

  • Self-Employed
  • San Francisco, CA
  • X @mrdmnd
View GitHub Profile
# heinous zen koan: solve problem with as few indents as possible
import sys
import numpy as np
import itertools
def solve(puzzle):
other_sides = [set(puzzle[(i+1)%4] + puzzle[(i+2)%4] + puzzle[(i+3)%4]) for i in range(4)]
letter_neighbors = {letter: other_sides[index] for (index, side_string) in enumerate(puzzle) for letter in side_string}
constructible = lambda word: len(word) >= 3 and all([(first in letter_neighbors) and (second in letter_neighbors[first]) for (first, second) in zip(word, word[1:])])
constructible_words = set(filter(constructible, map(lambda x: x.rstrip(), open('dictionary.txt', 'r'))))
@mrdmnd
mrdmnd / outlaw_agent.py
Created January 23, 2024 21:28
outlaw rogue DQN toy problem
import numpy as np
from outlaw_environment import OutlawEnvironment
from stable_baselines3 import PPO
from stable_baselines3 import DQN
from stable_baselines3.common.callbacks import BaseCallback
from stable_baselines3.common.env_checker import check_env
from stable_baselines3.common.evaluation import evaluate_policy
env = OutlawEnvironment()
check_env(env, warn=True)
paste into bottom of auto run code in details
Details.SpellsToIgnore[328351] = true; -- spear
Details.SpellsToIgnore[344421] = true; -- anima exhaust from kyrian goliath
Details.SpellsToIgnore[328128] = true; -- hammer
Details.SpellsToIgnore[328406] = true; -- Discharged Anima orb
@mrdmnd
mrdmnd / wordchain.py
Last active May 22, 2020 20:38
Word Chain Homework Exercise
import sys
# Should return a set() of all words in the scrabble dictionary passed in at the given file path.
# You should implement this file loader.
def LoadWords(scrabble_dictionary_path):
pass
# Return a set() of ALL valid words from the input set `all_words` that differ by exactly one letter from `word`
# Hint: you may want to try using regular expressions here.
def FindAllNeighbors(word, all_words):
@mrdmnd
mrdmnd / bloom_filter.py
Created May 8, 2020 19:22
Homework for Friday, May 15th for ATCS
import random
class HashFamily:
def __init__(self):
self.memomask = {}
def hash_fn(self, n):
mask = self.memomask.get(n)
if mask is None:
random.seed(n)
mask = self.memomask[n] = random.getrandbits(64)
@mrdmnd
mrdmnd / ex2.c
Created March 20, 2020 22:23
Solutions to the second problem set
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#define MAX_DICTIONARY_SIZE 300000
#define MAX_WORD_LENGTH 15
// We should guarantee room for a newline and null byte in our buffer.
#define BUFFER_SIZE (MAX_WORD_LENGTH + 2)
int populate_dictionary(char *filepath, char dictionary[][BUFFER_SIZE]) {
@mrdmnd
mrdmnd / ex1.c
Created March 20, 2020 07:43
Solutions to the first set of exercises on Pointers
#include "stdio.h"
#include "string.h"
// 6. (Implementation)
void memory_copy(void* to, const void* from, int n) {
// Need to cast from void to char so that pointer arithmetic works here.
const char* src = (const char *) from;
char* dest = (char *) to;
for (int i = 0; i < n; i++) {
@mrdmnd
mrdmnd / repeat_hello.asm
Last active March 10, 2020 19:39
Small Hello World repeater
; nasm -f elf64 -g -F dwarf repeat_hello.asm && gcc -g -no-pie repeat_hello.o -o repeat_hello && ./repeat_hello 5
; Intended for use on linux x86-864 machines; to run on OS X you'd have to change the syscalls.
extern atoi
global main
section .data
message: db "Hello, world!", 0x0A
length: equ 14
err_msg: db "Wrong!", 0x0A
@mrdmnd
mrdmnd / extract_stop_info.py
Created October 4, 2016 07:33
A short script to output ordered bus-route stop data for two routes in San Clemente, CA
import json
import requests
# Rough bounding box for San Clemente, CA
southwest = [33.351665, -117.779208]
northeast = [33.566387, -117.537489]
bbox_string = "%s,%s,%s,%s" % tuple(southwest[::-1]+northeast[::-1])
stops = []
routes = []
@mrdmnd
mrdmnd / gist:4760746
Created February 12, 2013 07:16
My .vimrc
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
Bundle 'gmarik/vundle'
Bundle 'tpope/vim-fugitive'
Bundle 'Lokaltog/vim-easymotion'
Bundle 'Valloric/YouCompleteMe'