Matt

 

Welcome to the Tuesday between Christmas and New Year’s day. This is kind of an odd week of the year when lots of people are still on vacation, there’s not a whole lot going on at work, and it’s hard to get motivated after a few days of feasting and opening presents.

As such, I’m one of the few people at work and not a whole lot of missile engineering is happening. So I just spent half my lunch break looking at Google images of bad album covers. Why? I don’t know. But I’m certainly glad I did. It’s given me something to spend the next fifteen minutes writing about. And maybe even a source for more fun future posts. Here are a few I came across today, and my thoughts on them. Continue reading »

 

Unfortunately, this is not Spike Jones.

I just heard what I think to be the worst Christmas song ever. This is maybe the third time I’ve heard it this season. The song? Spike Jones singing “All I want for Christmas is my two front teeth.” Now I’d heard of Spike Jones. I mean, the dude has a pretty cool name. He’s got to be some macho man on par with Clint Eastwood or Bruce Springsteen, right?

Until looking him up on the Internet, this was my mental picture of him. A big, tough guy. Probably wore a purple pimp hat with a feather in it during the seventies. May have even had a gold tooth or two. He could get away with wearing a long fur coat. Chicks would dig him.

But then you hear him sing “All I want for Christmas” and you think, whoa, this big tough pimp-looking guy wouldn’t be singing this crapfest of a song. So you do what any good investigative journalist would do — you look him up on Wikipedia.

That’s exactly what I did and I have to admit, my worldview was shattered just a little bit when I learned Spike Jones isn’t who I thought he was. Or I should say “wasn’t” who I thought he was since he’s dead. Another fact I didn’t know about him. If you didn’t know what Spike Jones looked like, take a quick break and go look him up. It’s quite disturbing. Continue reading »

 

African Lungfish

I read an interesting story in the Science section of the NY Times this morning. It seems that Heather King (a biologist at the University of Chicago) and her team observed a few African Lungfish taking alternating steps with their back fins.

Can you image the fish pictured above, with those tiny back legs, hopping along a muddy riverbank? Of course not. Those appendages look like something from the Flying Spaghetti Monster. But… once upon a time, all animals lived in the water. According to these guys, and smart biologists everywhere, this was as recent as about 400 million years ago.

Why is this significant? The first animals to poop on land and eventually build space shuttles and particle accelerators, were likely very similar to the guy pictured above. Speaking of that, I’ve often wondered why these lobe-finned fish decided to leave the comforts of their oceans and boggy marshes. Probably a combination of the water becoming less oxygenated, or drying up, or the fact that there just weren’t enough good restaurants in their neighborhood. I’m sure they were disappointed to learn they were the first inhabitants of this new dry land and no one up here had invented restaurants yet. Continue reading »

 

At the risk of seeming like an intellectual snob (I’m not, I promise I’m not smart enough to be one), I’m posting this as a plea to anyone who routinely posts comments on any blogs anywhere.

Please, please, for the love of English teachers everywhere, spend a few minutes to learn a handful of words that come up time and time again. I promise, mastering these few words will not take very long. And while knowing these won’t make you a genius, it may keep millions of people from thinking you are an idiot.

Without further ado, here they are.

1) your and you’re. Whenever you find yourself in need of writing one of these words, ask yourself one simple question. Is what I’m writing short for “you are?” If it is, please use the second one. You know, the one with the apostrophe in it. The apostrophe means that it’s a contraction. Ie., two words have been contracted together. And when that happens, we sometimes leave letters out. The apostrophe is inserted where letters have been omitted. Continue reading »

 

The following is Problem 10 from Project Euler. As of this posting, it has been solved 62,312 times.

The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.

MATLAB and Octave have a function called “primes” which takes any number as an argument and returns an array of all the prime numbers below that number.

For example, calling primes(10) would return an array of [2 3 5 7].

So solving this problem in MATLAB feels like cheating. The below code executed in just a few milliseconds.

% ProjectEuler.net problem #010
% The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
 
% Find the sum of all the primes below two million.
 
