Skip to content

Instantly share code, notes, and snippets.

View drvinceknight's full-sized avatar
😀
👍

Vince Knight drvinceknight

😀
👍
View GitHub Profile
\begin{tikzpicture}
\tikzstyle{state}=[minimum width=2cm, font=\boldmath];
% First row
\node (00) at (0,0) [state] {$(0,0)$};
\node (01) at ($(00)+(3,0)$) [state] {$(0,1)$};
\node (02) at ($(01)+(3,0)$) [state] {$(0,2)$};
\node (03) at ($(02)+(3,0)$) [state] {$(0,3)$};
\node (04) at ($(03)+(3,0)$) [state] {$(0,4)$};
% Second row
"""
A quick ceaser cipher; used to decrypt a message from a mysterious twitter account: https://twitter.com/cryptogram_app
"""
import string
alphabet = string.ascii_lowercase
def decrypt(encryption, key):
"""
Decrypt a ceaser cypher encrypted message
import difflib
usr_input = 'Rum and Juice'
drinks = ['Jargerbomb', 'Vodka', 'Rum and Coke']
def match_ratio(string):
return difflib.SequenceMatcher(None, usr_input, string).ratio()
best_match = max(drinks, key=match_ratio)
print best_match
import difflib
usr_input = 'Vodca'
drinks = ['Jargerbomb', 'Vodka', 'Rum and Coke']
best_match = max(drinks, key=lambda x: difflib.SequenceMatcher(None, usr_input, x).ratio())
print best_match
phrases = ['Cats are nice', 'Dogs are awesome', 'Python is the best', 'I like doughnuts']
words_to_check = ['are', 'awesome', 'brilliant', 'cake']
# This might be your question
print 50 * "="
print 'Checking pairwise'
print 50 * '-'
for pair in zip(phrases, words_to_check): # You don't know the zip command yet I think but look it up and this could easily be done using other tools (iterating over things)
if pair[1] in pair[0]:
"""
Quick script to run a Monte Carlo simulation of the effect of utility assumptions for a blog post about the last play in the super bowl
"""
from __future__ import division
class NashEquilibrium:
"""
Class for the Nash Equilibrium (just something to hold data)
"""
def __init__(self, A, B, C, D):
"""
Script to analyse the rock paper scissors lizard tournament I played in class
"""
from __future__ import division
import matplotlib.pyplot as plt
def dictplot(D, f, title):
plt.figure()
values = [v / sum(list(D.values())) for v in list(D.values())]
plt.bar(range(len(D)), values, align='center')
\documentclass[tikz]{standalone}
\usepackage{tikz,amsmath}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
% First round
% Duel 1
\node (Sally) at (0,0) {Sally};
\node at ($(Sally) + (0,-.5)$) [blue] {P,P,L,R,Sc};
"""
Quick script and data to analyse game played in class against a random strategy
The variable 'student_data' is a list composed of lists of strategies recorded by
players in class against a computer player a series of 3 mixed strategies:
- (.2, .8)
- (.9, .1)
- (1/3, 2/3)
def simple_sum(a, b):
return a + b
print simple_sum(5, 3) # You should get 8