Created
July 6, 2013 20:12
-
-
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!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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