Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

95% of /prog/ can't write this simple program

Name: Anonymous 2008-05-12 15:10

You are given an array of 1001 integers. The integers are in random order, but you know each of the integers is between 1 and 1000 (inclusive). Each number appears only once in the array, except for one number, which occurs twice. Assume that you can access each element of the array only once.

Task: In your language of choice, write an function to find the repeated number without using auxiliary storage.

Name: Anonymous 2008-05-12 15:14

Easy - sum them, then subtract 500500 (the sum of the integers from 1 to 1000) from that sum. This will be the missing number.

Name: Anonymous 2008-05-12 15:14

Fucking morons

I would add them all together and use the sum of the numbers 1-1000 (easily found) and compare.

GTFO THIS IS /PROG/

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List