예제 #1
0
def test_vs_brute_force_from_file(file_name):
  print 'Testing from file', file_name
  s = 0
  with open(file_name, 'r') as f:
    f.next() # Skip n, k line
    for i, line in enumerate(f):
      _assert_results_equal(ru.to_int_list(line), s)
  print 'OK'
예제 #2
0
def three_sum_of_file(file_name, s):
  # Generates the 3SUM solutions for each array in the input file 'file_name'.
  with open(file_name, 'r') as f:
    f.next() # Skip n, k header line.
    for line in f:
      # Map 0-based to 1-based indices. Negative index (not found) are unchanged.
      result = three_sum_indices_fast(ru.to_int_list(line), s)
      yield (NOT_FOUND, ) if result is None else map(lambda x: x if x < 0 else x + 1, result)
예제 #3
0
def two_sum_of_file(file_name, s):
  with open(file_name, 'r') as f:
    f.next() # Skip n, k line
    for line in f:
      # Map 0-based to 1-based indices. Negative index (not found) are unchanged.
      yield map(lambda x: x if x < 0 else x + 1, two_sum_indices(ru.to_int_list(line), s))