Archive for the 'Tech' Category

A better solution to the FizzBuzz interview problem

Wednesday, July 2nd, 2008

Many months ago, I wrote about a simple programming problem that I was administering to interviewees at work to assess their programming skills. The basic problem is this: loop through a range of integers, outputting different strings depending on whether each integer is divisible by one given number, by another given number, by both given numbers, or by neither. It’s a very basic weed-out problem that can be solved easily by any applicant with a basic understanding of control structures and modular arithmetic.

Last week, the comments section on that post erupted with new activity. I posted my own solution, which I was then criticized for because it used more than two division operations per integer (and as you should know, division is by far the most expensive basic arithmetic operation on a computer). So I got to brainstorming and I quickly came up with a solution that uses two divisions total, no matter how large the range is. I’m pretty convinced that my solution is very close to optimal (minus some minor fudging regarding how the if-statements are laid out and how the modular incrementing is handled). Here’s the solution in Java, simply because Java is the language most job applicants seemed to want to solve the problem in:


public class FizzBuzz {
	// I got lazy and coded in the parameters as constants instead of as arguments.
	static final int x = 3; // The first integer to test divisibility on
	static final int y = 5; // The second integer to test divisibility on
	static final int a = 27; // The starting number in the range to process
	static final int b = 74; // The ending number in the range to process

	public static void main(String[] args) {
		int x1 = a % x; // These are our only
		int y1 = a % y; // two divides!!
		for (int i = a; i <= b; i++) {
			if (x1 == 0) System.out.print("Fizz");
			if (y1 == 0) System.out.print("Buzz");
			if (x1 != 0 && y1 != 0) System.out.print(i);
			System.out.println("");
			x1 = ( x1 == x - 1 ? 0 : x1 + 1);
			y1 = ( y1 == y - 1 ? 0 : y1 + 1);
		}
	}
}

Pretty nifty, eh? Instead of having to perform expensive division operations on each integer in the loop, we’re simply incrementing two modular counters. This solution immediately suggests a good part two for the FizzBuzz interview question. After the applicant demonstrates basic familiarity with how programming works by writing up the naive solution, test their analytical abilities by asking them to come up with a more efficient version of the same program. If they don’t know it already, explain that division operations are expensive, and then ask them to minimize the total number of division operations necessary.

There will be a fair number of people who can get through the first part of the problem but won’t be able to get through the second part of the problem without a lot of hints. It’s these people that you may want to avoid hiring, because being able to improve on the naive algorithm and find more optimized ways of doing things is very important in programming. So, if you happen to be in a hiring position at a programming company, do try this problem out, and let me know how it goes!

Field Day 2008, wherein even a near-miss with a collapsing antenna can’t spoil the fun

Tuesday, July 1st, 2008

On Saturday this past weekend I did so many ham radio activities I had to split them across two blog posts. Yesterday I wrote about the 17 foot antenna I installed on top of my house. Today, I’ll regale you with tales from Field Day 2008.

Field Day is an annual 24-hour North American amateur radio event running from 2pm on Saturday to 2pm on Sunday. Amateur radio clubs and operators all across the nation set up stations off the grid as an emergency preparedness exercise and public outreach event. Contesting is a large part of it, with the goal being to make confirmed contacts with as many other Field Day stations as possible. So after finishing setting up our own antenna, and after grabbing a quick bite for dinner, my dad and I headed over to Montgomery Amateur Radio Club’s (W3EXP) Field Day location at the Montgomery College campus in Germantown, Maryland.

The Field Day setup was quite impressive. Antennas were everywhere. Many temporary masts, some guyed, some not, filled two different parking lots, a gravel area, and a field. Longwire antennas were strung between trees and in giant inverted-Vs off masts. Altogether the setup had eight separate antenna systems and at least fifteen towers/masts. Two gasoline generators provided electricity for all of the equipment. Three separate rental vans were set up as operating stations, with the radio stations inside of them shielded from the weather (they had a bad experience last year with the weather).

When we arrived, W3TDH was still working on setting up a 20m Yagi on a 50′ crank-up military mast made of aircraft-grade aluminum left over from the Korean War. Unfortunately, we never got that antenna up, because about an hour before dark a vicious thunderstorm blew in. Luckily, being at a ham radio station is about the best place to be when inclement weather is coming in, because everyone was kept apprised with up-to-the-minute weather information using the club’s repeater (it seemed like everyone there had a handheld VHF radio). I was also getting weather reports off the National Weather Service’s channels and the Blumont, Virginia ham radio repeater (147.300), which runs a SkyWarn net during inclement weather. As the storm came in, we shut off the transceivers and most of us headed into the nearest building on Montgomery College’s campus.

However, before I started to go inside, I had the immense “pleasure” of watching two guyed masts come down in the gale-force winds just forty feet away from me. Apparently they had been put up with only two guyed tiers (against W3TDH’s recommendation to use all three), and they came down quite quickly in the high-speed winds. It was a sight to see. The bottom sections of the masts, which were not secured to the ground, blew sideways, either coming undone from their locking joints or snapping right off. Then the entire masts toppled over sideways, straining against their guy anchors, many of which came ripping right out of the ground. Guy wires flew menacingly across the darkening sky. I was very fortunate not to be downwind of the masts when they blew over, because I was closer to them than they were tall. After this, I dithered no further outside.

After weathering out the storm inside the Science Building at Montgomery College until it was merely raining, we emerged to survey the extent of the damage. Those two masts were the only things that were damaged by the storm. Everything else survived just fine. Unfortunately in the meantime darkness had descended, and making progress on putting up that 20m Yagi became nearly impossible.

Read the rest of this entry »

Taking amateur radio to the next level

Monday, June 30th, 2008

This weekend was pretty awesome. Saturday was jam-packed with ham radio activities, from morning until midnight (and beyond). That’s right, an entire day of ham radio! I started off by installing the 17-foot antenna I bought awhile back on top of our house. That took a good four to five hours, many of them spent on top of a burning-hot roof forty feet in the air. But it was worth it! Here’s a close-up look at the antenna.

Don’t be fooled by the upwards-looking perspective; this antenna is a full 17′ tall. The mount also adds about two feet to the overall height. Altogether, the antenna is about 30′ in the air. That’s not bad considering we didn’t have to put up a tower or anything. The three spokes sticking out of the bottom of the antenna are the radials, which create the ground plane for the radio signals. And I should point out that this antenna is a marked improvement over my previous antenna, which was a 44-incher at ground level.

The two flanges of the mount are located off-center on the pressure-treated wood blocks. This was not intentional, but rather, a consequence of bad measurement and trying to get the darn thing straight up in the air. But don’t let its looks fool you: the mount itself is rock-solid. You could throw a grappling hook through the mount and ascend to the roof from the ground. Each wooden block is secured with four 4.5″ bolts to blocks of wood on the interior of the house that are screwed directly into the house’s frame.

Read the rest of this entry »

Wherein my computer joins a Stand Alone Complex

Sunday, June 29th, 2008

A year ago, Drinian was in Akihabara, Japan and he happened to pick up some Laughing Man stickers. He didn’t end up using most of them though, and he figured I would get more enjoyment of them than he would, so he gave them to me. I highly suspect that he was correct, because I’m having a blast with them. Unfortunately I only have three left, so I have to start rationing them carefully, but here’s what I did with one of them.

I bought a new computer recently that has been serving as my primary GNU/Linux desktop for the past few weeks. I initially wanted to build a computer from parts, because there’s a huge hackerish appeal to it (and because it’s usually cheaper), but then I came upon a fantastic deal on a Dell small business computer that I couldn’t turn down. But it just left the hardware nerd in me a little bit unsatisfied. It’s just another Dell box; it’s totally blah. Hell, it even came with Windows Vista stickers on it (which I have since removed); yecch! Laughing Man sticker to the rescue!

Luckily, the Laughing Man sticker was just the perfect size to fit directly on top of the Dell logo. My computer has gone from corporate to geeky. It’s gone from slaving away on mundane tasks to joining a Stand Alone Complex and fighting in the guerrilla Free Software movement against Big Proprietary Software. Err, something like that. So thank you Drinian for the stickers!

Now if only I could replenish my supply of Laughing Man stickers without having to cross over eleven time zones.

Death in the digital age?

Saturday, June 28th, 2008

My great-aunt died over three months ago, yet a week hasn’t gone by yet where we haven’t gotten some piece of mail addressed to her. How does death work in the digital age, anyway? Are you not truly gone until you are expunged from that one last database, after that final robotically-processed letter has been sent out?

Death has become quite the lingering affair.

What, a techie worry about inflation? Never!

Friday, June 27th, 2008

I’ve been thinking about my expenses over time, and not only am I now spending less in real terms (adjusted for inflation), I am now spending less in absolute terms (raw dollar amounts at the time of purchase). Here are some examples. I bought a 20″ flat-screen display for my computer three and a half years ago for $700. I could get the same thing nowadays for $200. I spent around ~$1400 total on a new computer back in January 2007
, versus the ~$500 total I spent on a new computer this month that is better than the previous one in almost every way. And I haven’t bought a flat-panel television, a digital camera, or a mobile phone recently, but I may soon, each of which is now cheaper than ever before. Technology expenditures make up a substantial portion of my budget, so when the price of technology continues dropping year over year, I notice a big difference in how much money I’m saving up.