tic();
 
format long
final_answer = sum(primes(2e6))
 
exec_time = toc()

I suppose I could write an algorithm to find the primes and brute-force it with an IF or WHILE loop, but I think I’d rather move on to the next problem. So there you have it. Happy coding!

 

The following is problem 9 of Project Euler. As of this posting, it has been solved 67,769 times.

A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
a^2 + b^2 = c^2

For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.

There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product a*b*c.

The following is a MATLAB and Octave solution. There may be no way around using nested FOR loops in this one. By using routine algebra to come up with the statement in the IF conditional, the program doesn’t have to loop through as many times. The following code executes in about 1.7 seconds.

% ProjectEuler.net problem #009
% A Pythagorean triplet where a<b<c, for which, a^2 + b^2 = c^2
% There exists exactly one for which a+b+c=1000. Find the product abc.
% Below code executes in 1.70 seconds.
 
clear
tic();
a=1; b=1;n=1000;
 
for a = 1:n
	for b = 1:1000-a
		if 1e6 - (2000)*(a+b) + 2*a*b == 0
			triplet(1:3) = [a b 1000-a-b];
		end
	end
end
 
triplet
final_answer = prod(triplet)
 
exec_time = toc()

There you have it. Good luck and happy coding!

 

In the last PHP tutorial, I showed how you could create an HTML form that would use PHP to write data into a MySQL database. In this tutorial, I’ll show you how you can use PHP to pull that data from the database and display it in your HTML. If you need the previous tutorial, you can find it here:

Simple PHP Script to Input Data to MySQL Database from HTML Form

If you recall, in our last example we have a database called “bozo” and a table called “famous_clowns.” In this table we have five fields. You can think of these as columns since we’ll be displaying them in an HTML table anyway. The data fields were: seed, name, country, rating and comments.

The below script is going to be called displayclowns.php. There’s nothing wrong with mixing your HTML with PHP calls, but the document needs to end with the .php extension so your server will know that it contains calls to PHP. Continue reading »

 

The following is problem 8 of Project Euler. To date, it has been solved 66,993 times.

Find the greatest product of five consecutive digits in the 1000-digit number.

73167176531330624919225119674426574742355349194934
96983520312774506326239578318016984801869478851843
85861560789112949495459501737958331952853208805511
12540698747158523863050715693290963295227443043557
66896648950445244523161731856403098711121722383113
62229893423380308135336276614282806444486645238749
30358907296290491560440772390713810515859307960866
70172427121883998797908792274921901699720888093776
65727333001053367881220235421809751254540594752243
52584907711670556013604839586446706324415722155397
53697817977846174064955149290862569321978468622482
83972241375657056057490261407972968652414535100474
82166370484403199890008895243450658541227588666881
16427171479924442928230863465674813919123162824586
17866458359124566529476545682848912883142607690042
24219022671055626321111109370544217506941658960408
07198403850962455444362981230987879927244284909188
84580156166097919133875499200524063689912560717606
05886116467109405077541002256983155200055935729725
71636269561882670428252483600823257530420752963450

The following is the Octave/MATLAB code that will solve it. The below executed in 1.502 seconds.

% ProjectEuler.net problem #008
% Find the greatest product of five consecutive digits in the 1000-digit number.
 
clear
t = clock;
 
% First, we'll treat the huge number as a string.
% Note, the code will need the whole number pasted here.
 
n = "7316717....3450";
 
for a = 1:996;
 
% Find the five numbers to multiply, convert from string to number.
for j=a:a+4
	five_nums(j-a+1) = str2num(n(j));
end
 
colm(a, 1:2) = [a, prod(five_nums)];
 
end
 
fin_answer = max(colm(1:996,2))
 
exec_time = etime(clock, t)
 
% It doesn't ask which numbers give this product, but by
% manually looking through colm, we see that they were
% the 365th - 369th digits, or 9,9,8,7,9.
 
the_digits = n(365:369)

There you have it. Happy coding!

© 2012 mattoneal.com Suffusion theme by Sayontan Sinha