Skip to content

Instantly share code, notes, and snippets.

@Caleb2501
Created July 6, 2013 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Caleb2501/5941115 to your computer and use it in GitHub Desktop.
Save Caleb2501/5941115 to your computer and use it in GitHub Desktop.
I completed this challenge 28, but the code takes way too long to process with a range of a million digits from 1 to a million. If you limit either the amount of digits or the range pool then it runs quickly enough. fun times!
# The array duplicates problem is when one integer is in an array for more than once.
# If you are given an array with integers between 1 and 1,000,000 or in some other interval
# and one integer is in the array twice. How can you determine which one?
import random
print "Creating a list of random numbers from 1 to 1,000,000."
numSet = []
for i in range(1, 1000000):
numSet.append(random.randint(1, 100))
checkList = []
checkDouble = []
for i in numSet:
if i in checkList:
if i in checkDouble:
continue
checkDouble.append(i)
print "%d is located at these positions in the array:" % (i)
for n in (n for n,x in enumerate(numSet) if x == i):
print n
else:
checkList.append(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment