AI Cheating

Revision en1, by generaleoley, 2021-07-14 05:13:38

I recently got access to Github's Copilot and it struck me that it could generate a lot of algorithms that someone might not know or even solve some of the simpler problems with ease. Despite this technology being very new, I think it's worth adding a rule restricting or prohibiting the use of certain AI code completers. From what I'm seeing in the development of this field, it's only a matter of years before someone trains an AI that can perform in coding contests at a LGM level.

Examples to demonstrate the power of Copilot:

  1. A very classical finding the maximum subarray of an array. (Kadane's Algorithm)

What was given: ~~~~~ nums = [6, 7, -2, 4, -4, 6, 12, 5]

find max subarray


What was generated:

max_sum = float('-inf') current_sum = 0 for i in range(len(nums)): current_sum += nums[i] if current_sum > max_sum: max_sum = current_sum if current_sum < 0: current_sum = 0

print(max_sum) ~~~~~

  1. Find 2 elements in an array that equal to N (2 Pointers) What was given: ~~~~~ nums = [6, 7, -2, 4, -4, 6, 12, 5]

Find a pair of numbers that sum to n.


What was generated (1st solution):

def pair_sum(nums, n): seen = set() output = set() for num in nums: target = n — num if target not in seen: seen.add(num) else: output.add((min(num, target), max(num, target))) return len(output)


Second Solution (brute force)

def find_pair(nums, n): for i in range(len(nums)): for j in range(i + 1, len(nums)): if nums[i] + nums[j] == n: return nums[i], nums[j] return None ~~~~~

  1. Coin Change
coins = [1, 2, 4, 5, 9, 69, 420]

# minimum number of coins needed to make n cents
# dynamic programming

def minCoins(n):
	if n < 0:
		return 0
	elif n in coins:
		return 1
	else:
		return 1 + min(minCoins(n-i) for i in coins if i <= n)

=======

def min_coins(cents):
        for cents in range(1, cents+1):
                for coin in coins:
                        if coin <= cents:
                                num_coins[cents] = min(num_coins[cents], num_coins[cents-coin] + 1)
        return num_coins[cents]

=======

def coin(n):
        coin_count = [0] * (n+1)
        coin_count[0] = 0
        for coin in coins:
                for i in range(coin, n+1):
                        coin_count[i] += coin_count[i-coin]
        return coin_count[n]

=======

def min_coins(n):
        table = [0] + [10000] * n
        for i in range(1, n + 1):
                for j in coins:
                        if i >= j and table[i - j] + 1 < table[i]:
                                table[i] = table[i - j] + 1
        return table[n]
Tags cheating

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English generaleoley 2021-07-15 08:39:13 239
en2 English generaleoley 2021-07-15 06:46:00 1300 Tiny change: 'ge code)\n~~~~~\n\' -> 'ge code)\n\n~~~~~\n\' (published)
en1 English generaleoley 2021-07-14 05:13:38 2904 Initial revision (saved to drafts)