This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bruteForce(A): | |
counter = 0 | |
for i in range(len(A)): | |
for j in range(i, len(A)): | |
if A[i] > A[j]: | |
counter += 1 | |
return counter | |
def countSplitInversions(B, C): | |
i,j,D = 0,0,[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def BinarySearch(val, A, idx = None): | |
"""Recursive algorithm for performing binary search""" | |
#idx: the rightmost index based on the numbering of the original array | |
n = len(A) | |
if idx == None: | |
idx = (n - 1) | |
if n == 1: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def Partition(A, pivot_idx, l, r): | |
#Choose a random value to be the pivot | |
pivot = A[pivot_idx] | |
#Move pivit to first position in subarray | |
A[l], A[pivot_idx] = A[pivot_idx], A[l] | |
#stores the idx of the last value less than or equal to the pivot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on Sun Feb 15 18:35:50 2015 | |
@author: mwoods | |
""" | |
import random | |
toy_graph = {1: [2, 4], | |
2: [1, 4, 3], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rgl) | |
x <- rep(NA, 20000) | |
y <- rep(NA, 20000) | |
z <- rep(NA, 20000) | |
color <- rep(NA, 20000) | |
#subspace | |
for(i in 1:10000){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#------------------------------------------------------------------------------- | |
# Name: module2 | |
# Purpose: | |
# | |
# Author: mwoods | |
# | |
# Created: 22/04/2015 | |
# Copyright: (c) mwoods 2015 | |
# Licence: <your licence> | |
#------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#------------------------------------------------------------------------------- | |
# Name: module1 | |
# Purpose: | |
# | |
# Author: mwoods | |
# | |
# Created: 15/05/2015 | |
# Copyright: (c) mwoods 2015 | |
# Licence: <your licence> | |
#------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://www.reddit.com/r/dailyprogrammer/comments/36cyxf/20150518_challenge_215_easy_sad_cycles | |
def next_digit(n, b): | |
return sum([int(d)**b for d in str(n)]) | |
def recover_cycle(nodes, end): | |
tmp = [] | |
while nodes: | |
node = nodes.pop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#------------------------------------------------------------------------------- | |
# Name: module1 | |
# Purpose: | |
# | |
# Author: mwoods | |
# | |
# Created: 20/05/2015 | |
# Copyright: (c) mwoods 2015 | |
# Licence: <your licence> | |
#------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Answer to https://www.reddit.com/r/dailyprogrammer/comments/3629st/20150515_challenge_214_hard_chester_the_greedy/ | |
#Needs to be further optimized and revisit quadtree implementation (use a bounded quadtree instead or a k-d tree | |
import heapq | |
from collections import deque | |
import random | |
start = [0.5, 0.5] | |
food = [(0.9, 0.7), (0.7, 0.7), (0.1, 0.1), (0.4, 0.1), (0.6, 0.6), (0.8, 0.8)] |