With any of these assignments, click on the **Clone** button to use it in your class.

- Week 1 Simple programs. Algorithms
- Week 2 Numbers and Strings
- Week 3 Simple Branches
- Week 4 Nested Branches, Booleans
- Week 5 Simple Loops
- Week 6 Complex Loops
- Week 7 Loop Algorithms
- Week 8 Functions
- Week 9 Arrays
- Week 10 Arrays Algorithms
- Week 11 2D Arrays and Vectors
- Week 12 Pointers
- Week 13 Simple Classes
- Week 14 More about Classes
- Week 15 Inheritance

- Given an input string, print the string with the first and last letter removed if they were equal, or the original string if they were not. CodeCheck
- On a chessboard, positions are marked with a letter between a and h for the column and a number between 1 and 8 for the row. Given an input string with a letter and number, print whether it is in a corner, at the border, or in the inside of the chess board. CodeCheck
- On a chessboard, fields are marked with a letter between a and h for the column and a number between 1 and 8 for the row. Given a position string, print the color of the field (white or black). CodeCheck
- Given the x- and y-coordinates of a point, print whether the point lies in the first, second, third, or fourth quadrant plane, or on the x-axis, or on the y-axis, or the origin. CodeCheck
- Given three numbers x, y, z, determine if one of them is the sum of the two others, and then print out the equation. CodeCheck
- Given three numbers x, y, z, print out how whether they are all distinct, two are the same, or all three are the same. CodeCheck
- Given two integers x and y, print their sum, but if it is more than 100 or less than 0, print "out of range". CodeCheck
- Given three integers x, y, z, print the sum of the odd integers. CodeCheck
- Given three input strings, print all but the shortest one. CodeCheck
- Given an actual time and an alarm clock time, both in “military” format (such as 0730 for 7:30am), print how many more minutes before the alarm rings. But if the time is after the alarm, print "Alarm already went off". CodeCheck
- Repeat the preceding exercise for U.S. time (e.g. 7:30am). CodeCheck
- Given a point with integer coordinates (x, y) and a compass direction N, E, S, W, print the neigboring lattice point. CodeCheck
- Repeat with compass directions NW, NE, SW, SE. CodeCheck

- Given two numbers, return true if they both have the same sign. CodeCheck
- Write a function that checks whether two points with coordinates x1, y1 and x2, y2 are in the same quadrant. CodeCheck
- Given two numbers, return their distance if it less than 10, or 10 otherwise. CodeCheck
- On a chessboard, positions are marked with a letter between a and h for the column and a number between 1 and 8 for the row. Given two position strings, return true if they have the same color. CodeCheck
- Given three numbers x, y, z and a Boolean variable
`strict`

, return`true`

if`strict`

is false and x ≤ y ≤ z, or`strict`

is true and x < y < z. CodeCheck - Given four numbers a, b, c, d, return true if exactly two of them are the same. CodeCheck
- Given three numbers, return true if they are evenly spaced; that is, sorted in ascending or descending order, with the same distance between them. CodeCheck
- Repeat for four numbers. Hint: Use the previous problem. CodeCheck
- Given numbers x, y, and target, return whichever of x and y is closer to the target. If they have the same distance, return the smaller of the two. CodeCheck

- Given a string, return the string with the first and last characters swapped. CodeCheck
- Given a string, return the string with the middle two characters removed if it has even length, and the middle character removed if it has odd length. CodeCheck
- Given a string, return the string with the middle two characters swapped if it has even length, and the middle three characters swapped if it has odd length. CodeCheck
- Given a string, return the string with the first and second half swapped. If the string has odd length, leave the middle character in place. CodeCheck
- Given a string, return the string with the first half and the second half doubled. For example, Java becomes JaJavava and Hello becomes HelHellolo. CodeCheck

- Given two strings s and t, return the first position where their characters differ, or -1 if they are identical. CodeCheck
- Given two strings s and t, return the first position where their characters are the same, or -1 if there is no such position. CodeCheck
- Given a string s, count how many times the ith character from the front equals the ith character from the back. CodeCheck

- Given strings s and t, return a list of all positions in which t occurs in s. CodeCheck
- Given strings s and t, return a string in which all occurrences of t are removed from s. CodeCheck
- Given strings s and t, return a string in which all characters in t are removed from s. CodeCheck
- Given a string s, return the longest prefix that is repeated somewhere else in the string. CodeCheck
- Given a string s, find the longest prefix that also occurs at the end (so that s = p + t + p), and return t, the string without the beginning and the end. CodeCheck

