Project Euler 82 – Find the minimal path sum from the left column to the right column

January 27, 2012

http://projecteuler.net/problem=82 I’m looking forward to reading the forums in Euler for this one, as I’m curious to find a more elegant way to solve this problem… # euler 82 f = open(‘matrix.txt’, ‘r’) # grid is a dictionary with key as tuple (i,j) and value as value of node # i is row, j is [...]

Read the full article →

If I’m using a for loop to generate a list of strings, how do I create a list of the variables, and not a list of the strings?

January 26, 2012

I posed a question on StackExchange today…. http://stackoverflow.com/q/9020500/1171561

Read the full article →

Project Euler 79 – By analysing a user’s login attempts, find the secret passcode

January 24, 2012

http://projecteuler.net/problem=79 As I was researching the web for approaches to solving this problem, I found Kristian’s MathBlog article quite useful (as usual), and so I took up his suggestion to try implementing a topological sorting algorithm, which I found described in Wikipedia. I had some problems just using the pseudocode described in Wikipedia, mostly because [...]

Read the full article →

Thou Shalt Not Modify A List During Iteration

January 24, 2012

Some good coding tips from this blog….. http://unspecified.wordpress.com/2009/02/12/thou-shalt-not-modify-a-list-during-iteration/

Read the full article →

Project Euler 134 – Investigating consecutive primes and the Extended Euclidean Algorithm

January 22, 2012

http://projecteuler.net/problem=134 My code took 2.5 seconds. In order to optimize this code, I had to use the Extended Euclidean Algorithm that I read about in Wikipedia. Brute force won’t work, so this optimization speeds up the code substantially. In essence, you are solving for a linear congruence of the form ax = b mod n. [...]

Read the full article →

Project Euler 98 – Investigating words and anagrams that are square numbers

January 20, 2012

http://projecteuler.net/problem=98 A very hacky solution, I admit, but I got it to work. #euler 98 import time import math t0 = time.time() f = open(‘words.txt’, ‘r’) for line in f: a = line.split(‘,’) maxLength = 0 for i in range(len(a)): a[i] = a[i].strip(‘”‘) if len(a[i]) > maxLength: maxLength = len(a[i]) print “longest word has “, [...]

Read the full article →

Project Euler 101 – Building polynomial functions based on first k terms of a sequence

January 17, 2012

http://projecteuler.net/problem=101 #euler 101 # let’s use numpy for our linear algebra matrix operations import math from numpy import * # we’ll use the array data structure for vectors, matrix # multiplication, and inverses #tenth polynomial generating function (and the test cube function) def polyTerm(n): return int(1 – n + n*n – math.pow(n,3) + math.pow(n,4) – [...]

Read the full article →

Project Euler 102 notes – Triangle interiors

January 12, 2012

While I coded up my solution to Project Euler 102 using the article I read on Wolfram Alpha, I was trying to derive the steps they took to solve for a, b in the article – and I found it much more intuitive to just get to a, b by simply inverting the 2 x [...]

Read the full article →

Project Euler 102 – How many triangles contain the origin?

January 11, 2012

http://projecteuler.net/problem=102 I implemented the formula from this Wolfram Alpha article on “Triangle Interiors”. # euler 102 import math def dtn(a,b): # 2 by 2 determinant return a[0]*b[1] – b[0]*a[1] def points(p, p1, p2, p3): # take 4 points, check to see if p is in triangle p1p2p3 # v = v0 + av1 + bv2 [...]

Read the full article →

Machine Learning course – Statement of Accomplishment

January 10, 2012

Got my statement of accomplishment by email for the Machine Learning online course I took in the fall from Stanford’s Professor Andrew Ng. Psyched!! Machine Learning (Online Class) – Statement of Accomplishment(function() { var scribd = document.createElement(“script”); scribd.type = “text/javascript”; scribd.async = true; scribd.src = “http://www.scribd.com/javascripts/embed_code/inject.js”; var s = document.getElementsByTagName(“script”)[0]; s.parentNode.insertBefore(scribd, s); })();

Read the full article →