Skip to content

Instantly share code, notes, and snippets.

@bcbwilla
bcbwilla / monty.py
Last active December 19, 2015 08:59
Simple simulation of Monty Hall problem.
import random
#number of games to play
n = 5
#number of correct guesses on first guess
correct = 0
# run simulations
for i in range(n):
print 'cycle %i' % i
"""Genetic Algorithmn Implementation
see:
http://www.obitko.com/tutorials/genetic-algorithms/ga-basic-description.php
"""
import random
class GeneticAlgorithm(object):
def __init__(self, genetics):
self.genetics = genetics
pass
@bcbwilla
bcbwilla / skatescraper.py
Last active December 18, 2015 05:38
Scrapes interviews from the blog 'the chrome ball incident' (http://chromeballincident.blogspot.com) and then analyzes the word occurrence frequency. Output is then fed into wordle to make a word cloud (http://www.wordle.net/)
"""Scrapes interviews from the blog 'the chrome ball incident' for text analysis."""
import urllib
import string
from bs4 import BeautifulSoup
# url of first page of interviews
url = 'http://chromeballincident.blogspot.com/search/label/chrome%20ball%20interview'
interviews = 0
@bcbwilla
bcbwilla / mapreport.py
Last active December 17, 2015 07:29
Gather minecraft pvp match data from at oc.tc/matches
import urllib
from datetime import timedelta
from operator import itemgetter
import csv
from bs4 import BeautifulSoup
# function that does stuff
def match_stats(last_page=2, out_file='out.csv', info=False):
""" gets match statistics from oc.tc/matches pages
@bcbwilla
bcbwilla / filterx.nb
Last active December 15, 2015 10:59
This Mathematica function removes an {x,y} point if the point does not have a unique x value from a list {{x1,y1},{x2,y2},...}
(* This function removes an {x,y} point if the point does not
have a unique x value from a list {{x1,y1},{x2,y2},...} *)
removeDupX[l_] := (
nl = l;
length = Length[l];
xs = l[[All, 1]];
For[i = 1, i <= length, i++,
If[Count[nl[[All, 1]], xs[[i]]] > 1,
nl = Delete[nl, i];
xs = Delete[xs, i];
@bcbwilla
bcbwilla / qmhw6.nb
Last active December 15, 2015 10:39
Graduate Quantum Mechanics II, HW 6, #4
En[n_, a_, V_] :=
Assuming[a \[Element] Reals &&
a > 0, (1/8)*Integrate[D[n, x]^2/n, {x, -Infinity, Infinity}] +
Integrate[V*n, {x, -Infinity, Infinity}]]
V[x_, k_] := (1/2)*k*x^2
\[Psi][x_, a_] := (1/Sqrt[2*Pi*a])*Exp[-x^2/(2*a)]
Enf = En[\[Psi][x, a]^2, a, V[x, k]]
Solve[D[Enf, a] == 0, a]
@bcbwilla
bcbwilla / euler.nb
Last active December 15, 2015 09:39
Mathematica functions for solving first order differential equations numerically
(* Numerical Schemes *)
(* Regular Euler Method *)
euler[y0_, npoints_, a_, b_, f_] := (
h = (b - a)/(npoints - 1);
y = Table[0, {npoints}];
t = Table[0, {npoints}];
y[[1]] = y0;
t[[1]] = a;
Do[
yn = y[[n]];
@bcbwilla
bcbwilla / makereport.py
Last active December 15, 2015 08:59
Computes statistics for teams competing in Project Ares Minecraft Tournaments. The data is scraped for each player on each team from their profile page at http://www.oc.tc. The data is processed and a .csv report file is produced. The data scraping is completely dependent on the html structure of the profile and tournament page, so this script w…
'''
Created on Mar 24, 2013
@author: Ben
'''
import pATournamentReport as r
#Example of how to use the classes.
base_url = "https://oc.tc"