- Given a string in which words are separated by spaces, return the longest word. CodeCheck
- Given a string in which words are separated by spaces, return the first word that is duplicated (such as an accidental “this this”). CodeCheck
- Given a string in which words are separated by spaces, return the first word that is repeated somewhere in the string. CodeCheck
- Given a string in which words are separated by spaces, and two words a and b, interchange all occurrences of a and b. CodeCheck

- Given a string, find the first integer inside and return its value as an integer. Return 0 if there is no integer inside. CodeCheck
- Given a string, find the sum of all integers inside. Return 0 if there is no integer inside. CodeCheck
- Given a string, find all integers inside and return a string that separates them by commas. CodeCheck

- Given a string s and an integer n, return a string in which each of the characters in s is repeated n times. CodeCheck
- Given a string s, return the first vowel that is doubled in the string. CodeCheck
- Given a string s, return the string with adjacent duplicates removed. For example, Mississippi yields Misisipi. CodeCheck
- Given a string s and a string t, return a string in which all the characters of s that occur in t have been replaced by a _ sign. CodeCheck
- Given a string, return a string composed first of all characters at even positions and then of all characters at odd positions. CodeCheck
- Write a method that undoes the effect of the preceding exercise. CodeCheck
- Given a string and two characters x and y, interchange all occurrences of x and y. CodeCheck
- Given a string s and a character c, return a string with the characters surrounding the first of c reversed. For example, if s is Hello-World and c is -, return HellW-oorld. CodeCheck
- Given a string s and a character c, return a string with the characters surrounding any occurrence of c reversed. For example, if s is Hello beautiful world and c is a space, return Hellb oeautifuw lorld. CodeCheck

- Given an array of integers of length ≥ 4, return the average of the first two and last two elements. CodeCheck
- Given an array of integers of length ≥ 3, return the average of the first, last, and middle element (or the two middle elements if the length is even). CodeCheck
- Given an array of integers, swap the first and last elements. CodeCheck
- Given an array of integers, swap the first two and the last two elements. CodeCheck

- Given an integer n, fill an array of length n with 1 -1 1 -1 ... CodeCheck
- Given integers n and k, fill an array of length n with 0 1 2 ... k-1 0 1 2 ... k-1 ... CodeCheck
- Given integers a and b, fill an array with a, a + 1, a + 2, ..., b. CodeCheck
- Given integers a and b, fill an array containing all even numbers that are at least a and at most b. CodeCheck
- Given an integer n, fill an array with 1 2 2 3 3 3 4 4 4 4 ... and finally n repeated n times. CodeCheck

- Given an array of integers, return the position of the first occurrence of the largest element. CodeCheck
- Given an array of integers, return the position of the last occurrence of the largest element. CodeCheck
- Given an array of integers, return the difference of the positions of the first and the last occurrence of the largest element. CodeCheck
- Given an array of integers, return the difference between the maximum and minimum. CodeCheck
- Given an array of integers, swap the the maximum and minimum. CodeCheck
- Given an array of integers, return the second-largest element.
- Given an array of element, find the shortest distance between two consecutive elements. CodeCheck

- Given an array of integers and a value, return the position of the last occurrence of the value in the array, or -1 if the value does not exist. CodeCheck
- Given an array of integers and a value, return the difference between the last and first position of the value in the array, or -1 if the value does not exist. CodeCheck
- Given an array of integers and a value, fill an array with all positions of the value in the array. CodeCheck
- Given an array of integers and a value, return the position of the element that is closest to the value. If there is more than one, return the position of the first one. CodeCheck
- Given two arrays of integers of the same length, return the first position where their elements are the same. CodeCheck
- Given two arrays of integers of the same length, return the first position where their elements differ. CodeCheck

- Given an array of integers, count how many elements are negative. CodeCheck
- Given an array of integers and two values a and b, count how many elements are at least a and at most b. CodeCheck
- Given an array of integers, return the most frequent element. If there is more than one element with maximum frequency, return the one that occurs first in the array. CodeCheck
- Given an array of integers, return an array of all elements that occur with maximum frequency. CodeCheck
- Given an array of integers, return the position of the first element that occurs more than once, or -1 if all elements occur exactly once. CodeCheck
- Given an array of integers, return an array of all elements that occur exactly once. CodeCheck
- Given an array of integers, remove all elements that occur more than once, leaving the first occurrence. CodeCheck
- Given two arrays of integers a and b of the same length, count the number of positions where the arrays have the same elements. CodeCheck
- Given two arrays of integers a and b of the same length, count the number of positions where the array elements differ by at least 2. CodeCheck
- Given an array a, count how many times the ith element from the front equals the ith element from the back. CodeCheck

