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(ggplot2) | |
library(grid) | |
library(rworldmap) | |
library(grid) | |
# Data sources: | |
# https://en.wikipedia.org/wiki/Timeline_of_women%27s_suffrage | |
# http://womensuffrage.org/?page_id=97 |
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
package model; | |
public class MonteCarloToolbox { | |
public static boolean[] dartThrow(int r, int d) { | |
boolean[] booleanArray = new boolean[d]; | |
for (int i = 0; i < d; i++) { | |
double xCoord = Math.random() * r; | |
double yCoord = Math.random() * r; | |
// condition check |
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
#!/usr/bin/python | |
# Usage example: | |
# python comments.py --videoid='<video_id>' --text='<text>' | |
import httplib2 | |
import os | |
import sys | |
from apiclient.discovery import build_from_document |
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
from itertools import tee, izip | |
from copy import copy | |
def pairwise(seq): | |
a, b = tee(seq) | |
b.next() | |
return izip(a, b) |
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 math | |
def solution(A, B): | |
bottom = int(math.ceil(math.sqrt(A))) | |
upper = int(math.floor(math.sqrt(B))) | |
# int should be enough | |
return upper - bottom + 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
# Majority Element of an Array (Moore’s Algorithm) | |
# If n is odd then it should appear at least (n+1)/2 times | |
# If n is even then it should appear at least (n/2) + 1 times | |
def dominant(A): | |
x = None | |
count = 0 | |
for i in A: |
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
public class Asymetry { | |
public static int solution(int X, int[] A) { | |
int n = -1; | |
int right = A.length - 1; | |
int left = 0; | |
int rightCounter = 0; | |
int leftCounter = 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
public class MaxSliceSum { | |
public int solution(int[] A) { | |
int ans = A[0], sum = 0; | |
for (int i = 0; i < A.length; i++) { | |
if (sum > 0) { | |
sum += A[i]; | |
} else { | |
sum = A[i]; | |
} | |
ans = Math.max(ans, sum); |
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
from timeit import timeit | |
def is_palindrome(input): | |
return input == reduce(lambda x, y: y + x, input) | |
def is_palindrome2(input): | |
start = stop = None | |
step = -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
from collections import defaultdict | |
def get_distance(l): | |
assert len(l) > 0 | |
return l[-1] - l[0] # takes O(1) time | |
def solution(A): | |
distances = defaultdict(list) |
NewerOlder