python_code
stringlengths
0
4.04M
repo_name
stringlengths
8
58
file_path
stringlengths
5
147
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( arr , n ) : found = False for i in range ( n - 1 ) : s = set ( ) for j in range ( i + 1 , n...
CodeGen-main
data/transcoder_evaluation_gfg/python/FIND_TRIPLETS_ARRAY_WHOSE_SUM_EQUAL_ZERO_1.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( num , divisor ) : if ( divisor == 0 ) : return False if ( divisor < 0 ) : divisor = - divis...
CodeGen-main
data/transcoder_evaluation_gfg/python/PROGRAM_TO_FIND_REMAINDER_WITHOUT_USING_MODULO_OR_OPERATOR_1.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( a , n ) : count = 0 for i in range ( 0 , n ) : for j in range ( i + 1 , n ) : if ( a [ ...
CodeGen-main
data/transcoder_evaluation_gfg/python/NUMBER_ORDERED_PAIRS_AI_AJ_0.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( mat , n , m ) : rowsum = [ 0 ] * n ; colsum = [ 0 ] * m ; for i in range ( n ) : for j in range...
CodeGen-main
data/transcoder_evaluation_gfg/python/UNIQUE_CELLS_BINARY_MATRIX.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( str ) : result = 0 for i in range ( len ( str ) ) : if ( ( i == ord ( str [ i ] ) - ord ( 'a' ) ) o...
CodeGen-main
data/transcoder_evaluation_gfg/python/COUNT_CHARACTERS_POSITION_ENGLISH_ALPHABETS.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold(arr, n): mls = [] max = 0 for i in range(n): mls.append(1) for i in range(n): for j i...
CodeGen-main
data/transcoder_evaluation_gfg/python/MAXIMUM_LENGTH_SUBSEQUENCE_DIFFERENCE_ADJACENT_ELEMENTS_EITHER_0_1.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( a , n ) : return ( ( n - 1 ) * min ( a ) ) #TOFILL if __name__ == '__main__': param = [ ([1, 2, 3, 4...
CodeGen-main
data/transcoder_evaluation_gfg/python/MINIMUM_COST_MAKE_ARRAY_SIZE_1_REMOVING_LARGER_PAIRS.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( n ) : bell = [ [ 0 for i in range ( n + 1 ) ] for j in range ( n + 1 ) ] bell [ 0 ] [ 0 ] = 1 for i in ...
CodeGen-main
data/transcoder_evaluation_gfg/python/BELL_NUMBERS_NUMBER_OF_WAYS_TO_PARTITION_A_SET.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( s , c ) : res = 0 for i in range ( len ( s ) ) : if ( s [ i ] == c ) : res = res + 1 ...
CodeGen-main
data/transcoder_evaluation_gfg/python/PROGRAM_COUNT_OCCURRENCE_GIVEN_CHARACTER_STRING.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( n ) : count = 0 for i in range ( 0 , n + 1 ) : for j in range ( 0 , n + 1 ) : for k in ...
CodeGen-main
data/transcoder_evaluation_gfg/python/BREAK_NUMBER_THREE_PARTS.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( arr , n ) : SubsetSum_1 = 0 SubsetSum_2 = 0 for i in range ( 0 , n ) : isSingleOccurance = True...
CodeGen-main
data/transcoder_evaluation_gfg/python/MAXIMUM_POSSIBLE_DIFFERENCE_TWO_SUBSETS_ARRAY.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( n ) : return 1 if ( n == 1 or n == 0 ) else n * f_gold ( n - 1 ) ; #TOFILL if __name__ == '__main__': pa...
CodeGen-main
data/transcoder_evaluation_gfg/python/C_PROGRAM_FACTORIAL_NUMBER.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( n ) : position = 1 m = 1 while ( not ( n & m ) ) : m = m << 1 position += 1 return ...
CodeGen-main
data/transcoder_evaluation_gfg/python/POSITION_OF_RIGHTMOST_SET_BIT_1.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( arr , N ) : lis = [ 0 ] * N for i in range ( N ) : lis [ i ] = 1 for i in range ( 1 , N ) : ...
CodeGen-main
data/transcoder_evaluation_gfg/python/MINIMUM_INSERTIONS_SORT_ARRAY.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( arr , n ) : arr = sorted ( arr ) diff = 10 ** 20 for i in range ( n - 1 ) : if arr [ i + 1 ] - ...
CodeGen-main
data/transcoder_evaluation_gfg/python/FIND_MINIMUM_DIFFERENCE_PAIR_1.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( arr , n ) : return sum ( arr ) - ( ( ( n - 1 ) * n ) // 2 ) #TOFILL if __name__ == '__main__': param = [...
CodeGen-main
data/transcoder_evaluation_gfg/python/FIND_REPETITIVE_ELEMENT_1_N_1.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold(arr, n, x): if n < 2: return False s = set() for i in range(0, n): if arr[i] == 0: ...
CodeGen-main
data/transcoder_evaluation_gfg/python/PAIR_WITH_GIVEN_PRODUCT_SET_1_FIND_IF_ANY_PAIR_EXISTS_1.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( ar , n ) : res = 0 ar.sort ( ) for i in range ( 0 , n ) : count = 1 for i in range ( n ...
CodeGen-main
data/transcoder_evaluation_gfg/python/MINIMUM_NUMBER_SUBSETS_DISTINCT_ELEMENTS.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( arr , n ) : max_ele = arr [ n - 1 ] min_ele = arr [ 0 ] for i in range ( n ) : if i % 2 == 0 : ...
CodeGen-main
data/transcoder_evaluation_gfg/python/REARRANGE_ARRAY_MAXIMUM_MINIMUM_FORM_SET_2_O1_EXTRA_SPACE_1.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( n ) : i = 0 ans = 0 while ( ( 1 << i ) <= n ) : k = 0 change = 1 << i for j in ...
CodeGen-main
data/transcoder_evaluation_gfg/python/COUNT_TOTAL_SET_BITS_IN_ALL_NUMBERS_FROM_1_TO_N.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( n ) : count = 0 count = ( n + 1 ) * ( n + 2 ) // 2 return count #TOFILL if __name__ == '__main__': ...
CodeGen-main
data/transcoder_evaluation_gfg/python/BREAK_NUMBER_THREE_PARTS_1.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( arr , low , high , key ) : if ( high < low ) : return - 1 mid = ( low + high ) / 2 if ( key == ...
CodeGen-main
data/transcoder_evaluation_gfg/python/SEARCH_INSERT_AND_DELETE_IN_A_SORTED_ARRAY.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( str ) : n = len ( str ) for i in range ( n ) : if ( str [ i ] != 'a' ) : break if (...
CodeGen-main
data/transcoder_evaluation_gfg/python/CHECK_STRING_FOLLOWS_ANBN_PATTERN_NOT.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( str ) : n = len ( str ) res = - 1 for i in range ( 0 , n - 1 ) : for j in range ( i + 1 , n ) :...
CodeGen-main
data/transcoder_evaluation_gfg/python/MAXIMUM_NUMBER_CHARACTERS_TWO_CHARACTER_STRING.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import math def f_gold ( n ) : nthElement = 19 + ( n - 1 ) * 9 outliersCount = int ( math.log10 ( nthElement ) ) - 1 ...
CodeGen-main
data/transcoder_evaluation_gfg/python/N_TH_NUMBER_WHOSE_SUM_OF_DIGITS_IS_TEN_2.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( mat , row , column ) : print ( "Diagonal one : " , end = "" ) for i in range ( 0 , row ) : for j in...
CodeGen-main
data/transcoder_evaluation_gfg/python/SQUARES_OF_MATRIX_DIAGONAL_ELEMENTS.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( n ) : return 1 if ( n == 1 or n == 0 ) else n * f_gold ( n - 1 ) ; #TOFILL if __name__ == '__main__': pa...
CodeGen-main
data/transcoder_evaluation_gfg/python/PROGRAM_FOR_FACTORIAL_OF_A_NUMBER.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( s ) : n = len ( s ) lps = [ 0 ] * n l = 0 i = 1 while ( i < n ) : if ( s [ i ] == s [ l...
CodeGen-main
data/transcoder_evaluation_gfg/python/LONGEST_PREFIX_ALSO_SUFFIX_1.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # from math import floor def f_gold ( a , b ) : return floor ( ( a + b ) / 2 ) #TOFILL if __name__ == '__main__': para...
CodeGen-main
data/transcoder_evaluation_gfg/python/COMPUTE_AVERAGE_TWO_NUMBERS_WITHOUT_OVERFLOW.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( arr , n , k ) : if ( n == 1 ) : return 0 arr.sort ( ) ans = arr [ n - 1 ] - arr [ 0 ] small...
CodeGen-main
data/transcoder_evaluation_gfg/python/MINIMIZE_THE_MAXIMUM_DIFFERENCE_BETWEEN_THE_HEIGHTS.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( mat , n ) : diag1_left = 0 diag1_right = 0 diag2_left = 0 diag2_right = 0 i = 0 j = n - 1 ...
CodeGen-main
data/transcoder_evaluation_gfg/python/CENTER_ELEMENT_OF_MATRIX_EQUALS_SUMS_OF_HALF_DIAGONALS.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import sys def f_gold(A, B, m, n): A.sort() B.sort() a = 0 b = 0 result = sys.maxsize while (a < m and...
CodeGen-main
data/transcoder_evaluation_gfg/python/SMALLEST_DIFFERENCE_PAIR_VALUES_TWO_UNSORTED_ARRAYS.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( arr , low , high ) : if ( high < low ) : return 0 if ( high == low ) : return low mid =...
CodeGen-main
data/transcoder_evaluation_gfg/python/FIND_ROTATION_COUNT_ROTATED_SORTED_ARRAY_1.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( arr , n , x , k ) : i = 0 while ( i < n ) : if ( arr [ i ] == x ) : return i i ...
CodeGen-main
data/transcoder_evaluation_gfg/python/SEARCHING_ARRAY_ADJACENT_DIFFER_K.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import math def f_gold ( n ) : maxPrime = - 1 while n % 2 == 0 : maxPrime = 2 n >>= 1 for i in rang...
CodeGen-main
data/transcoder_evaluation_gfg/python/FIND_LARGEST_PRIME_FACTOR_NUMBER.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( n ) : n -= 1 n |= n >> 1 n |= n >> 2 n |= n >> 4 n |= n >> 8 n |= n >> 16 n += 1 re...
CodeGen-main
data/transcoder_evaluation_gfg/python/NEXT_POWER_OF_2_2.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( n ) : count = 0 if ( n and ( not ( n & ( n - 1 ) ) ) ) : while ( n > 1 ) : n >>= 1 ...
CodeGen-main
data/transcoder_evaluation_gfg/python/FIND_WHETHER_A_GIVEN_NUMBER_IS_A_POWER_OF_4_OR_NOT_1.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( n , m ) : return ( m * n * ( n + 1 ) * ( m + 1 ) ) // 4 #TOFILL if __name__ == '__main__': param = [ ...
CodeGen-main
data/transcoder_evaluation_gfg/python/NUMBER_RECTANGLES_NM_GRID.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( n , k , x ) : dp = list ( ) dp.append ( 0 ) dp.append ( 1 ) i = 2 while i < n : dp.appe...
CodeGen-main
data/transcoder_evaluation_gfg/python/COUNT_ARRAYS_CONSECUTIVE_ELEMENT_DIFFERENT_VALUES.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( s ) : _sum = 0 n = 1 while ( _sum < s ) : _sum += n * n n += 1 n -= 1 if _sum =...
CodeGen-main
data/transcoder_evaluation_gfg/python/SQUARE_PYRAMIDAL_NUMBER_SUM_SQUARES.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( arr , n ) : res = 0 for i in range ( 0 , n - 1 ) : res = res ^ ( i + 1 ) ^ arr [ i ] res = res ...
CodeGen-main
data/transcoder_evaluation_gfg/python/FIND_REPETITIVE_ELEMENT_1_N_1_2.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( s , t ) : count = 0 for i in range ( 0 , len ( t ) ) : if ( count == len ( s ) ) : brea...
CodeGen-main
data/transcoder_evaluation_gfg/python/MAXIMUM_LENGTH_PREFIX_ONE_STRING_OCCURS_SUBSEQUENCE_ANOTHER.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( n ) : p = 1 if ( n and not ( n & ( n - 1 ) ) ) : return n while ( p < n ) : p <<= 1 ...
CodeGen-main
data/transcoder_evaluation_gfg/python/SMALLEST_POWER_OF_2_GREATER_THAN_OR_EQUAL_TO_N_1.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( arr , n ) : for i in range ( n ) : if arr [ i ] is i : return i return - 1 #TOFILL i...
CodeGen-main
data/transcoder_evaluation_gfg/python/FIND_A_FIXED_POINT_IN_A_GIVEN_ARRAY.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( arr , n ) : d1 = 0 d2 = 0 for i in range ( 0 , n ) : d1 = d1 + arr [ i ] [ i ] d2 = d2 ...
CodeGen-main
data/transcoder_evaluation_gfg/python/FIND_DIFFERENCE_BETWEEN_SUMS_OF_TWO_DIAGONALS_1.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( arr , n , k ) : dist_count = 0 for i in range ( n ) : j = 0 while j < n : if ( ...
CodeGen-main
data/transcoder_evaluation_gfg/python/K_TH_DISTINCT_OR_NON_REPEATING_ELEMENT_IN_AN_ARRAY.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( arr , n ) : for i in range ( n ) : j = 0 while ( j < n ) : if ( i != j and arr [ i ...
CodeGen-main
data/transcoder_evaluation_gfg/python/NON_REPEATING_ELEMENT.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( l , b , h ) : return ( ( l * b * h ) / 2 ) #TOFILL if __name__ == '__main__': param = [ (8448.900678...
CodeGen-main
data/transcoder_evaluation_gfg/python/PROGRAM_TO_FIND_THE_VOLUME_OF_A_TRIANGULAR_PRISM.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( a , b ) : if a == 0 : return b return f_gold ( b % a , a ) #TOFILL if __name__ == '__main__': ...
CodeGen-main
data/transcoder_evaluation_gfg/python/BASIC_AND_EXTENDED_EUCLIDEAN_ALGORITHMS.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( N , insrt , remov , cpy ) : if N == 0 : return 0 if N == 1 : return insrt dp = [ 0 ] * ...
CodeGen-main
data/transcoder_evaluation_gfg/python/MINIMUM_TIME_WRITE_CHARACTERS_USING_INSERT_DELETE_COPY_OPERATION.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( n ) : return ( 3.0 * n ) / ( 4.0 * ( n * n ) - 1 ) #TOFILL if __name__ == '__main__': param = [ (46,...
CodeGen-main
data/transcoder_evaluation_gfg/python/PROBABILITY_THREE_RANDOMLY_CHOSEN_NUMBERS_AP.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( arr , n , x ) : for i in arr : for j in arr : if i * j == x : return True ...
CodeGen-main
data/transcoder_evaluation_gfg/python/PAIR_WITH_GIVEN_PRODUCT_SET_1_FIND_IF_ANY_PAIR_EXISTS.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( n ) : sum = 0 sum = 1 << n ; return ( sum - 1 ) #TOFILL if __name__ == '__main__': param = [ ...
CodeGen-main
data/transcoder_evaluation_gfg/python/SUM_OF_ALL_ELEMENTS_UP_TO_NTH_ROW_IN_A_PASCALS_TRIANGLE_1.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import math def f_gold ( r , R , r1 , x1 , y1 ) : dis = int ( math.sqrt ( x1 * x1 + y1 * y1 ) ) return ( dis - r1 >= R ...
CodeGen-main
data/transcoder_evaluation_gfg/python/CHECK_GIVEN_CIRCLE_LIES_COMPLETELY_INSIDE_RING_FORMED_TWO_CONCENTRIC_CIRCLES.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( x ) : return ( - ( ~ x ) ) ; #TOFILL if __name__ == '__main__': param = [ (20,), (68,), (52,...
CodeGen-main
data/transcoder_evaluation_gfg/python/ADD_1_TO_A_GIVEN_NUMBER_1.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( n , k ) : dp = [ [ [ 0 , 0 ] for __ in range ( k + 1 ) ] for _ in range ( n + 1 ) ] dp [ 1 ] [ 0 ] [ 0 ] = ...
CodeGen-main
data/transcoder_evaluation_gfg/python/COUNT_BINARY_STRINGS_K_TIMES_APPEARING_ADJACENT_TWO_SET_BITS.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold(n): i = 0 j = len(n) pos = 0 while (i < j): if (n[i] == '4'): pos = pos * 2 + 1 ...
CodeGen-main
data/transcoder_evaluation_gfg/python/FIND_POSITION_GIVEN_NUMBER_AMONG_NUMBERS_MADE_4_7.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( x , y , z ) : if ( not ( y / x ) ) : return y if ( not ( y / z ) ) else z return x if ( not ( x / z...
CodeGen-main
data/transcoder_evaluation_gfg/python/SMALLEST_OF_THREE_INTEGERS_WITHOUT_COMPARISON_OPERATORS_1.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( arr , k , n ) : for c in range ( k ) : max_so_far = - float ( "inf" ) max_here = 0 star...
CodeGen-main
data/transcoder_evaluation_gfg/python/K_MAXIMUM_SUMS_NON_OVERLAPPING_CONTIGUOUS_SUB_ARRAYS.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( a , b , c ) : x = a - b y = b - c z = a - c if x * y > 0 : return b elif ( x * z > 0 ) ...
CodeGen-main
data/transcoder_evaluation_gfg/python/MIDDLE_OF_THREE_USING_MINIMUM_COMPARISONS_2.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( arr , n ) : d1 = 0 d2 = 0 for i in range ( 0 , n ) : for j in range ( 0 , n ) : if ...
CodeGen-main
data/transcoder_evaluation_gfg/python/FIND_DIFFERENCE_BETWEEN_SUMS_OF_TWO_DIAGONALS.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( arr , n ) : LIS = [ 0 for i in range ( n ) ] len = 0 for i in range ( n ) : LIS [ i ] = 1 f...
CodeGen-main
data/transcoder_evaluation_gfg/python/CONVERT_STRICTLY_INCREASING_ARRAY_MINIMUM_CHANGES.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( arr , n ) : arr.sort ( ) sum = 0 for i in range ( n ) : sum += arr [ i ] * i return sum #...
CodeGen-main
data/transcoder_evaluation_gfg/python/MAXIMIZE_SUM_ARRII.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( arr , N , k ) : MS = [ 0 for i in range ( N ) ] MS [ N - 1 ] = arr [ N - 1 ] for i in range ( N - 2 , -...
CodeGen-main
data/transcoder_evaluation_gfg/python/MAXIMUM_SUM_SUBSEQUENCE_LEAST_K_DISTANT_ELEMENTS.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( n ) : return 1 if ( n == 1 or n == 0 ) else n * f_gold ( n - 1 ) ; #TOFILL if __name__ == '__main__': pa...
CodeGen-main
data/transcoder_evaluation_gfg/python/ONE_LINE_FUNCTION_FOR_FACTORIAL_OF_A_NUMBER.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( cost , N ) : dp = [ [ 0 for i in range ( N + 1 ) ] for j in range ( N + 1 ) ] dp [ 0 ] [ 0 ] = cost [ 0 ] [...
CodeGen-main
data/transcoder_evaluation_gfg/python/PATH_MAXIMUM_AVERAGE_VALUE.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( x , y ) : while ( y != 0 ) : carry = x & y x = x ^ y y = carry << 1 return x #TOF...
CodeGen-main
data/transcoder_evaluation_gfg/python/ADD_TWO_NUMBERS_WITHOUT_USING_ARITHMETIC_OPERATORS.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( s ) : l = len ( s ) i = 0 j = l - 1 while i <= j : if ( s [ i ] != s [ j ] ) : ...
CodeGen-main
data/transcoder_evaluation_gfg/python/MINIMUM_CHARACTERS_ADDED_FRONT_MAKE_STRING_PALINDROME.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( arr , n , x ) : res = 0 for i in range ( n ) : if x == arr [ i ] : res += 1 return ...
CodeGen-main
data/transcoder_evaluation_gfg/python/COUNT_NUMBER_OF_OCCURRENCES_OR_FREQUENCY_IN_A_SORTED_ARRAY.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( arr , n ) : return max ( arr ) #TOFILL if __name__ == '__main__': param = [ ([10, 12, 14, 16, 17, 17...
CodeGen-main
data/transcoder_evaluation_gfg/python/C_PROGRAM_FIND_LARGEST_ELEMENT_ARRAY_1.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( arr , low , high ) : if high < low : return arr [ 0 ] if high == low : return arr [ low ] ...
CodeGen-main
data/transcoder_evaluation_gfg/python/FIND_MINIMUM_ELEMENT_IN_A_SORTED_AND_ROTATED_ARRAY.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( n ) : answer = [ None ] * ( n + 1 ) ; answer [ 0 ] = 1 ; i = 1 while i <= n : answer [ i ] ...
CodeGen-main
data/transcoder_evaluation_gfg/python/NUMBER_TRIANGLES_N_MOVES.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( a , b , k , n1 , n2 ) : s = set ( ) for i in range ( n2 ) : s.add ( b [ i ] ) missing = 0 f...
CodeGen-main
data/transcoder_evaluation_gfg/python/K_TH_MISSING_ELEMENT_INCREASING_SEQUENCE_NOT_PRESENT_GIVEN_SEQUENCE.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( arr , n ) : count = 0 for i in range ( n ) : if arr [ i ] != 0 : arr [ count ] = arr [ ...
CodeGen-main
data/transcoder_evaluation_gfg/python/MOVE_ZEROES_END_ARRAY.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( X , Y , l , r , k , dp ) : if k == 0 : return 0 if l < 0 or r < 0 : return 1000000000 i...
CodeGen-main
data/transcoder_evaluation_gfg/python/MINIMUM_COST_MAKE_LONGEST_COMMON_SUBSEQUENCE_LENGTH_K.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( num ) : if ( num // 10 == 0 ) : return True while ( num != 0 ) : if ( num // 10 == 0 ) : ...
CodeGen-main
data/transcoder_evaluation_gfg/python/CHECK_IF_A_NUMBER_IS_JUMBLED_OR_NOT.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( S ) : arr = [ ] arr.append ( [ '@' , - 1 ] ) maxlen = 0 for i in range ( len ( S ) ) : arr....
CodeGen-main
data/transcoder_evaluation_gfg/python/LENGTH_LONGEST_SUB_STRING_CAN_MAKE_REMOVED.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( arr , n ) : result = - 1 for i in range ( n ) : for j in range ( n - 1 ) : for k in ran...
CodeGen-main
data/transcoder_evaluation_gfg/python/FIND_PAIR_WITH_GREATEST_PRODUCT_IN_ARRAY.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( side ) : area = side * side return area #TOFILL if __name__ == '__main__': param = [ (50,), ...
CodeGen-main
data/transcoder_evaluation_gfg/python/PROGRAM_AREA_SQUARE.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( s ) : n = len ( s ) for i in range ( 1 , n ) : if s [ i ] != s [ 0 ] : return False ...
CodeGen-main
data/transcoder_evaluation_gfg/python/QUICK_WAY_CHECK_CHARACTERS_STRING.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( keypad , n ) : if ( not keypad or n <= 0 ) : return 0 if ( n == 1 ) : return 10 odd = [...
CodeGen-main
data/transcoder_evaluation_gfg/python/MOBILE_NUMERIC_KEYPAD_PROBLEM.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( n , p ) : ans = 0 temp = p while ( temp <= n ) : ans += n / temp temp = temp * p re...
CodeGen-main
data/transcoder_evaluation_gfg/python/FINDING_POWER_PRIME_NUMBER_P_N_1.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( mat , n ) : flip = 0 for i in range ( n ) : for j in range ( i ) : if mat [ i ] [ j ] !...
CodeGen-main
data/transcoder_evaluation_gfg/python/MINIMUM_FLIP_REQUIRED_MAKE_BINARY_MATRIX_SYMMETRIC_1.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( arr , n ) : l = 0 _sum = 0 ans = 360 for i in range ( n ) : _sum += arr [ i ] while...
CodeGen-main
data/transcoder_evaluation_gfg/python/PROGRAM_FIND_SMALLEST_DIFFERENCE_ANGLES_TWO_PARTS_GIVEN_CIRCLE.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( n ) : sum = 0 for i in range ( 1 , n + 1 ) : sum = sum + ( 2 * i - 1 ) * ( 2 * i - 1 ) return s...
CodeGen-main
data/transcoder_evaluation_gfg/python/SUM_SERIES_12_32_52_2N_12.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( n ) : return ( 1 + ( n * 2 ) + ( n * ( ( n * n ) - 1 ) // 2 ) ) #TOFILL if __name__ == '__main__': param...
CodeGen-main
data/transcoder_evaluation_gfg/python/COUNT_STRINGS_CAN_FORMED_USING_B_C_GIVEN_CONSTRAINTS_1.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def f_gold ( arr1 , arr2 , m , n , x ) : count = 0 for i in range ( m ) : for j in range ( n ) : if ...
CodeGen-main
data/transcoder_evaluation_gfg/python/COUNT_PAIRS_TWO_SORTED_ARRAYS_WHOSE_SUM_EQUAL_GIVEN_VALUE_X.py
# https://docs.oracle.com/cd/E19182-01/820-7851/inst_cli_jdk_javahome_t/ # JAVA_HOME = "<...>/bin/" # https://prereleases.llvm.org/5.0.1/ # LLVM_5_PATH = "<...>/bin/" # Useful for Java as JLang output is LLVM v5 # clang+llvm at https://github.com/llvm/llvm-project/releases/tag/llvmorg-13.0.0-rc2 # LLVM_13_PATH = "<....
CodeGen-main
codegen_sources/external_paths.py
CodeGen-main
codegen_sources/__init__.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import os from logging import getLogger import torch import torch.nn as nn import torch.nn.functional as F from codegen_source...
CodeGen-main
codegen_sources/wrappers/models.py
CodeGen-main
codegen_sources/wrappers/__init__.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import os from pathlib import Path from typing import List import fastBPE import torch from codegen_sources.model.src.utils im...
CodeGen-main
codegen_sources/wrappers/tokenizer.py
import os import shutil import string import subprocess import typing as tp import uuid from pathlib import Path from random import randint, choices from subprocess import Popen from .utils import ( FIREJAIL_COMMAND, MAX_VIRTUAL_MEMORY, limit_virtual_memory, _handle_timeouts, ) from ..model.src.constan...
CodeGen-main
codegen_sources/code_runners/code_runner.py
# utils from .utils import compile_go as compile_go from .utils import compile_rust as compile_rust from .runner_errors import CompilationError as CompilationError from .runner_errors import Timeout as Timeout
CodeGen-main
codegen_sources/code_runners/__init__.py
import os import sys import typing as tp from pathlib import Path from .code_runner import CodeRunner, DEFAULT_TESTS_PATH PYTHON_ENV = os.environ.copy() PYTHON_ENV["PATH"] = f"{sys.executable.rstrip('python')}:{PYTHON_ENV['PATH']}" class PythonCodeRunner(CodeRunner): def __init__( self, tmp_fold...
CodeGen-main
codegen_sources/code_runners/python_code_runner.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # class CompilationError(Exception): pass class TestRuntimeError(Exception): pass class MissingTest(Exception): ...
CodeGen-main
codegen_sources/code_runners/runner_errors.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import os import pathlib import signal import subprocess import typing as tp from pathlib import Path from .runner_errors impor...
CodeGen-main
codegen_sources/code_runners/utils.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import typing as tp from pathlib import Path from ..runner_errors import ( TestRuntimeError, CompilationError, Inva...
CodeGen-main
codegen_sources/code_runners/test_runners/unittest_runner.py
from .evosuite_test_runners.cpp_evosuite_test_runner import ( CppEvosuiteTestRunner as CppEvosuiteTestRunner, ) from .evosuite_test_runners.python_evosuite_test_runner import ( PythonEvosuiteTestRunner as PythonEvosuiteTestRunner, ) from .input_output_runners.cpp_input_output_evaluator import ( CppInputOutp...
CodeGen-main
codegen_sources/code_runners/test_runners/__init__.py
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # from pathlib import Path from .input_output_evaluator import InputOutputEvaluator from ...code_runner import RUN_ROOT_DIR from ...
CodeGen-main
codegen_sources/code_runners/test_runners/input_output_runners/rust_input_output_evaluator.py