- Given an array of integers, return the sum of all positive elements. CodeCheck
- Given an array of integers, return the sum of all odd elements. CodeCheck
- Given an array of integers and two values a and b, return the sum of all elements that are at least a and at most b. CodeCheck
- Given an array of integers, return the average of all positive elements. CodeCheck
- Given an array of strings and a string s, return the average length of all strings containing s. CodeCheck
- Given an array of integers, return the product of all non-zero elements. CodeCheck
- Given an array of integers, give the smallest n so that the sum of the first n elements is at least as large as the sum of the remaining elements. CodeCheck
- Given an array of integers, give the largest n ≤ length / 2 so that the sum of the first n elements equals the sum of the last n elements. CodeCheck
- Given an array of integers, give the largest sum of n consecutive elements. CodeCheck
- Given an array of integers, find the largest sum of two different elements in the array. CodeCheck
- Given an array of floating-point numbers, return an array of the averages of consecutive element pairs of the original array. CodeCheck
- Given an array of integers and an integer n, return an array of the averages of n consecutive elements of the original array. CodeCheck
- Given an array of integers, return the average of all elements that are not the maximum or minimum. CodeCheck
- Given an array of integers, replace each element with the average of its neighbors. CodeCheck

- Given an array of integers and an integer n, remove all elementts > n or < -n. Shift all remaining elements to the front, and return the number of removed elements. CodeCheck
- Given an array of integers, move all zeroes to the back. CodeCheck
- Given an array of integers, move all zeroes to the front. CodeCheck
- Given an array of integers, move all negative numbers to the front and all positive numbers to the back, keeping their relative order. CodeCheck
- Given an array of integers, remove all even elements that occur exactly twice. CodeCheck
- Given an array of integers, remove all adjacent duplicates. CodeCheck

- Given an array of integers, return an array of length 2 containing the first and last element, in sorted order. CodeCheck
- Given an array of integers, return an array of length 2 containing the minimum and the maximum. CodeCheck
- Given an array of integers, return an array of length 2, with the number of positive and the number of negative elements in the array. CodeCheck
- Given an array of integers, return an array of length 2, each being an array. The first one holds the positive elements and the second one holds the negative elements of the original array. CodeCheck
- Given an array of integers, return an array of length 2, each being an array. The first one holds the elements with even positions, and the second one holds the elements with odd positions of the original array. CodeCheck

- Given two arrays a and b, remove all elements of b from a. CodeCheck
- Given two arrays a and b, return an array that contains all elements occurring in a but not in b. CodeCheck
- Given an array a, return the longest n so that the first n elements equal the last n elements. CodeCheck
- Given an array of integers, return the largest sum of consecutive elements. CodeCheck
- Given an array of integers, return the largest sequence whose reverse also occurs somewhere in the array. CodeCheck
- Given an array a of integers, return an array of all elements of a that occur exactly once. CodeCheck
- Given an array of integers, return an array of arrays of length 2, containing each unique element together with its frequency. CodeCheck
- Given an array of integers, return the position of the longest subsequence of consecutive integers a, a + 1, a + 2, ... CodeCheck

- Given a two-dimensional array of integers, return the average of the four corner elements. CodeCheck
- Given a two-dimensional array of integers, return the middle element if both the row and column lenghts are odd, or the average of the two or four middle elements of one or both is even. CodeCheck
- Given a two-dimensional array of integers and a string N, E, S, W, give the middle element along the border in the given compass direction, or the average of the two middle ones if the border length is even. CodeCheck
- Given a two-dimensional array of integers and a string NW, NW, SW, SE, return the sum of the four elements in the given compass direction. CodeCheck
- Given a two-dimensional array of integers, row/column indexes r, c, and a string N E S W, return the neighbor in that direction, or 0 if it doesn't exist. CodeCheck
- Repeat with NW NE SW SE. CodeCheck
- Given a two-dimensional array of integers and row/column indexes r, c, return the number of neighbors (not counting the element itself). A neighbor is any neighbor in the compass direction N E S W NE NW SE SW. CodeCheck
- On a chessboard, positions are marked with a letter between a and h for the column and a number between 1 and 8 for the row. Given an 8x8 array of integers and a string with such a position, return the element at that position. CodeCheck

