09/21/09 – Challenge


A software engineer lived on a street that was numbered linearly starting at 1. She had a dog that she used to take out for walks. In the morning she would walk in one direction and in the evening she would walk in the opposite direction. On one of her walks she summed the house numbers in that direction and compared it to the sum of the house numbers in the other direction (not including her house number). To her amazemment she found that the two sums were the same. This was a unique feature of her house and she felt that she lived in a lucky house. So when she moved to another city, she asked her realtor to find her a house with exactly that same feature, i.e. the sum of house numbers on one side is equal to sum of the house numbers on the other side. Your task is to write a program that will help the real estate agent find pairs of numbers (the lucky house and the last house on the street). Assume that there cannot be more than 10,000 houses on a given street. The first set of numbers that have this property is 6 and 8.

My Solution

Note: My solution to this problem seems to work as far as I can tell, but it is slow. See if you can optimize it.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: