Skip to content

Instantly share code, notes, and snippets.

/**
* This program shows the different kinds of calls that can be made for functions like the factorial, and fibonacci
*
*/
public class FactorialExample {
public static void main(String[] args) {
System.out.println( factRecursive(5));
System.out.println( factTailRecursive(5));
System.out.println( factIterative(5));
@garykpdx
garykpdx / enforced_parameters_decorator.py
Last active August 29, 2015 14:16
A decorator that enforces a particular type/subtype for each parameter of a function
class enforce(object):
def __init__(self,*argtypes):
# the types that need to be enforced for each position arg[i]
self.argtypes = argtypes
def __call__(self,f):
def wrapper(*args):
# bail if the definition isn't set up to handle this many arguments
if len(self.argtypes) < len(args):
raise Exception('too many parameters passed in')
@garykpdx
garykpdx / concurrent_example.py
Last active July 12, 2016 19:33
Example of concurrent processusing Python builtin library(example modified from example in Python docs)
#!/usr/bin/env python
import os
from concurrent.futures import ProcessPoolExecutor
import math
import time
PRIMES = [
112272535095293,
112582705942171,