Skip to content

Instantly share code, notes, and snippets.

def perms(arr):
if len(arr) == 1:
return [arr]
ret = []
head = arr[:1]
for tail in perms(arr[1:]):
for i in range(len(arr)):
ret.append(tail[i:] + head + tail[:i])
return ret
@abarax
abarax / backtracking-perms.py
Created June 3, 2013 12:36
Based off the backtracking algorithm in 'The Algorithm Design Manual' but written in python.
__author__ = 'cody'
finished = False # found all solutions yet?
def backtrack(a, k):
if is_a_solution(a, k):
return process_solution(a)
else:
candidates = construct_candidates(a, k)
@abarax
abarax / qsort.py
Last active December 18, 2015 14:08
def quicksort(ls, low, high):
if high - low > 0:
pivot = partition(ls, low, high)
quicksort(ls, low, pivot-1)
quicksort(ls, pivot+1, high)
def partition(ls, low, high):
pivot = ls[high]
firsthigh = low
valid_input = '((()()))()'
invalid_input = '())'
bracket_stack = []
count = 0
for c in invalid_input:
count = count + 1
class node(object):
pass
class linked_list:
size = 0
def append(self, node):
if self.size == 0:
self.head, self.tail = node, node
package patmat
import common._
/**
* Assignment 4: Huffman coding
*
*/
object Huffman {
@abarax
abarax / batch-attachment-download.vb
Created November 14, 2013 02:57
Outlook macro for batch download of email attachments
Option Explicit
Sub SaveAttachments()
Dim strPath As String
Dim SH As Shell32.Shell
Dim Fldr As Shell32.Folder
Dim olFolder As Folder
Dim olItem As MailItem
Dim olAttach As Attachment
Const strSubject As String = "VA SSIM" 'text to look for in the subject line
/*!
* Bootstrap v2.2.1
*
* Copyright 2012 Twitter, Inc
* Licensed under the Apache License v2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Designed and built with all the love in the world @twitter by @mdo and @fat.
*/
/*
author: jbenet
os x, compile with: gcc -o testo test.c
linux, compile with: gcc -o testo test.c -lrt
*/
#include <time.h>
#include <sys/time.h>
#include <stdio.h>
@abarax
abarax / luke.js
Last active August 29, 2015 14:13
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Camera Rotate
//
// Give the camera rotate tool some mass so that
// camera motion is smoothed out
//
// Directions:
// Adjust the properties of the camera rotation by calling the various
// set____() methods of the cameraController object at the end of the script.