User:Jaigoda/Programming

Collatz
http://imgs.xkcd.com/comics/collatz_conjecture.png

Choose a number. If it is odd, multiply by 3 and add 1. If even, divide by 2. Repeat this process and eventually you will get 1.

My little Python program that I made from my (very limited) knowledge thanks to my high school Computer Programming I course: for n in range(1,101): #The range determines how many numbers will be evaluated. #1,101 means it will evaluate numbers 1 through 100. 1,1001 would be 1 through 1000. print str(n) + ":", while n != 1: if n % 2 == 0:  # If even, n = n/2     # Divide by 2. else:           # If odd, n = 3*n + 1 # Multiply by 3 and add 1 print (n), print print

Calculating the first 1000 numbers was pretty fun.

Fibonacci
i=500 nMinusOne = 0 nMinusTwo = 1 print "First " + str(i) + " numbers of the Fibonacci Sequence:" while i >= 1: n = nMinusOne + nMinusTwo print str(n) + ",", nMinusTwo = nMinusOne nMinusOne = n   i = i - 1

Really, really simple program. I realize I could probably use a for loop instead of my somewhat crude use of the while loop, but meh, I love doing "i = i - 1" crap. However, be warned that the first 500 numbers takes like 15-30 seconds to finish, and any higher n means multiplicatively longer times. For best effect, open the results in Notepad with Word Wrap on.
 * Now solve it recursively-- Relyk 23:32, 2 May 2012 (UTC)