Skip to content

Instantly share code, notes, and snippets.

@aymanfarhat
Last active December 21, 2015 05:28
Show Gist options
  • Save aymanfarhat/6256639 to your computer and use it in GitHub Desktop.
Save aymanfarhat/6256639 to your computer and use it in GitHub Desktop.
f = open('input.txt')
lines = f.readlines()
lines = list(map(lambda x: int(x.strip()), lines))
f.close()
d = {}
found = {}
for line in lines:
if line in d:
d[line] += 1
else:
d[line] = 1
nums = list(d.keys())
nums.sort()
left = 0
right = len(nums) - 1
count = 0
num_range = (-10000, 10000)
while left < right:
s = nums[left] + nums[right]
if s >= num_range[0] and s <= num_range[1]:
if s not in found:
count += 1
found[s] = True
left += 1
right -= 1
elif s < num_range[0]:
left += 1
else:
right -= 1
print(count)
f = open('input.txt')
lines = f.readlines()
f.close()
d = {}
for i in lines:
val = int(i.strip('\r\n'))
if d.has_key(i):
d[val] += 1
else:
d[val] = 1
res = 0
sorts = d.keys()
sorts.sort()
def sums(arr, target, d):
size = len(arr)
x = arr[:(size/2)]
y = arr[(size/2):]
the_arr = []
if target >= x[0] or target <= x[len(x)-1]:
the_arr = x
elif target >= y[0] or target <= y[len(y)-1]:
the_arr = y
else:
return False
print total
left = 0
right = len(the_arr)-1
for el in the_arr:
if d.has_key(target-el):
return True
return False
for total in xrange(-10000,10001):
print total
if sums(sorts, total, d):
res += 1
print "result: "+str(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment