You should really check out Project Euler! It's a long list of problems of simply stated mathematical problems (often involving arithmetic and/or geometry) that require both mathematical ingenuity and computational ability to solve. Typically, this means you need to write a short computer program. For the simpler problems, you need to understand a basic mathematical idea and write a program that checks a bunch of cases. For more complicated problems, you typically need to use a little mathematical analysis to make your code more efficient so that it finishes in your lifetime.
More than anything, it's all great fun and the perfect recreation for the aspiring mathematician who likes the idea of gainful employment someday!
Let's take a look at a few examples.
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
Here's a little python code to solve the problem:
s=0
for n in range(1,1000):
if n%3==0 or n%5 == 0:
s = s+n
s
My hope is that this is not too hard to read. We initialize a variable s
(for sum) and let n
range from 1 to 1000. (1000 is not included.) Now, %
is the "mod" operator; n%m
yields the remainder after the integer $n$ is divided by the integer $m$, i.e. $n \mod m$. Thus, $n$ is divisible by 3 if n%3==0
. (The double equals sign tests for equality and returns True
or False
. If n%3==0 or n%5 == 0
, we add n
to s
.
How about you give problem 2 a go!
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
$$1, 2, 3, 5, 8, 13, 21, 34, 55, 89, \ldots$$By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
Python is a free, widely used, and pretty awesome programming language. It's relatively easy to use, can run interactively, and has a huge number of libraries for mathematics and the sciences. It can run right in a notebook via the Jupyter project. For this class, you'll need to give python a try to solve a couple of computational problems. There's two easy ways to get it:
Anaconda installs a full version of Jupyter right on your machine. This very webpage is a converted Jupyter notebook.