I hereby claim:
- I am dougyoung on github.
- I am dougyoung (https://keybase.io/dougyoung) on keybase.
- I have a public key ASAE5lQfO03fPjNXY6RW1aodXjMBr7trsxHfDn2_TMQZ2wo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
# TODO: Should make this an object for sharing. | |
heap = [] | |
def hasParent(index): | |
return parentIndex(index) >= 0 and parentIndex(index) < len(heap) | |
def hasLeftChild(index): | |
return leftChildIndex(index) < len(heap) | |
def hasRightChild(index): | |
return rightChildIndex(index) < len(heap) |
import java.util.*; | |
class Main { | |
private static class MedianHeap { | |
PriorityQueue<Integer> lowers = new PriorityQueue<>(new Comparator<Integer>() { | |
public int compare(Integer one, Integer two) { | |
return -1 * one.compareTo(two); | |
} | |
}); | |
PriorityQueue<Integer> uppers = new PriorityQueue<>(); |
package main | |
import "fmt" | |
func fibo(x uint64, y uint64, n uint64) uint64 { | |
fibos := [2]uint64{x, y} | |
var fibo uint64; | |
for i := uint64(2); i < n+1; i++ { | |
fibo = fibos[0] + fibos[1] |
package main | |
import "fmt" | |
func sieve(n uint64) []bool { | |
primeBits := make([]bool, n-2) | |
for i := uint64(2); i < n; i++ { | |
for j := i; (i*j)-2 < n-2; j++ { | |
primeBits[(i*j)-2] = true |
# Set working directory | |
setwd('/Users/dougyoung/Downloads') | |
# Load data | |
inboundLeadData <- read.csv('Inbound Lead Regression Analysis Data.csv', stringsAsFactors=TRUE) | |
# Inspect data | |
class(inboundLeadData) | |
dim(inboundLeadData) | |
names(inboundLeadData) |
# Recursive finds number: | |
def fib_recur(n) | |
return n if n <= 1 | |
fib_recur(n-1) + fib_recur(n-2) | |
end | |
# Computes F(n − 2) twice, F(n − 3) three times, etc., each time from scratch. | |
# O(2^n) | |
# Recursive with memorization: |
require 'set' | |
class Anagram | |
DefaultWordlist = (File.open '/usr/share/dict/words' rescue []) | |
.inject(Set.new) { |s, word| s << word.downcase.chomp } | |
def initialize(wordlist = DefaultWordlist) | |
@wordlist_signed = wordlist | |
.inject(Hash.new { [] }) { |h, word| h[sign(word)] <<= word; h } | |
end |
def prime_number_sieve(n) | |
primes = [] | |
integers_up_to_n = (2..n).to_a | |
integers_up_to_n.each do |i| | |
next if i.nil? | |
primes << i | |
not_prime = i + i | |
while (not_prime <= n) do | |
integers_up_to_n[not_prime - 2] = nil | |
not_prime = not_prime + i |
class Product | |
def self.recommend(products, distribution) | |
accumulative_distribution_intervals = ProbabilityHelper.cumulative_intervals(distribution) | |
accumulative_distribution_sum = ProbabilityHelper.cumulative_sum(distribution) | |
random_point_in_accumulative_distribution = Random.rand * accumulative_distribution_sum | |
accumulative_distribution_intervals.each_with_index do |interval, index| | |
if random_point_in_accumulative_distribution >= interval[0] && random_point_in_accumulative_distribution < interval[1] | |
return products[index] | |
end | |
end |