diff options
author | Chris Ball <cjb@pullcord.laptop.org> | 2007-08-28 21:36:32 (GMT) |
---|---|---|
committer | Chris Ball <cjb@pullcord.laptop.org> | 2007-08-28 21:36:32 (GMT) |
commit | a8eedd102ba32233d52fbb45b1f67b255d6e8396 (patch) | |
tree | 2e9709284a14cccafc2812ae7f9d3c72f55629c7 /data | |
parent | 4d3670ccd35eabbd3084ed932a3dffb0c23ff064 (diff) |
Examples update.
Diffstat (limited to 'data')
-rw-r--r-- | data/math/fibonacci | 1 | ||||
-rw-r--r-- | data/math/sierpinski | 25 | ||||
-rw-r--r-- | data/python/recursion | 10 |
3 files changed, 35 insertions, 1 deletions
diff --git a/data/math/fibonacci b/data/math/fibonacci index 7788182..9bc1acb 100644 --- a/data/math/fibonacci +++ b/data/math/fibonacci @@ -2,4 +2,3 @@ a, b = 0, 1 while b < 1001: print b, a, b = b, a+b - diff --git a/data/math/sierpinski b/data/math/sierpinski new file mode 100644 index 0000000..c034d93 --- /dev/null +++ b/data/math/sierpinski @@ -0,0 +1,25 @@ +# Sierpinski triangles +size = 5 +modulus = 2 + +lines = modulus**size + +vector = [1] +for i in range(1,lines+1): + vector.insert(0,0) + vector.append(0) + +for i in range(0,lines): + newvector = vector[:] + for j in range(0,len(vector)-1): + if (newvector[j] == 0): + print " ", + else: + remainder = newvector[j] % modulus + if (remainder == 0): + print "O", + else: + print ".", + newvector[j] = vector[j-1] + vector[j+1] + print + vector = newvector[:] diff --git a/data/python/recursion b/data/python/recursion new file mode 100644 index 0000000..c34638d --- /dev/null +++ b/data/python/recursion @@ -0,0 +1,10 @@ +def countbackwards(number): + print "I have the number", number + if number > 0: + print "Calling countbackwards again!" + countbackwards(number-1) + else: + print "I am done counting" + +number = input("Enter a number: ") +countbackwards(number) |