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/env python | |
# Four men want to cross a bridge. The bridge is of a width such that a | |
# maximum of 2 people may cross at a time. | |
# | |
# One man takes 10 minutes to cross, another takes 5 minutes to cross, | |
# another takes 2 minutes to cross, and the last takes 1 minute to | |
# cross. | |
# I will call these men A, B, C, and D, respectively. |
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/env python | |
import timeit | |
def w_swap(min, max): | |
if min > max: min, max = max, min | |
def w_builtin(x, y): | |
min_val, max_val = min(x, y), max(x, y) |
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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" | |
"http://www.w3.org/TR/html4/loose.dtd"> | |
<html lang="en"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
<title>untitled</title> | |
<script type="text/javascript" | |
src="http://www.google.com/jsapi"></script> |
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/env python | |
# -*- coding: utf-8 -*- | |
# http://stackoverflow.com/questions/3744048/python-how-to-merge-a-list-into-clusters/3744095#3744095 | |
import itertools | |
def merge_it(lot): | |
""" | |
>>> merge_it( [(3,4), (18,27), (4,14)] ) |
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
#!/bin/sh | |
# ================================================================ | |
# | |
# Convert a mysql database dump into something sqlite3 understands. | |
# | |
# Adapted from | |
# http://stackoverflow.com/questions/489277/script-to-convert-mysql-dump-sql-file-into-format-that-can-be-imported-into-sqlit | |
# | |
# (c) 2010 Martin Czygan <martin.czygan@gmail.com> |
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/env python | |
# http://www.disinformatics.com/blog/2010/12/14/a-google-internship-interview-question-in-scala/ | |
# The question is: | |
# given a sorted array of integers and a target integer, | |
# find a pair of integers in the array that sum to the target in linear time. | |
# The Solution | |
# |
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/env python | |
def equi(A): | |
upper = sum(A) | |
lower = 0 | |
for position in range(0, len(A)): | |
if upper - A[position] == lower: | |
return position | |
else: | |
lower += A[position] |
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/env python | |
def maximize(a): | |
""" Find the maximal difference between items u, v | |
(where index(u) < index(v)) of a given sequence ``a``. | |
Think stockmarket prices. | |
Returns the actual difference, start and end position in ``a`` and | |
the sublist yielding the best result. |
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/env python | |
# http://stackoverflow.com/questions/4585255/how-to-filter-all-words-which-contain-n-or-more-characters/4585315 | |
import sys, re | |
def morethan(n, file_or_string): | |
try: | |
content = open(file_or_string, 'r').read() | |
except: |
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
<!DOCTYPE html> | |
<head> | |
<meta name="found-at" content="http://www.computedstyle.com/2010/12/hiring-front-end-engineers.html"> | |
<meta name="description" content="A div with an id of 'slideshow' contains | |
five images, the first of which is shown and the others are hidden using a | |
display style of none. Using Javascript, create a simple slideshow that cycles | |
through the images, displaying each image for three seconds at a time, looping | |
back to the first image when the end is reached. You cannot use jQuery or any | |
other library."> |