In the developing world, or amongst those living below the poverty line in developed nations, inflation has not been kind. Cost of living increases have been especially vicious, doubling the price of many basic food staples in the past year alone. Gasoline price increases have also dealt a cruel blow. Yet few increases have hit me very hard: my food expenditures are still a comparatively tiny part of my income, health care increases don’t affect me much because I’m young and I get free insurance through my employer, etc. The one increase that hasn’t been kind to me has been the price of gasoline, as I do commute to work regularly. But the price in gasoline has still been offset by all of the money I’m saving on gadgets.

Take an average 5% cost of living increase year-over-year (if ones income is also increasing at 5% a year, then ones real wage remains constant). Then look at Moore’s Law, which specifically addresses the increase of transistor density on microprocessors over time, but which can also be applied to the cost of technology of equivalent performance over time. Moore’s Law gives us a doubling in performance every two years, or equivalently, a halving in price for the same performance every two years. That’s a 30% annual cost of technology decrease for equivalent performance.

If you’re trying to stay on top of the latest and greatest in computer technology, then yes, costs haven’t decreased over time; a top of the line graphics card or processor will always be expensive. This is because the performance of computer components is increasing with Moore’s Law (thus canceling out the exponential price decreases), so the tiers remain roughly equivalently priced over time. But what was the high-end tier two years ago is now the low-end tier today. Most consumers’ technology needs do not grow exponentially like the technology itself does.

If all you’re doing is word processing, web browsing, and email, you don’t need to keep up with the latest and greatest hardware like gamers do, so a computer with basic functionality is much cheaper now than it was before. Many other consumer electronics items follow this basic curve as well: quality digital cameras are far cheaper than they’ve ever been; the same for big screen flat-panel televisions. You can get a 50″ flat-panel television for $1,500 now; two years ago, it was around $5,000. All hail rapidly decreasing costs of technology!

So if you’re a techie like I am, and you do spend a significant portion of your income on technological gadgets, do not fear the passage of time: relish it! Even though our economy is really tanking at the moment, I can’t be too sad about it. The march of technological progress continues ever onwards, bringing us ever more amazing things at ever-decreasing prices. The effects of time are hitting lots of people really hard as the prices of most basic needs grow much more quickly than real wages, but not everyone is suffering.

How to fix images not displaying in Microsoft Word 2007

Thursday, June 26th, 2008

Recently I’ve been hit by a bug (or what I thought was a bug) in Microsoft Word 2007: images embedded in the document did not display in any mode other than “Full Screen Reading”. And since the editing ribbons are not available in that mode, it’s hard to get work done. This all started when Word crashed on me one time; ever since then, images simply haven’t been displaying correctly. I get a border where the image should be and white space inside. But when I send the file to other people and they open it, they can view the images just fine. I can even add images to documents; I just can’t see them.

So I performed a Google search on this issue, but the only relevant “solution” was behind a paywall over at ExpertSexchange. After a few minutes of trying to figure it out on my own, I stumbled upon the solution, and to save everyone from the hell that is ExpertSexchange, here it is:

Click the Office Button (it’s in the upper left corner of Word), select “Word Options”, select “Advanced” in the left pane, scroll down to the “Show document content” subsection, and uncheck the “Show picture placeholders” option. Yes, it’s that simple. Somehow, when Word crashes, this option can get turned on all by itself. It’s really annoying because there’s no clue that Word is intentionally hiding images from you; it just feels like a bug. And the reason for this insane option?

That’s right, it’s for performance. And it improves performance only at the expense of severely crippling usability. You’d think this option should never be able to get turned on accidentally, yet there it is. At least you know the solution now.

In search of stream-based desktop metaphors

Thursday, June 26th, 2008

I just ran across an excellent article comparing two competing desktop worldviews, documents and streams. The author argues that everything in our desktop environments is set up to support a document-based metaphor, when actually what is more relevant to the majority of our work these days is streams. He makes a very persuasive argument:

The prevailing UI paradigm today is built around the notion of document authoring. It expects that the main thing you do is create spreadsheets, word documents, presentations, and so on. There is a task bar to remind you of what documents you’re editing, there is cross-application cut and paste so you can put pieces of one document into another. You can place documents on your desktop surface itself, so you can organize your work. You can define which applications to use for which types of docs. You can set up a default printer to put your documents to hard copy. You can set up system-wide fonts to use in documents. You can put icons to apps and even documents onto your panel. And on and on. [...]

Really, what I mostly do today is stream management. And I suspect this is true for the vast majority of people. I don’t deal with writing documents, but with changes to documents. I put comments onto things. I slap patches onto things. I tweak the states of things. Once in a rare while I may author a completely new thingee, but even there I usually end up working with it as a stream of changes that I build up over time (and usually in collaboration with a few other people who stream changes to me).

I’m sold.

The problem is, our virtual desktops (and pretty much all OSes fail equally at this) do not support stream-centric interfaces to data. I can create discrete files just fine, even organize them into nice little directories, but what about my precious streams? I’m talking about my constantly updating server logs, the weather, stocks quotes, news, emails, instant messages, IRC messages, downloads, and more. Everything is handled separately and discordantly.

I can use an ugly hackish little program that outputs system log tails directly to my desktop. I have a Firefox plugin that tells me the current weather and a couple days’ forecasts. My investing service offers a streaming stock quote desktop application, but it only runs on Windows. Mozilla Thunderbird and Azureus pop up email notices and download completion notices, respectively. Instant messages are handled by Pidgin while incoming IRC messages are handled by X-Chat, both of which blink in my taskbar. As for the news — I can use a KDE plugin called Knewsticker that snarfs up RSS feeds. And I haven’t yet found a good way to track, say, SVN commits to the pyWikipediaBot project, so I’m stuck with getting a new email on every commit. Brilliant.

Read the rest of this entry »

How to learn Morse code in GNU/Linux

Monday, June 23rd, 2008

I know what you’re thinking — as if GNU/Linux and ham radio couldn’t possibly be nerdy enough when separate, let’s put them together! But let’s take a step back …

I started getting involved with ham radio just three months ago with VHF/UHF voice FM, and already I’m hungering for more. I don’t have an HF rig yet, and might actually not have one for awhile, but since I know it’s something I’ll want to do eventually, I figure I should just start learning Morse code now. As for why I want to learn Morse code, I couldn’t exactly tell you — there’s just a certain romance to it, and pounding away on a key is such a delightfully different method of communicating than just speaking into a microphone. But ignoring why I want to learn it, here’s how I’m going about doing it, in GNU/Linux no less.

Learning Morse code on the computer is actually harder than it should be. I couldn’t find any Flash or Java applets that do something as simple as generate Morse code. Seriously. I found some really old Java applets that no longer function in current JDKs, but they don’t count. I found lots of DOS programs, many of which are pushing two decades old, but I wasn’t having much luck with them even under Windows. And since I’m running GNU/Linux as my primary desktop now, these programs weren’t helpful at all. Luckily, there’s a simple up-to-date command-line utility for GNU/Linux that does all the basics with a minimum of fuss.

First, you’ll want the morse program. In Ubuntu or Debian GNU/Linux, you can do the following:

sudo apt-get install morse

If you’re not using Ubuntu or Debian, you should be able to find it using the package manager in your distro of choice.

Now, learning Morse is as simple as passing in the right command-line parameters to morse. Here’s what I’ve started with:

morse -rC 'ETAOINSHRDLU' -w 5 -Ts

Read the rest of this entry »

Minor hardware upgrade news

Saturday, June 21st, 2008

Having just gotten a new computer a scant two weeks ago, I’ve all ready failed at resisting the urge to start pimping it out. I should point out the whole point of this endeavor was to make a cheap computer. Well, today I added another 2 GB of RAM (at a cost of $25) and a 400 GB hard drive (transferred from another computer). I’m lucky I all ready had that hard drive laying around; otherwise, I’d be out another, what, $80?

So the total price of my “cheap” system, if you don’t have any components laying around and have to buy everything from scratch, has ballooned to over $500. And that’s not even the end of it. I thought I could get away without a discrete graphics card; well, now I’m finding out that maybe I can’t. I’ve been playing around with Compiz, the 3D desktop manager, and also gotten interested in running some 3D Windows games in Wine. So it looks like I will need better than Intel Integrated graphics after all. And with the recent news that ATI is beefing up their Linux support, it’s proving hard to resist.

I still contend it’s possible to build a decent GNU/Linux desktop computer for $300. It’s just not something I seem capable of. I have the upgrade bug. The first time I happen to examine top and notice that I’m using swap space (gah!), I’m off buying 2 GB more RAM. A similar thing happens when I fill up all my hard drives (the whole reason I added this 400 GB hard drive is because the 500 GB one the system came with is all ready full).