Coding with Khan
A better way to learn math?
Here’s a neat way of using Khan Academy that I’ve been messing around with to re-learn math and find some interesting programming exercises.
The Basic Idea
For the simplest exercise, you can use their practice area as a kind of interactive Project Euler.
Example
Finding the greatest common divisor. In this Khan Academy exercise, the user is presented with two numbers and asked to produce the greatest common divisor. Instead of watching the video lecture and solving the series of exercises I created a Python program that tries to follow the algorithm Mr. Khan describes in the youtube video.
I came up with this solution, which is actually pretty simple in that it only involves a few of the main concepts from programming.
def gcf(numOne, numTwo):
	numOneFactors = factors(numOne)
	numTwoFactors = factors(numTwo)
	for num in numOneFactors:
		if num in numTwoFactors:
			return num
def factors(number):
	factorsList = []
	counter = 1
	while counter <= number:
		if number % counter == 0:
			factorsList.append(counter)
		counter += 1
	#Return the list of factors in reverse
	return factorsList[::-1]
numOne = 12
numTwo = 8
print gcf(numOne, numTwo)
I’m not a good programmer, but even I know there’s a lot to be desired with this code. Maybe that’s a good thing, as there are some pretty simple scenarios that break it. What if you want to get the GCF of 3 numbers? What if a negative number is entered? That being said, it’s enough to get through the practice session for greatest common factors–a great way of testing the script.
It’s more fun than math class
This is just a baby of an idea, but I jumped at how much more excited it made me in comparison to over a decade sitting in a traditional classroom trying to memorize this stuff.
Some other ideas that I plan on looking into:
- Using processing.js to do drawing for geometry and trigonometry purposes
 - Some way of ‘programming algebra’ – user enters two polynomals to multiply, simplified product is returned. Doing this without a lot of parser code may be tough.
 - The above exercise works better for some topics than others. Dividing two numbers is as easy as entering ‘238599573949 / 98593830’. Creating visualizations of different division algorithms is more difficult than using the computer as a calculator, but provides an excellent way of digesting how computation by hand actually works.
 
If you spot an error, please let me know. The primary purpose of this site is for my own continued education, any benefit to you the visitor is purely accidental. blog comments powered by Disqus
