# -*- coding: utf-8 -*-
"""
Created on Sun Sep 27 15:11:09 2020

@author: jbobowsk
"""

# This script creates a few functions which are intended to be imported into
# other external scripts.

# First, we define the function 'fact' which, using a for loop,
# calculates the factorial of n.
def fact(n):
    z = 1
    for i in range(n):
        z = z*(i+1)
    return z

# Second, we define the function 'choose' which finds the number of combinations
# of selecting m items from n.  Note that 'choose' makes use of the 'fact' function.
def choose(n, m):
    c = fact(n)/(fact(n - m)*fact(m))
    return int(c)

# Third is the 'quad' function which calculates the quadrature sum of an array
# of numbers.
def quad(xx):
    total = 0
    for i in range(len(xx)):
        total = total + xx[i]**2
    return total**0.5