Skip to content

Instantly share code, notes, and snippets.

@1328
1328 / rps
Last active August 29, 2015 14:04
another take on rps
import random
class Throw(object):
choices = {1:'Rock',2:'Paper', 3:'Scissors'}
victory = {
(1,3):'Rock smashes Scissors',
(2,1):'Paper covers Rock',
(3,2):'Scissors cut Paper',
}
from pprint import pprint
import dicttoxml
from xml.dom.minidom import parseString
FILES = ['FILE2.COMPAS', 'FILE1.COMPAS']
import os
import sys
import math
import random
import itertools
import bisect
# Fix Python 2.x.
@1328
1328 / mapper
Last active August 29, 2015 14:07
mapper
from random import randrange, sample
from collections import Counter
class Map(object):
water_chance = 10 #Chance of ground being water
water_near_water = 30 #If a water tile is to our left or top
house_chance = 5
boat_chance = 25 #If we're on a water tile, with a house nearby, chance of it being a boat
def __init__(self, height, width):
from string import ascii_lowercase
from pprint import pprint
def init_matrix():
'''
check out collections.defaultdict for a much easier way to do this
'''
matrix = {}
for a in ascii_lowercase:
matrix[a] = {}
from string import ascii_lowercase
from collections import defaultdict
from pprint import pprint
def add_word(matrix, word):
'''
this modifies a letter count matrix to add in the pairs
the matrix stores things as follows:
matrix[first][second] = count of times first+second appear in word
from string import ascii_lowercase
from collections import defaultdict
from itertools import zip_longest
from pprint import pprint
from random import random
import bisect
class Matrix(object):
def __init__(self, words = None):
@1328
1328 / word_box.py
Last active August 29, 2015 14:07
word box
from copy import deepcopy
from collections import defaultdict
import random
import time
def load_dictionary():
with open('dictionary.txt', mode='r') as fh:
result = [w.strip() for w in fh]
return result
@1328
1328 / aliens.py
Created October 20, 2014 23:39
aliens - comments
import sys
import random
#Helper dictionary to reverse directions
# line is too long, break it up
reverse_directions = { "north" : "south",
"east":"west",
"west":"east",
"south":"north" }
@1328
1328 / aliens.py
Last active August 29, 2015 14:07
aliens - try
import random
from collections import defaultdict
from pprint import pprint
class City(object):
def __init__(self, data=None):
self.name = None
self.neighbors = {}
if data is not None: