Archive for the ‘Uncategorized’ Category

Project Euler Challenge #3 : Finding Primes

Thursday, 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
			primes.add(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

Thursday, 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

Thursday, 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

Thursday, 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

Sunday, 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.

All Lanes Open

Monday, March 3rd, 2008

A surprisingly open Wal-Mart blog, and of course the NYT provides the relevant details.

There goes his feet!

Monday, March 3rd, 2008

This should make up for the spiders: Mocha and his first broccoli.

Books: Old Man’s War

Wednesday, February 27th, 2008

catwithhat.pngI finished reading Old Man’s War by John Scalzi last night. It’s another military sci-fi book. Yes, I know – this is not a healthy habit and I need to quit today. Maybe tomorrow.

The book’s interstellar politics can be easily described through the board-game monopoly: many alien species like planets similar enough to our own tastes that first contact typically occurs over territory disputes; humans are essentially boxed in from all sides by other species; if humans wish to remain competitive in a few centuries’ time they better start invading. It’s interesting how ethics are fundamentally based on self-preservation.

Earth is essentially excommunicated from all human colonies. This is to prevent disease as well as the culture shock of inter-species war of this scale. For example one encounter involved some bad aliens landing on an unarmed colony and enslaving all the colonists (enslaving in this case meaning caging everyone, milking the males, impregnating the females, and finally cooking up some human-flavored veal).

So the universe is a bad place where humans are not that popular. The military’s attrition rate stays around 80% mainly because every war they fight is completely different from the last. So enlistment takes place on Earth where no-one has a clue what they are in for. People sign up because it’s the only option to leave the planet. And that’s where the title comes from: enlistment is only accepted on the applicant’s 75th birthday. The recruit is then genetically modified to become a soldier who will (hopefully) be capable to compete with all the unknown alien badguys out there. I swear it makes more sense in the book.

The book is a quick read, about eight hours. It’s not “life-changing good” but still very enjoyable. The characters feel genuine and are hilarious which is what makes this book so much fun.

The Anti-Cockblock Argument

Wednesday, February 27th, 2008

Senator Obama has class, or at least he tries not to cockblock.

I <3 Movie Trailers

Saturday, February 23rd, 2008

Be Kind Rewind gets the Be Kind Rewind treatment. Indiana Jones and the Kingdom of the Crystal Skull learns to fit in with its siblings.

Books: The Forever War

Friday, February 22nd, 2008

stormtrooper.jpgI finished a book!

The Forever War is one of those military sci-fi books I read so much yet am too embarrassed to discuss with my real friends. Overall I would give it a 7/10, enjoyable but nothing too special. The author knows his physics, especially general relativity, which provides most of the interesting concepts behind this. He also served in the Army during Vietnam and it shows as the main character is painfully ostracized from society.

But for me the book really excels when it discusses the time-dilation effects of an interstellar war. The first veterans arrive back on Earth after a single skirmish thirty years after they left, but only two years from their perspective. Enemy reinforcements will unexpectedly arrive with equipment decades ahead of what the humans have, or show up to fight with weapons almost a century out of date. Soldiers are sent to worlds so distant and numerous that they often don’t even bother naming them.

There are other topics explored such as conscription, military sociology and culture, eugenics, and the economics of war. Interesting quirks in the world described are heavy drug use and fraternization, but he was a college student in the sixties so what can you do? It’s not as philosophically deep as Starship Troopers (the empirical standard to measure these stories by) but still fun. It took me about 12 hours to jog through it.

Anonymizing Life

Thursday, February 21st, 2008

zebra.pngPrivacy is one of my favorite topics to muse over, and it’s been in the news a fair bit in the last few weeks. So here’s a collection of thoughts poorly organized and randomly selected. For a far more interesting discussion on these topics listen to Bruce Schneier, especially his discussions of Liberty vs. Control as well as Little Kids and Strangers.

Popular Science posted an interesting article regarding privacy and personal information protection. I know, sounds pointless and possibly even too esoteric for anyone to care about but the article is surprisingly well researched, especially for a Popular Science piece. It documents how difficult it is to cover your trail in today’s world, and how simply attempting this often raises suspicion.

Another great article dealing privacy and consumerism examines how Build-a-Bear takes advantage of little kids to harvest private information. I can’t exactly explain why but this particularly disgusts me, and not because of the company but how the parents are just as complacent and unquestioning as their own kids.

A great service I’ve used many times is dodgeit.com, which offers free anonymous email access with RSS syndication. This allows effortless disposable email addresses without (directly) providing identifying information to the provider. But it does have it’s share of problems, primarily one cannot delete messages without registering an account. Therefore any registration emails you receive may potentially contain an account password and be available to anyone who happens to be looking. To secure or control an account you must make a donation through amazon.com or paypal.com, but now you’re giving out even more information, destroying your original intent.

Ideally anyone using dodgeit.com or similar services could access and delete any messages on the system, allowing an individual to control many accounts simultaneously while transparently sharing others. But all of this is moot as the site hasn’t posted a privacy policy and makes no mention of where information goes behind the html brackets, so please be aware of the risks. Assume the administrator is a New York prosecutor.

A much more amusing option for protecting your identity is to wear infrared LEDs. This is a long known trick based on the idea that modern surveillance cameras typically use light from the infrared spectrum. The LEDs broadcast light blinding the cameras while remaining invisible to the human eye. This is explored quite effectively in Cory Doctorow’s short story I, Robot (a re-imagining of Asimov’s world and one of my favorite short stories – highly recommended).

This all interests me because I deal with these issues daily at work, often from many sides. We regularly protect other’s privacy, as well as organizational security as a whole, but also monitor each other through what are known as “invasive policies.” However this is far from typical as my employer places particular emphasis on things like integrity and honor, whatever those are.

Anyway I apologize for posting such slop. Future posts will be better thought out I promise.

I Want a Pet Lion!

Thursday, February 21st, 2008

Lions are so cute

Henry Rollins Started Everything

Wednesday, February 20th, 2008

Death of a corporate news producer.

Find Israel

Wednesday, February 20th, 2008

World Survey: Wealth and Religiosity (graph).

I Wish I Went To High School in Korea

Wednesday, February 20th, 2008

US States Renamed For Countries With Similar GDPs.

Proper Punctuation

Tuesday, February 19th, 2008

A story about a semicolon.

Say Something.

Tuesday, February 19th, 2008

So for the past five days I have simply posted links. This does not bode well for the blog.

What can I say? Life has been boring. The most exciting event this weekend was starting Ocarina of Time: Master Quest on my N64 emulator. And whether you think that last sentence was sarcastic or not depends on how much you enjoy saving princesses.

The game is fun. The only differences between Master Quest and Regular Quest are the dungeons, specifically the puzzles and baddies within them. Harder monsters appear earlier and more frequent, often in ways that you don’t always expect. The puzzles have been made trickier, sometimes in ways where the original solution is now a trap. This creates a very sadistic Pavlov’s dog situation where I now fear my own memory but love the nostalgia. I don’t get it either.

If you want it, email me.

Free The Signal

Friday, February 15th, 2008

The Gaurdian learns you can’t control the message on the internets. Oops.

Madrid!

Friday, February 15th, 2008

An ad for the Madrid Subway.