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 Counter | |
all_possible_results = [] | |
for first_roll_result in range(1, 8): | |
for second_roll_result in range(1, 8): | |
for third_roll_result in range(1, 8): | |
for fourth_roll_result in range(1, 8): | |
for fifth_roll_result in range(1, 8): |
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
#include <stdio.h> | |
#ifndef max | |
#define max(a,b) ((a) > (b) ? (a) : (b)) | |
#define min(a,b) ((a) < (b) ? (a) : (b)) | |
#endif | |
int getminElement(int [], int); | |
int getmaxElement(int [], int); | |
int highest_product_of_3(int[], int); |
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
Please translate this code. | |
It's available below in Python, Ruby, Java, and JavaScript. | |
You can consult whichever version you like. | |
Then save your answer as a new gist and send me a link. | |
Thanks! | |
--Parker |
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 rand7(): | |
return random.randrange(1,8) | |
def rand5_mod(): | |
return rand7() % 5 + 1 | |
def rand5_recursive(): | |
roll = rand7() |
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 binary_search(target, nums): | |
# see if target appears in nums | |
# the number /cannot/ be at floor_index or ceiling_index-- | |
# floor and ceiling are "just outside" the range of possibilities | |
floor_index = -1 | |
ceiling_index = len(nums) | |
# if there isn't at least 1 index between floor and ceiling, | |
# we've run out of guesses and the number must not be present |
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 get_best_profit_brute_force(stock_prices_yesterday): | |
max_profit = 0 | |
# go through every time | |
for outer_time in xrange(len(stock_prices_yesterday)): | |
# for every time, go through every OTHER time | |
for inner_time in xrange(len(stock_prices_yesterday)): |
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
class WordCloudData: | |
def __init__(self, input_string): | |
self.input_string = input_string | |
self.words_to_counts = {} | |
self.populate_hash() | |
def populate_hash(self): | |
# | |
current_word = '' |
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
<div code-sample> | |
. () | |
/ \ | |
o o | |
/\ /\ | |
o o o o | |
/ \ / \ | |
o o o o | |
/ \ / \ | |
o o o o |
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
# InterviewCake (Beta Exercise 5) | |
# Brett Beutell | |
# June 17, 2014 | |
import sys | |
# Let top_left be a 2-tuple | |
# E.g., top_left = (x,y) | |
# Create a rectangle class containing the top_left x and y coordinates, width, and height |
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 largest_product_of_3(array_of_ints): | |
greatest = array_of_ints[0] | |
smallest = array_of_ints[0] | |
greatest_product_of_two = array_of_ints[0] * array_of_ints[1] | |
smallest_product_of_two = array_of_ints[0] * array_of_ints[1] | |
greatest_product_of_three = array_of_ints[0] * array_of_ints[1] * array_of_ints[2] | |
for current_int in array_of_ints: |