- Given a two-dimensional array of integers and a row index, return the largest element in that row. CodeCheck
- Given a two-dimensional array of integers and a column index, return the smallest element in that column. CodeCheck
- Given a two-dimensional array of integers, an index, and a string R or C, return the sum of the elements in that row or column. CodeCheck
- Given a two-dimensional array of integers, a row index r, and a column index c, return the sum of all elements in the given row and column. The element where the row and column meet should only be included once. CodeCheck
- Given a two-dimensional array of integers and a string N, E, S, W, return the sum of all elements of the border in the given compass direction. CodeCheck
- Given a two-dimensional array of integers, return the sum of all elements along the north and south border. CodeCheck
- Given a two-dimensional array of integers, return the sum of all elements along all borders but not the corners. CodeCheck
- Given a two-dimensional array of integers, return the sum of all elements along all borders including the corners. CodeCheck
- Given a two-dimensional square array of integers, return the sum of the elements along both diagonals. Make sure not to count the center twice. CodeCheck
- Given a two-dimensional array of integers and a row index r, reverse the given row. CodeCheck
- Given a two-dimensional square array of integers, reverse both diagonals. CodeCheck

- Given a two-dimensional array of integers, compute the sum of all positive elements. CodeCheck
- Given a two-dimensional array of integers, compute the sum of all elements that are not one of the borders. CodeCheck
- Given a two-dimensional square array of integers, compute the sum of all elements that are not on one of the diagonals. CodeCheck
- Given a two-dimensional array of integers, replace all negative elements with zero. CodeCheck
- Given a two-dimensional array of integers, reverse all rows. CodeCheck
- Given a two-dimensional array of integers, shift each row by one to the right and put a 0 at the leftmost column. The rightmost column is lost. CodeCheck
- Given an r x c array of integers, return an (r + 2) x (c + 2) array whose borders are zero and whose interior is the original array. CodeCheck
- Given a two-dimensional array of integers, return an array of the largest element in each row. CodeCheck
- Given a two-dimensional array of integers, return an array of the number of negative elements in each column. CodeCheck
- Given a two-dimensional array of integers, return the largest element in the array. CodeCheck
- Given a two-dimensional array of integers, return the position of the smallest element in the array as an array of length 2. CodeCheck
- Given a two-dimensional array of integers and a value x, return the position of the first match as an array of length 2. Return [-1, -1] if the value does not occur in the array. CodeCheck
- Given a two-dimensional array of integers and a value x, return the positions of all matching elements, as an array of arrays of length 2. CodeCheck

- Given a two-dimensional array of integers and row/column positions r, c, return the largest neighbor in the compass directions N E S W. CodeCheck
- Given a two-dimensional array of integers and row/column positions r, c, return the largest neighbor in the compass directions N E S W NE NW SE SW. CodeCheck
- Given a two-dimensional array of integers and row/column positions r, c, return the compass direction of the largest neighbor as a string N E S W NE NW SE SW. CodeCheck
- Given a two-dimensional array of integers, row/column positions r, c, and a value x, fill the given element and its neighbors in the compass directions N E S W NE NW SE SW with x. CodeCheck
- Given a two-dimensional array a of integers and row/column positions r, c, return a 3x3 array whose middle element is a[r][c], and whose neighbors are copied from the original. Set non-existent neighbors to zero. CodeCheck

- Given an integer n, produce the array
0 1 2 3 ... n 1 2 3 4 ... 0 ... n 0 1 2 ... n-1

CodeCheck - Given two two-dimensional arrays a and b of integers with the same number of rows and columns, return an array of the same size where each element is the greater of the corresponding elements in the two arrays. CodeCheck
- Repeat the preceding exercise where the array dimensions need not match, filling positions that exist in neither array with 0. CodeCheck
- Given two two-dimensional arrays of integers with the same number of rows and columns, return the first position where they do not match, as an array of length 2. CodeCheck
- Given two two-dimensional arrays with the same number of rows, return an array that places them side by side. CodeCheck
- Repeat where the row lengths don't have to match. Fill the shorter array with zeroes. CodeCheck
- Given a two-dimensional array a, return an array whose [i][j] element is the average of the neighbors of a[i][j] in the N, E, S, W direction. CodeCheck

- Given a two-dimensional array of integers, return the number of distinct elements. CodeCheck
- Given a two-dimensional array of integers, remove any adjacent duplicate rows by filling the duplicates with zeroes. CodeCheck
- Given a two-dimensional array of integers, return the index of the first row that is entirely filled with CodeCheckzeroes.
- Given a two-dimensional array of integers, return the top left corner of the first subarray of the form
0 0 0 0

CodeCheck - Given a two-dimensional array of integers, return the position of the largest square subarray filled with zeroes, as an array of length 2. Return [-1, -1] if there is no such subarray. CodeCheck
- Repeat the previous exercise with subarrays that are not necessarily square. CodeCheck