Thursday, July 24, 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.
"""Returns a set of primes"""
primes = set()
if number != int(number):
raise Exception('Must be int') # Improve this
if number < 4:
i = 2
while number > 1:
while number % i == 0:
number = number / i
i += 1
In this solution, I learned some basic uses for python’s set builtin. I’m a better person today.
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
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:
- Searching Google for answers or algorithms is not allowed.
- Searching Google for builtin language libraries is allowed.
- 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.
"""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
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.
From Wednesday, August 5, 2009
“Those who can make you believe absurdities can make you commit atrocities.”
Sunday, May 4, 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.
From Sunday, May 4, 2008
The Best Wedding Toast Ever! Saying anything else would ruin the surprise.
Don’t Eat That – the worst foods in America.
How Valid are T.V. Weatherman – Freakonomics wants to know.
Childhood Nightmares, a portfolio by Joshua Hoffine.
From Sunday, March 23, 2008
Happy Easter – have a bunny.
From Wednesday, March 19, 2008
Ziplock bag seals magnified. Cool.
Wednesday, March 19, 2008
Last night I finished reading The Dark Knight Returns – yes, a comic book or graphic novel or whatever – and I loved it. Characters I’ve known since childhood are reintroduced many years after we last saw them and they are in situations they just don’t want to be in. Throughout I felt as if I was visiting a forgotten hometown, seeing old friends who have grown and changed, yet still living the same bland life that we all struggle with daily. These characters felt more alive than ever before.
I say all this because the story really is about the characters. Bruce Wayne is crazy, unstoppable, and at times suicidal in the pursuit of his own concept of justice. Commissioner Gordon knows that the city needs Batman and risks his own career and life on that increasingly unpopular idea. Superman is terrified of Wayne, not because of what he can do, but what he represents to the people they both protect. And the Joker needs Batman and is thrilled by that very fact: while musing over his victims he thinks “No, I don’t keep count. But you do. And I love you for it.” Reading that gave me goosebumps.
Again, I loved this story. The writing was amazing. The story was put together wonderfully. Real suspense often followed each page turn. I wish everything I read was this much fun.
As a side note, I read this on my iphone and it was suprisingly intuitive. Holding the phone vertically allowed me to see the entire page, holding it horizontally let me read the text while still seeing the entire width, pinching would zoom in and out, and simply tapping turned the page. It’s reasons like this that I love that phone.
From Wednesday, March 19, 2008
A More Perfect Union (direct link) – Senator Obama’s speech about the state of our country. Of course The Onion is on top of it.
From Tuesday, March 18, 2008
Joel on Software on the Internet Explorer Crisis: a comprehensive explanation that involves software development, Jewish Law, Microsoft Vista, marketing and sales, and Vonnegut inspired scenarios.
From Sunday, March 16, 2008
Remember that 763 mp3 torrent of selected SXSW artists? Well someone went and rated them all with six word reviews. From what I’ve sampled it’s crazy-accurate, but check out for the include observations such as the awesomeness vs. cuteness regarding female singers.