File size: 20,098 Bytes
007405f
 
 
 
 
fed9c8f
007405f
 
 
fed9c8f
 
 
 
 
 
007405f
fed9c8f
 
 
 
 
007405f
fed9c8f
007405f
fed9c8f
 
 
 
 
f6d6467
fed9c8f
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{"assignment_id":"square_perimeter","func_name":"square_perimeter","reference_solution":"def square_perimeter(side):\n    return 4 * side\n    \n\n","description":"Returns the perimeter of a square.","test":"assert square_perimeter(0)==0 and square_perimeter(-12684)==-50736"}
{"assignment_id":"circle_area","func_name":"circle_area","reference_solution":"def circle_area(r):\n    return  r * r * 3.14\n    \n\n","description":"Return the area of a circle.","test":"assert circle_area(0)==0.0 and circle_area(-1160877629)==4.231579770269758e+18"}
{"assignment_id":"circle_circumference","func_name":"circle_circumference","reference_solution":"def circle_circumference(r):\n    return r * 2 * 3.14\n    \n\n","description":"Return the circumference of a circle.","test":"assert circle_circumference(0)==0.0 and circle_circumference(25619)==160887.32"}
{"assignment_id":"rectangle_perimeter","func_name":"rectangle_perimeter","reference_solution":"def rectangle_perimeter(l, w):\n    return 2 * (l + w)\n   \n\n\n","description":"Return the perimeter of a rectangle with the given coordinates.","test":"assert rectangle_perimeter(0,0)==0 and rectangle_perimeter(7968917888512863576,-18677)==15937835777025689798"}
{"assignment_id":"square_area","func_name":"square_area","reference_solution":"def square_area(l):\n   return l * l \n\n","description":"Return the area of a square.","test":"assert square_area(0)==0 and square_area(21138)==446815044"}
{"assignment_id":"reverse_iter","func_name":"reverse","reference_solution":"def reverse(a):\n   b=[]\n   i=0\n   while i < len(a):\n      b.append(a[len(a)-1-i])\n      i = i + 1\n   return b","description":"Iteratively reverse a list of elements.","test":"assert reverse([])==[] and reverse([20, 10, 0, -10, -20])==[-20, -10, 0, 10, 20] and reverse(['toto', True, [10, 0, 9], 12.8, 6])==[6, 12.8, [10, 0, 9], True, 'toto']"}
{"assignment_id":"area","func_name":"area","reference_solution":"def area (a):\n\tx= 3.141 *a**2\n\treturn x\n","description":"Return the area of a circle with the given coordinates.","test":"assert area(0)==0.0 and area(-14329)==644910876.981"}
{"assignment_id":"circumference","func_name":"circumference","reference_solution":"def circumference(r):\n\ty=3.141 * 2 *r\n\treturn y\n","description":"Return the circumference of a circle.","test":"assert circumference(0)==0.0 and circumference(-23091)==-145057.662"}
{"assignment_id":"double","func_name":"double","reference_solution":"def double(n):\n\ty=2*n\n\treturn y\n\n","description":"Double a number or a string.","test":"assert double(0)==0 and double(-7601)==-15202"}
{"assignment_id":"selection_sort","func_name":"selection_sort","reference_solution":"def selection_sort(a):\n\ti=0\n\twhile i<len(a):\n\t\tp=i\n\t\tj=i+1\n\t\twhile j < len(a):\n\t\t\tif a[j] < a[p] :\n\t\t\t\tp=j\n\t\t\tj=j+1\n\t\ttmp=a[p]\n\t\ta[p]=a[i]\n\t\ta[i]=tmp\n\t\ti=i+1\n\treturn a\n\n","description":"Sort a list by repeatedly move minimimum of remaining sublist to front.","test":"assert selection_sort([])==[] and selection_sort([0])==[0] and selection_sort([25204, -1, -18176])==[-18176, -1, 25204] and selection_sort([-18176, -1, 25204])==[-18176, -1, 25204]"}
{"assignment_id":"reverse_by_swap","func_name":"reverse","reference_solution":"def reverse(a):\n   b=[]\n   i=0\n   while i < len(a):\n      b.append(a[len(a)-1-i])\n      i = i + 1\n   return b","description":"Reverse a list of elements by swapping its elements.","test":"assert reverse([])==[] and reverse([0])==[0] and reverse([-103, 1867157052, 10933, -70, 31758, 113466788817036974729578468346735566318, 1867157052])==[1867157052, 113466788817036974729578468346735566318, 31758, -70, 10933, 1867157052, -103] and reverse([-103, 113466788817036974729578468346735566318, 31758, 1867157052, 10933, -70, 1867157052])==[1867157052, -70, 10933, 1867157052, 31758, 113466788817036974729578468346735566318, -103] and reverse([1867157052, 1867157052, 10933, -70, 31758, 113466788817036974729578468346735566318, -103])==[-103, 113466788817036974729578468346735566318, 31758, -70, 10933, 1867157052, 1867157052] and reverse([1867157052, 113466788817036974729578468346735566318, 31758, -70, 10933, 1867157052, -103])==[-103, 1867157052, 10933, -70, 31758, 113466788817036974729578468346735566318, 1867157052] and reverse([-103, 113466788817036974729578468346735566318, 31758, -70, 10933, 1867157052, 1867157052])==[1867157052, 1867157052, 10933, -70, 31758, 113466788817036974729578468346735566318, -103] and reverse([[1]])==[[1]]"}
{"assignment_id":"bsearch","func_name":"bsearch","reference_solution":"def bsearch(a, q):\n        low = 0\n        high = len(a)\n        while low < high:\n            mid = (low + high) \/\/ 2\n            if a[mid] < q:\n                low = mid + 1\n            else:\n                high = mid\n        return low","description":"Search for element q in the sorted array a.","test":"assert bsearch([],12)==0 and bsearch([1, 2, 3, 4, 6, 7, 8],5)==4 and bsearch([1, 2, 3, 4, 6, 7, 8],1)==0 and bsearch([1, 2, 3, 4, 6, 7, 8],4)==3"}
{"assignment_id":"count_letters","func_name":"count_letters","reference_solution":"def count_letters(s):\n    if not s:\n        return 0\n    return 1 + count_letters(s[1:])\n","description":"Return the number of lettres in a string.","test":"assert count_letters('')==0 and count_letters('0')==1 and count_letters('##')==2 and count_letters('t')==1 and count_letters('fqfseqfseqsse')==13"}
{"assignment_id":"maximum","func_name":"maximum","reference_solution":"def maximum(l):\n    if len(l) == 1:\n        return l[0]\n    tail_max = maximum(l[1:])\n    return l[0] if l[0] > tail_max else tail_max\n    # Could do this but ought not use max I suppose...\n    # return max(l[0], maximum(l[1:]))\n","description":"Return the maximum element in a list of numbers.","test":"assert maximum([0])==0 and maximum([67, 1, 2, -2, 0])==67 and maximum([0, -2, 2, 1, 67])==67 and maximum([-10, -23, -45, -9, -45617])==-9"}
{"assignment_id":"minimum","func_name":"minimum","reference_solution":"def minimum(l):\n    if len(l) == 1:\n        return l[0]\n    tail_min = minimum(l[1:])\n    return l[0] if l[0] < tail_min else tail_min\n    # Could do this but ought not use min I suppose...\n    # return min(l[0], rmin(l[1:]))\n","description":"Return the minimum element in a list of numbers.","test":"assert minimum([0])==0 and minimum([2, 10, 23, 9, 187])==2 and minimum([-2, -26, 7, -123, -1236521])==-1236521 and minimum([3896, 3673, 45, 16715, 23673])==45"}
{"assignment_id":"power","func_name":"power","reference_solution":"def power(m, n):\n    if not n:\n        return 1\n    return m * power(m, n-1)\n","description":"Raise m to the power of n.","test":"assert power(0,0)==1 and power(62,4)==14776336 and power(-14012,0)==1"}
{"assignment_id":"reverse_recur","func_name":"reverse_list","reference_solution":"def reverse_list(l):\n    if l == []:\n        return []\n    return reverse_list(l[1:]) + [l[0]]\n    # temp = reverse(l[1:])\n    # temp.append(l[0])\n    # return temp\n    # note we cannot use return reverse(l[1:]).append(l[0]) because append()\n    # does not return anything\n","description":"Recursively reverse a list of elements.","test":"assert reverse_list([])==[] and reverse_list([0])==[0] and reverse_list([9650, 12103, -1947378123, -109345868112896702250879906349988323457, 85, -74, -10050, 787, -3])==[-3, 787, -10050, -74, 85, -109345868112896702250879906349988323457, -1947378123, 12103, 9650] and reverse_list([9650, 12103, -1947378123, -109345868112896702250879906349988323457])==[-109345868112896702250879906349988323457, -1947378123, 12103, 9650] and reverse_list([0, 0])==[0, 0] and reverse_list([85, -74, -10050, 787, 9650, 12103, -1947378123, -109345868112896702250879906349988323457, -3])==[-3, -109345868112896702250879906349988323457, -1947378123, 12103, 9650, 787, -10050, -74, 85] and reverse_list([85, -74, -10050, 787, -3, 9650, 12103, -1947378123, -109345868112896702250879906349988323457])==[-109345868112896702250879906349988323457, -1947378123, 12103, 9650, -3, 787, -10050, -74, 85]"}
{"assignment_id":"sort","func_name":"sort","reference_solution":"def swap(a, i, j):\n   tmp  = a[i]\n   a[i] = a[j]\n   a[j] = tmp\n\n\ndef find_position_of_smallest(a, i):\n p = i  \n while i < len(a):\n    if a[i]  < a[p]:\n       p = i\n    i = i + 1\n return p\t\n   \n\ndef sort(a):\n   i = 0\n   while i < len(a):\n      p = find_position_of_smallest(a,i)       \n      swap(a, i, p)\n      i = i + 1\n","description":"Sort a list by repeatedly moving the minimimum of the remaining sublist to the front.","test":"assert sort([0])==None and sort([0])==None and sort([])==None and sort([])==None and sort([' '])==None and sort([' '])==None and sort([70, 339305549])==None and sort([70, 339305549])==None"}
{"assignment_id":"union","func_name":"union","reference_solution":"def union(a, b):\n\tc=[]\n\ti = 0\n\twhile i < len(a):\n\t\tif a[i] not in c:\n\t\t\tc.append(a[i])\n\t\ti = i + 1\n\n\tp = 0\n\twhile p < len(b):\n\t\tif b[p] not in c:\n\t\t\tc.append(b[p])\n\t\tp = p + 1\n\n\treturn c\n\n","description":"Merge two lists into a single one.","test":"assert union([],[])==[] and union([25785],[25785])==[25785] and union([-90, 21135, 29310, -8059, 7114, -90, -5808, 1333, -18691, 7, -19450, 67745575129021321678860432754396203799, -9288, -161403197171354040520992237328119268342, 49, 120528818203287557, 133011337445419463191476642795673848676, 11952, 11996],[5, -9316, 7379237229304681733])==[-90, 21135, 29310, -8059, 7114, -5808, 1333, -18691, 7, -19450, 67745575129021321678860432754396203799, -9288, -161403197171354040520992237328119268342, 49, 120528818203287557, 133011337445419463191476642795673848676, 11952, 11996, 5, -9316, 7379237229304681733]"}
{"assignment_id":"intersection","func_name":"intersection","reference_solution":"def intersection(a, b):\n\td=[]\n\ti = 0\n\twhile i < len(a):\n\t\tif a[i] in b and a[i] not in d:\n\t\t\td.append(a[i])\n\t\ti = i + 1\n\n\treturn d","description":"Return the intersection between two lists.","test":"assert intersection([],[])==[] and intersection([20052, 20052, -9991],[102, 20052, -9991])==[20052, -9991] and intersection([38908273694008580353068229963801163341, 59, 38908273694008580353068229963801163341, -38, 28239, -2723, 24559, -5794],[38908273694008580353068229963801163341, 59, 38908273694008580353068229963801163341, -38, 28239, -2723, 24559, -5794])==[38908273694008580353068229963801163341, 59, -38, 28239, -2723, 24559, -5794]"}
{"assignment_id":"swap_keys_values","func_name":"swap_keys_values","reference_solution":"def swap_keys_values(d):\n    return dict([(v, k) for (k, v) in list(d.items())])\n","description":"Swap the keys of a dictionary with its values.","test":"assert swap_keys_values({})=={} and swap_keys_values({'1': 'a'})=={'a': '1'} and swap_keys_values({'1': 'a', '2': 'b', '3': 'c', '4': 'd'})=={'a': '1', 'b': '2', 'c': '3', 'd': '4'} and swap_keys_values({'1': 'a', '2': 'b', '3': 'a'})=={'a': '3', 'b': '2'}"}
{"assignment_id":"swap_unique_keys_values","func_name":"swap_unique_keys_values","reference_solution":"def swap_unique_keys_values(d):\n    # Have to explicitly convert dict_view type to list type in Python 3\n    return dict([(v, k) for (k, v) in list(d.items()) if list(d.values()).count(v) == 1])\n","description":"Swap the keys of a dictionary with its unique values.","test":"assert swap_unique_keys_values({})=={} and swap_unique_keys_values({'1': 'a'})=={'a': '1'} and swap_unique_keys_values({'1': 'a', '2': 'b', '3': 'c', '4': 'd'})=={'a': '1', 'b': '2', 'c': '3', 'd': '4'} and swap_unique_keys_values({'1': 'a', '2': 'b', '3': 'a'})=={'b': '2'}"}
{"assignment_id":"merge_lists","func_name":"merge_lists","reference_solution":"def merge_lists(l1,l2):\n  '''take two lists l1 and l2 and return a third list which contains \n  every second element of l1 and l2'''\n  l3 = []\n  i = 0\n  while i < len(l1):\n      l3.append(l1[i])\n      i += 2\n  i = 0\n  while i < len(l2):\n      l3.append(l2[i])\n      i += 2\n  return l3\n\n","description":"Take two lists l1 and l2 and return a third list which contains every second element of l1 and l2.","test":"assert merge_lists([],[])==[] and merge_lists([],[1, 2, 3, 4])==[1, 3] and merge_lists([1, 2, 3, 4],[])==[1, 3] and merge_lists([10, 20, 45, 2, -10987, 89165],[9, 0, -6754, 5625264, 8765])==[10, 45, -10987, 9, -6754, 8765]"}
{"assignment_id":"weird_case","func_name":"weird_case","reference_solution":"def weird_case(some_str):\n    '''takes a string some_str and contains a new string which contains \nevery second letter in some_str'''\n    new_str = \"\"\n    i = 0\n    lc = 0 # separate count for the letters\n    while i < len(some_str):\n        if some_str[i].isalpha():\n            if lc % 2 == 0:\n                new_str += some_str[i].upper()\n            else:\n                new_str += some_str[i].lower()\n            lc += 1\n        else:\n          new_str += some_str[i]\n        i = i + 1\n    return new_str\n\n","description":"Takes a string some_str and contains a new string which is the same as some_str but the case alternates between upper and lower.","test":"assert weird_case('au0x6')==Au0X6 and weird_case('F:BnJ')==F:bNj"}
{"assignment_id":"remove_zeros","func_name":"remove_zeros","reference_solution":"def remove_zeros(list):\n    '''take a list of numbers and remove zeros from the list'''\n    while 0 in list:\n        list.remove(0)\n\n","description":"Take a list of numbers and removes the zeros from it.","test":"assert remove_zeros([])==None and remove_zeros([])==None and remove_zeros([5202, -24344, -6528])==None and remove_zeros([5202, -24344, -6528])==None"}
{"assignment_id":"overlap","func_name":"overlap","reference_solution":"def overlap(x1=0, y1=0, r1=1, x2=0, y2=0, r2=1):\n    d = ((x2-x1)**2 + (y2-y1)**2)**0.5\n    if d < r1 + r2:\n        return True\n    return False\n\n","description":"Test if two circles overlap.","test":"assert overlap(12,-6058,21436,-3483096651887624530,24,31017)==False and overlap(-30592,-26624,-11905,1,2,30134)==False and overlap(0,0,0,0,0,0)==False and overlap(5128,-8635,-28938,25,-31295,-21637807133189218411179185993653430151)==False and overlap(-16348,-2218,2871,-15155,-83,24475)==True and overlap(4807,1216206119,8753907074291481720,-19844,-26061,-15639)==True and overlap(1348593950,19232,-10923,20,2259187900768772679,-5343103208648864320)==False and overlap(8410739119977124611,9995,83,8410739119977124611,19348,21604)==True"}
{"assignment_id":"append2list","func_name":"append2list","reference_solution":"def append2list(l1, l2=None):\n    if l2 == None:\n        l2 = []\n    for i in l1:\n        l2.append(i)\n    return l2\n\n","description":"Appends elements of a list l1 at the end of the list l2. If l2 not supplied default to empty list.","test":"assert append2list([-12248, -4743, -25, -6030600119498841921, -8866],[-16276, 117, -12248, -4743, -25, -6030600119498841921, -8866])==[-16276, 117, -12248, -4743, -25, -6030600119498841921, -8866, -12248, -4743, -25, -6030600119498841921, -8866] and append2list([-12248, -4743, -25, -6030600119498841921, -8866],[-16276, 117, -12248, -4743, -25, -6030600119498841921, -8866, -12248, -4743, -25, -6030600119498841921, -8866])==[-16276, 117, -12248, -4743, -25, -6030600119498841921, -8866, -12248, -4743, -25, -6030600119498841921, -8866, -12248, -4743, -25, -6030600119498841921, -8866] and append2list([-12248, -4743, -25, -6030600119498841921, -8866, -16276, 117, -12248, -4743, -25, -6030600119498841921, -8866, -12248, -4743, -25, -6030600119498841921, -8866],[-16276, 117, -12248, -4743, -25, -6030600119498841921, -8866, -12248, -4743, -25, -6030600119498841921, -8866])==[-16276, 117, -12248, -4743, -25, -6030600119498841921, -8866, -12248, -4743, -25, -6030600119498841921, -8866, -12248, -4743, -25, -6030600119498841921, -8866, -16276, 117, -12248, -4743, -25, -6030600119498841921, -8866, -12248, -4743, -25, -6030600119498841921, -8866] and append2list([-21267],[-21267, -21267])==[-21267, -21267, -21267]"}
{"assignment_id":"search_iter","func_name":"search","reference_solution":"def search(str,letter):\n  '''returns True if letter is in str, False if it is not there'''\n  i = 0\n  while i < len(str):\n    if letter == str[i]:\n      return True\n    i = i + 1\n  return False\n\n","description":"Iteratively search for a letter in a string","test":"assert search('','0')==False and search('0','0')==True and search('ERFE0Rfsef','0')==True and search('ERFERfsef0','0')==True and search('','a')==False and search('cbzeycuzbvyzuvb','a')==False and search('cbsducsvdbcyts','c')==True and search('dbzeducvbzy','y')==True and search('xqvsgxcutvy','u')==True"}
{"assignment_id":"index_iter","func_name":"index","reference_solution":"def index(str,letter):\n  '''returns the position of letter in str, -1 if it is not there'''\n  i = 0\n  while i < len(str):\n    if letter == str[i]:\n      return i\n    i = i + 1\n  return -1\n\n\n","description":"Iteratively search for the position of letter in str, return -1 if it is not there.","test":"assert index('','0')==-1 and index('0','0')==0 and index('11','1')==0"}
{"assignment_id":"fibonacci_iter","func_name":"fibonacci","reference_solution":"def fibonacci(n):\n  '''returns the value of the fibonacci series at position n'''\n  if n == 0:\n    return 0\n  if n == 1:\n    return 1\n  else:\n    fibN_2 = 0\n    fibN_1 = 1\n    i = 2\n    while i <=n:\n      fibN = fibN_2 + fibN_1\n      fibN_2 = fibN_1\n      fibN_1 = fibN\n      i = i + 1\n    return fibN\n\n","description":"Iteratively compute the value of the fibonacci series at position n.","test":"assert fibonacci(1)==1 and fibonacci(41)==165580141 and fibonacci(3)==2 and fibonacci(91)==4660046610375530309"}
{"assignment_id":"search_recur","func_name":"search","reference_solution":"def search(str,letter):\n  '''returns True if letter is in str, False otherwise'''\n  if str == \"\":\n    return False\n  elif str[0] == letter:\n    return True\n  else:\n    #keep looking\n    return search(str[1:],letter)\n  \n\n","description":"Recursively search for a letter in a string","test":"assert search('','0')==False and search('0','0')==True and search('ERFE0Rfsef','0')==True and search('ERFERfsef0','0')==True and search('','a')==False and search('cbzeycuzbvyzuvb','a')==False and search('cbsducsvdbcyts','c')==True and search('dbzeducvbzy','y')==True and search('xqvsgxcutvy','u')==True"}
{"assignment_id":"index_recur","func_name":"index","reference_solution":"def index(str,letter,pos):\n  '''returns the position of letter in str, -1 if it is not there'''\n  if pos == len(str):\n    return -1\n  elif str[pos] == letter:\n    return pos\n  else:\n    return index(str,letter,pos+1)\n\n\n","description":"Recursively search for the position of letter in str, return -1 if it is not there.","test":"assert index('','0',0)==-1 and index('0','0',0)==0 and index('a','8',0)==-1 and index('tV2','2',0)==2"}
{"assignment_id":"fibonacci_recur","func_name":"fibonacci","reference_solution":"def fibonacci(n):\n  '''returns the value of the fibonacci series at position n'''\n  if n == 0:\n    return 0\n  elif n == 1:\n    return 1\n  else:\n    return fibonacci(n-1) + fibonacci(n-2)\n\n","description":"Recursively compute the value of the fibonacci series at position n.","test":"assert fibonacci(0)==0 and fibonacci(1)==1 and fibonacci(2)==1 and fibonacci(10)==55 and fibonacci(23)==28657"}
{"assignment_id":"factorial","func_name":"factorial","reference_solution":"def factorial(n):\n\tif n < 2:\n\t\treturn 1\n\treturn n * factorial(n-1)","description":"Compute the factorial of the given number.","test":"assert factorial(-1)==1 and factorial(0)==1 and factorial(1)==1 and factorial(2)==2 and factorial(5)==120 and factorial(20)==2432902008176640000"}
{"assignment_id":"sumup","func_name":"sumup","reference_solution":"def sumup(n):\n\tif n < 2:\n\t\treturn n\n\tsum_to_n = sumup(n-1)\n\treturn n + sum_to_n","description":"Return the sum of all integers up to n.","test":"assert sumup(0)==0 and sumup(1)==1 and sumup(2)==3 and sumup(10)==55 and sumup(27)==378"}