Skip to content

Instantly share code, notes, and snippets.

/*
* The function flattens an arbitrarily nested array of k-dimensions using recursion.
* The implementation is quite fast (i.e. O(n) where n is the total number of
* elements in the k-th dimensional array where k >= 1).
* However stack overflow errors could occur in cases where k is particularly large -
* thus requiring a very deep level of recursion.
*
* @param {number[][]} - A k-dimensional array where k >= 1
* @returns {number[]} - A 1-dimensional flattened array
*/
@MrfksIv
MrfksIv / fibonacci_cython.pyx
Created November 2, 2018 10:41
The fibonacci function written in Cython
def fib(int n):
cdef int i
cdef double a=0.0, b=1.0
for i in range(n):
a, b = a+b, a
return a
@MrfksIv
MrfksIv / python_design_patterns-intro.py
Last active September 24, 2018 11:31
python_design_patterns introduction code
# This is the class definition
class House(object):
def __init__(self, address, longitude, latitude): # This is the constructor
self.address = address
self.longitude = longitude
self.latitude = latitude
def get_house_position(self):
return "<House @ (%, %)>".format(self.longitude, self.latitude)