{"assignment_id":"reverse.py_ca277_reverse","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.","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":"func_selection_sort.py_ca116_selection_sort","func_name":"selection_sort","reference_solution":"def selection_sort(a):\n\ti=0\n\twhile iPI5FmV\/dq,-=]N2MmOkB .hRL_P2','=')==3"} {"assignment_id":"iterative08.py_ca278_fibonacci","func_name":"fibonacci","reference_solution":"def fibonacci(n):\n '''returns the value of the fibonnaci series at position n'''\n if n == 0 or n == 1:\n return 1\n else:\n fibN_2 = 1\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":"Return the value of the fibonacci series at position n.","test":"assert fibonacci(0)==1 and fibonacci(1)==1 and fibonacci(2)==2 and fibonacci(10)==89 and fibonacci(23)==46368"} {"assignment_id":"recursive08.py_ca278_search","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":"Return whether a letter is part of 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":"recursive08.py_ca278_index","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":"Return the position of letter in str, -1 if it is not there.","test":"assert index('','0',0)==-1 and index('dc8','s',0)==-1"} {"assignment_id":"recursive08.py_ca278_fibonacci","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":"Return 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":"count_102.py_ca117_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":"fibonacci_102.py_ca117_fibonacci","func_name":"fibonacci","reference_solution":"def fibonacci(n):\n if n == 0:\n return 1\n if n == 1:\n return 1\n return fibonacci(n-1) + fibonacci(n-2)\n","description":"Return the value of the fibonacci series at position n.","test":"assert fibonacci(0)==1 and fibonacci(1)==1 and fibonacci(2)==2 and fibonacci(10)==89 and fibonacci(23)==46368"} {"assignment_id":"maximum_102.py_ca117_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_102.py_ca117_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":"selectionsort_102.py_ca117_selectionsort","func_name":"selectionsort","reference_solution":"def selectionsort(A):\n\n i = 0\n while i < len(A):\n min_index = i\n j = i+1\n while j < len(A):\n if A[j] < A[min_index]:\n min_index = j\n j += 1\n A[i], A[min_index] = A[min_index], A[i]\n i += 1\n\n# repeatedly insert into sorted array\n","description":"Repeatedly move minimimum of remaining sublist to front.","test":"assert selectionsort([])==None and selectionsort([])==None and selectionsort([0])==None and selectionsort([0])==None"} {"assignment_id":"quicksort_102.py_ca117_quicksort","func_name":"quicksort","reference_solution":"def partition(A, p, r):\n q = j = p\n while j < r:\n if A[j] <= A[r]:\n A[q], A[j] = A[j], A[q]\n q = q + 1\n j = j + 1\n A[q], A[r] = A[r], A[q]\n return q\n\n \ndef quicksort(A, p, r):\n \n def partition(A, p, r):\n q = j = p\n while j < r:\n if A[j] <= A[r]:\n A[q], A[j] = A[j], A[q]\n q = q + 1\n j = j + 1\n A[q], A[r] = A[r], A[q]\n return q\n\n if r <= p:\n return\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q + 1, r)","description":"Recursively partition list until sorted.","test":"assert quicksort([],0,0)==None and quicksort([],0,0)==None and quicksort([5, 4, 3, 2, 1],0,4)==None and quicksort([5, 4, 3, 2, 1],0,4)==None and quicksort([5, 5, 5, 5],0,3)==None and quicksort([5, 5, 5, 5],0,3)==None and quicksort([5675, 564, 987, 154132, 8976, 0, -16221, 87526, 9826732986],0,8)==None and quicksort([5675, 564, 987, 154132, 8976, 0, -16221, 87526, 9826732986],0,8)==None"} {"assignment_id":"reverse_102.py_ca117_reverse_list","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":"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":"selection_sort.py_ca277_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":"Repeatedly move minimimum of remaining sublist to 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":"sets.py_ca277_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":"sets.py_ca277_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 elements which are in both 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]"}