def generate_example(): len = random.randint(1, 10) * 2 array = gen_utils.randomintarray(len) array2 = gen_utils.randomintarray(len) min_so_far_array = [] min_so_far = 1 for i in range(len): min_so_far = min_so_far if (min_so_far < array[i]) else 1 min_so_far_array.append(min_so_far) # Now, compute the max of the two max_of_min_so_far_and_other_array = [] for i in range(len): m1 = min_so_far_array[i] m2 = array2[i] max = m1 if (m1 > m2) else m2 max_of_min_so_far_and_other_array.append(max) result = [] for i in range(len): result.append(min_so_far_array[i] - max_of_min_so_far_and_other_array[i]) return (array, array2, result)
def generate_example(): array_len_1 = random.randint(1, 30) array_len_2 = random.randint(1, 30) arr1 = sorted(gen_utils.randomintarray(array_len_1)) arr2 = sorted(gen_utils.randomintarray(array_len_2)) outarr = sorted(arr1 + arr2) return (arr1, arr2, outarr)
def generate_example(): len = random.randint(1, 10) * 2 arr1 = gen_utils.randomintarray(len, max=1) arr2 = gen_utils.randomintarray(len, max=1) sum = 0 for i in range(0, len): sum += (arr1[i] + arr2[i]) * arr1[i] return (arr1, arr2, sum)
def generate_example(): len = random.randint(1, 6) array = gen_utils.randomintarray(len, min=1, max=5) array2 = gen_utils.randomintarray(len, min=1, max=5) sum = 0 for i in range(len): sum += array2[i] * (array[i] // 3) return (array, array2, sum)
def generate_example(): arrlen = random.randint(1, 20) array = gen_utils.randomintarray(arrlen) other_array = gen_utils.randomintarray(arrlen, min=1) n_arr = [] for i in range(len(array)): n_arr.append(array[i] + other_array[i]) return (array, other_array, n_arr)
def generate_example(): len = random.randint(1, 10) * 2 array = gen_utils.randomintarray(len) array2 = gen_utils.randomintarray(len) out = [] for i in range(len): x = array[i] - array2[i] if (x % 2 == 0): out.append(x * array2[i]) return (array, array2, out)
def generate_example(): N = random.randint(2, 5) M = random.randint(2, 5) arr1 = gen_utils.randomintarray(N * M) arr2 = gen_utils.randomintarray(N * M) newarr = [0] * (N * M) for i in range(N * M): newarr[i] = arr1[i] - arr2[i] return (arr1, arr2, N, M, newarr)
def generate_example(): array_len = random.randint(1, 4) arr1 = gen_utils.randomintarray(array_len, min=-3, max=3) arr2 = gen_utils.randomintarray(array_len, min=-3, max=3) res = 0 for i in range(array_len): res += arr1[i] * arr2[i] return (arr1, arr2, res)
def generate_example(): N = int(random.randint(2, 5)) alpha = int(random.randint(-5, 5)) out = [0] * N x = gen_utils.randomintarray(N) y = gen_utils.randomintarray(N) for i in range(N): out[i] = alpha * x[i] + (1 - alpha) * y[i] return (x, y, alpha, N, out)
def generate_example(): N = int(random.randint(2, 20)) inarr = gen_utils.randomintarray(N, min=-5, max=5) outarr = [0] * N coeffs = gen_utils.randomintarray(N, min=-5, max=5) for n in range(N): outarr[n] = 0 for i in range(0, N - 1): outarr[n] += coeffs[i] * inarr[N - 1 - i] return (inarr, coeffs, N, outarr)
def generate_example(): array_len = random.randint(1, 30) arr1 = gen_utils.randomintarray(array_len) arr2 = gen_utils.randomintarray(array_len) are_equal = random.randint(0, 1) if are_equal == 1 or arr1 == arr2: res = 1 return (arr1, arr1, res) else: res = 0 return (arr1, arr2, res)
def generate_example(): M = int(random.randint(2, 5)) N = int(random.randint(2, 5)) a = [0] * (M * N) x = gen_utils.randomintarray(M) y = gen_utils.randomintarray(N) for i in range(M): for j in range(N): a[j + i * N] = x[i] * y[j] return (M, N, x, y, a)
def generate_example(): array_len = random.randint(1, 30) arr = gen_utils.randomintarray(array_len, min=1) output = gen_utils.randomintarray(array_len) output_orig = output[:] size = 0 for e in arr: size += e for i in range(len(output)): output[i] = (100 * output[i]) // size return (arr, output_orig, output)
def generate_example(): len = random.randint(1, 10) * 2 array = gen_utils.randomintarray(len) array2 = gen_utils.randomintarray(len) result = [] for i in range(len): e1 = array[i] e1_rev = array[len - i - 1] e2 = array2[i] result.append(e1 - (e1_rev if (e1_rev < e2) else e2)) return (array, array2, result)
def generate_example(): len = random.randint(1, 10) * 2 array = gen_utils.randomintarray(len) array2 = gen_utils.randomintarray(len) result = [0] * len outindex = 0 for i in range(len): if array[i] > 0: m = max(array[i], array2[i]) result[outindex] = array[i] + m outindex += 1 return (array, array2, result)
def generate_example(): n = random.randint(2, 5) m = random.randint(2, 5) p = random.randint(2, 5) matA = gen_utils.randomintarray(m * n, min=0, max=4) matB = gen_utils.randomintarray(n * p, min=0, max=4) matC = [0] * (m * p) for i in range(m): for j in range(p): for k in range(n): matC[p * i + j] += matA[n * i + k] + matB[p * k + j] return (matA, matB, m, n, p, matC)
def generate_example(): M = int(random.randint(2, 5)) N = int(random.randint(2, 5)) a = gen_utils.randomintarray(N * M, min=-3, max=3) x = gen_utils.randomintarray(N, min=-3, max=3) y = [0] * M for i in range(M): sum = 0 for j in range(N): sum += a[j + i * N] * x[j] y[i] = sum return (M, N, a, x, y)
def generate_example(): len = random.randint(1, 10) * 2 array = gen_utils.randomintarray(len) array2 = gen_utils.randomintarray(len) diff_so_far = 10000 for i in range(len): diff = array[i] - array2[i] if diff < diff_so_far: diff_so_far = diff out = [] for i in range(len): out.append(array[i] - diff_so__far) return (array, array2, out)
def generate_example(): array_len = random.randint(1, 30) arr1 = gen_utils.randomintarray(array_len, min=0, max=100) arr2 = gen_utils.randomintarray(array_len, min=0, max=100) are_equal = random.randint(0, 1) if are_equal == 1: eq_index = random.randint(0, array_len - 1) arr2[eq_index] = arr1[eq_index] else: for i in range(array_len): if arr1[i] == arr2[i]: arr2[i] = arr2[i] + 1 return (arr1, arr2, 1 - are_equal)
def generate_example(): array_len = random.randint(1, 30) arr1 = gen_utils.randomintarray(array_len) res = [x for x in arr1 if x % 2 == 0] return (arr1, res)
def generate_example(): len = random.randint(1, 20) array = gen_utils.randomintarray(len) out_arr = [0] * len for i in range(len): out_arr[i] = array[0] return (array, out_arr)
def generate_example(): array_len_1 = random.randint(1, 30) array_len_2 = random.randint(1, 30) inp = gen_utils.randomintarray(array_len_1) outp = sorted(inp) return (inp, outp)
def generate_example(): array_len = random.randint(1, 3) arr = gen_utils.randomintarray(array_len, min=1, max=3) len = 0 for e in arr: len += e * e return (arr, len)
def generate_example(): len = random.randint(1, 20) array = gen_utils.randomintarray(len, min=-100, max=100) min = 1000000 for i in range(len): if array[i] < min: min = array[i] return (array, min)
def generate_example(): len = random.randint(1, 20) array = gen_utils.randomintarray(len, min=-40, max=40) max = -1000000 for i in range(len): if array[i] > max: max = array[i] return (array, max)
def generate_example(): array_len = random.randint(1, 3) arr = gen_utils.randomintarray(array_len, max=5) len = 0 for e in arr: len += e * e return (arr, int(math.sqrt(len)))
def generate_example(): len = random.randint(1, 20) array = gen_utils.randomintarray(len, min=0, max=3) idx = 0 for i in range(len): if array[i] == 0: idx = i return (array, idx)
def generate_example(): len = random.randint(1, 20) array = gen_utils.randomintarray(len) count = 0 for i in array: if i % 2 == 1: count += 1 return (array, count)
def generate_example(): arrlen = random.randint(1, 20) array = gen_utils.randomintarray(arrlen) divnum = random.randint(1, 20) n_arr = [] for i in range(len(array)): n_arr.append(array[i] // divnum) return (array, divnum, n_arr)
def generate_example(): length = random.randint(1, 10) array = gen_utils.randomintarray(length, min=-4, max=4) res = 1 for i in range(length): res *= array[i] res *= array[i] return (array, res)