Problem:

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.

### Like this:

Like Loading...

*Related*

This entry was posted on 09/25/2009 at 22:14 and is filed under Classwork. You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.

## Leave a Reply