Project Euler Challenge #3 : Finding Primes

July 24th, 2014

Finally, it gets interesting. Below is my third attempt on this problem, the first taking so long to complete that I improved it before its first iteration, and the second just wasn’t good enough.

def find_primes(number):
	"""Returns a set of primes"""
	primes = set()
	if number != int(number):
		raise Exception('Must be int') # Improve this
	if number < 4:
		return primes
	i = 2
	while number > 1:
		while number % i == 0:
			number = number / i
		i += 1
	return primes

In this solution, I learned some basic uses for python’s set builtin. I’m a better person today.

Project Euler Challenge #2 : Fibonacci Sums

July 24th, 2014

Another straightforward challenge: find the sum of all even numbers in the Fibonacci sequence less than four million.

 def even_fib_sum(limit = 10):
	num = 2
	pre = 1
	tot = 2
	while num < limit:
		num += pre
		pre = num - pre
		if num % 2 == 0:
			tot += num
	return tot

Yeah, yawn.

Project Euler Challenge #1 : Threes and Fives

July 24th, 2014

So I’ve been trying to improve my coding technique while thinking about some fun math problems, and Project Euler will help me achieve exactly that. It’s unfortunate that they were hacked recent, so a lot of their functionality has been removed, but it will still confirm your answer.

My rules for these challenges:

  1. Searching Google for answers or algorithms is not allowed.
  2. Searching Google for builtin language libraries is allowed.
  3. After a solution is found, the first rule can be ignored (provided advance knowledge of future challenges is not present).

Anyway, below is Challenge #1 by me. This was pretty straightforward and brute-force, but it works. The only interesting thing I’m doing here is playing with the flexible definitions of True/False.

def euler1(n=1000):
    """Returns the sum of all numbers that possess either three or five as factors."""
    for i in range(n):
        if not ((i % 3) * (i % 5)):
            s += i
    return s

Reclaiming the Blog

July 24th, 2014

Old posts are embarrassing and awkward (they’ll remain for now), spam has been scrubbed out, and all that’s left is some new content.

Post-Navy me, trying to establish an identity and develop as a person.

Expect coding challenges, notes-to-self, quotes, maybe a video or two. Awesomeness.

Stay tuned.

PBS Knows What’s Up

May 4th, 2008

If you want to know what the Navy is really like, watch PBS’s new documentary Carrier. The stories told are amazingly honest and dramatic. How this made it past the Navy’s bureaucracy so uncensored, we will probably never know. The entire series is available online for free (I love public media). Episode 3, Chapter 1 discusses nukes, in its own special way.

And for another take on Navy life, check out Hey Shipwreck. Watch up to (or start at) episode four, that’s where the show finds its rhythm and includes nukes.

Ziplock Bag Seals Magnified

March 19th, 2008

Ziplock bag seals magnified. Cool.

RFID Card Vulnerabilities

March 19th, 2008

How to hack RFID-enabled credit cards for $8.

He’s Still Crazy

March 15th, 2008

As much as I disagree with Glenn Beck, he makes a good point about Florida and Michigan.

Why We Love the Info

March 15th, 2008

An evolution-based explanation for nadding it out.

Pi Day 2008

March 14th, 2008

It’s Pi Day! (that song gets around)

Nasubi the Unfortunate

March 13th, 2008

Nasubi – The Truman Show for reals.

Laptop Travel Guide

March 13th, 2008

Traveling with your laptop is a serious affair.

Craigslist is Great

March 13th, 2008

Who loves capitalism?!?

Mary Rocks

March 13th, 2008

The Muslim Jesus – another surprising documentary.

The Wire’s War on Drugs

March 13th, 2008

The Wire’s War on Drugs.


March 13th, 2008

A supersonic jet is literally torn apart around the pilot.

Retro Sabotage

March 9th, 2008

Incompatible Visions – the latest game from Retro Sabotage.

The Press and the Powerful

March 8th, 2008

The relationship between the press and the powerful.

Big Trouble with Little Gravity

March 8th, 2008

There seems to be a problem with gravity, It might be due to hyperbolic orbits.

Everyone Should Be British

March 7th, 2008

An Englishman reviews a Ford F-Series pickup truck.