From 94ff968814e77ba9f95dc36af592a190f72ddc5e Mon Sep 17 00:00:00 2001 From: lepatrick714 Date: Tue, 18 Jul 2017 21:25:08 -0700 Subject: [PATCH] Added general recursion and python recursion --- sheets/_python/recursion | 15 +++++++++++++++ sheets/recursion | 11 +++++++++++ 2 files changed, 26 insertions(+) create mode 100644 sheets/_python/recursion create mode 100644 sheets/recursion diff --git a/sheets/_python/recursion b/sheets/_python/recursion new file mode 100644 index 0000000..8f2163f --- /dev/null +++ b/sheets/_python/recursion @@ -0,0 +1,15 @@ +# For what Recursion is, please check recursion + +# Simple Factorial Python Recursion +def factorial(n) : + if n == 0 : + return 1 + else : + return n * factorial(n-1) + +# Simple Greatest Common Divisor Recursion +def gcd(x, y) : + if y == 0 : + return x + else : + return gcd(y, x%y) diff --git a/sheets/recursion b/sheets/recursion new file mode 100644 index 0000000..68fe022 --- /dev/null +++ b/sheets/recursion @@ -0,0 +1,11 @@ +# Recursion +# Def: "...is a method where the solution to a problem depends on solutions to smaller instance of the same problem.." - wiki +# TL;DR: a function that calls itself inside its body. + +# Recursive programs - Pseduocode +function factorial: +input: integer n such that n >= 0 +output: n * (n-1) * (n-2) * ... * 1 = n! + + 1. if n is 0, return 1 + 2. else, return ( n * factorial(n-1) )