Skip to content

Instantly share code, notes, and snippets.

@andrewpatt24
andrewpatt24 / fibonacci_memory.py
Created July 12, 2016 13:11
Fibonacci with memory - asked for it in a job application
class memstate:
"""
Takes a function with input:int and output:int
creates memory
"""
def __init__(self,func):
self.func=func
self.memory = {}
def __call__(self,inp):
if inp in self.memory.keys():
@andrewpatt24
andrewpatt24 / dota_elo_ratings.py
Last active August 29, 2015 14:22
"Dota 2 Game Prediction" submission to Hackerrank - 2nd in UK! (Code posted to Hackerrank is only bottom portion)
##########################################################################################################
## All below code is just calculation for each player type in game and there ELO from the training data ##
##########################################################################################################
################################################################
## General ELO rating functions ################################
################################################################
def expected_score(own_rating,opp_rating):
return 1.0/(1.0+10.0**((float(opp_rating)-float(own_rating))/400.0))
@andrewpatt24
andrewpatt24 / snakes_and_ladders.py
Created June 8, 2015 09:25
"Markov's Snakes And Ladders" Hackerrank submission
from random import random
n_games = int(raw_input())
def parse_game_data():
dict_temp = {}
dict_temp['game'] = i
dict_temp['dice_prob'] = [float(x) for x in raw_input().strip().split(',')]
@andrewpatt24
andrewpatt24 / the_best_aptitude_test.py
Created June 8, 2015 09:24
"The best aptitude test" Hackerrank submission
from scipy.stats.stats import pearsonr
n_tests = int(raw_input())
def parse():
n_cases = int(raw_input())
#print n_cases
final_data = {}
@andrewpatt24
andrewpatt24 / getFootyData.py
Created October 17, 2014 10:52
Pull Fantasy Football data and upload to a Mongodb database hosted on Mongolab
import requests
import htmlmin
import json
from bs4 import BeautifulSoup
from datetime import datetime, date, timedelta ##Basic Python
##define unique function
def uniq(seq):
# order preserving
@andrewpatt24
andrewpatt24 / server.R
Created October 7, 2014 16:26
server.R file for Shiny profiling app
library(shiny)
require(rCharts)
library(reshape2)
cluster.data <- read.csv("./data/cluster_data.csv")
graphoptions<-as.list(colnames(cluster.data))
names(graphoptions)<-colnames(cluster.data)
@andrewpatt24
andrewpatt24 / ui.R
Created October 7, 2014 16:25
ui.R file for Shiny profiling app
library(shiny)
library(rCharts)
library(reshape2)
cluster.data <- read.csv("./data/cluster_data.csv")
graphoptions<-as.list(colnames(cluster.data))
names(graphoptions)<-colnames(cluster.data)
@andrewpatt24
andrewpatt24 / squad_select.R
Last active August 29, 2015 14:05
Selecting my Fantasy football squad for the 2014/15 season
#install.packages("XML")
library(XML)
#install.package("caret")
library(caret)
#install.packages("lpSolve")
library(lpSolve)
###################################
## Take data from premier league website##
###################################
@andrewpatt24
andrewpatt24 / optSquad.R
Last active August 29, 2015 14:05
Optimal Fantasy Football squad selector
#install.package("caret")
library(caret)
#install.packages("lpSolve")
library(lpSolve)
Opt.squad<-function(dat,cost,n.gk=2,n.df=5,n.md=5,n.fd=3) {
#dat<-footy.data
#cost<-100
#n.gk=2
#n.df=5
<?xml version="1.0"?>
<root>
<item>
<name>Change zero 9 part 1</name>
<identifier>private.changezerotowierds1</identifier>
<autogen>
--KeyToKey--
KeyCode::KEY_9, ModifierFlag::CONTROL_L,
KeyCode::KEY_0
</autogen>