Simple programming assignments

Submission instructions 

These assignments are meant to help students who need to practice simpler programming exercises
  • To submit this assignment you need to have less than 150,000 points
  • Each question is worth 4,000 points as usual.
  • Please submit your assignments to the email address bhamcs22752@gmail.com .
  • The subject line must be in the following format: Week 100 Question number ID n
  • For example: Week 100 Question 1 ID 175674.
  • The body of the email must contain only the source code of the program you are submitting -- just copy-and-paste your program into the email. 
  • Use a separate email for each question you are submitting.
  • Once you submit a correct answer to an assignment, further submissions for the same assignment will be ignored. 
  • You will need to consult the scoreboard to make sure that your assignment was processed and accepted. 
  • Incorrect programs can be resubmitted.
  • If you have any questions about the submission process, contact Alex Smith
  • Do not send your solutions to any other email address, as they won't be processed.
  • These questions carry no bonuses
Assignments
  1. Find the last element of a list.
    Example: lastelem [1; 2; 3; 4] = 4

  2. Find the second-last element of a list.
    Example: seclastelem [1; 2; 3; 4] = 3

  3. Find out whether a list is a palindrome. A palindrome is the same if read forward or backward, for example [1;2;3;2;1].
    Example: palindrome [1; 2; 3; 4] = false
    Example: palindrome [1; 2; 3; 4; 3; 2; 1] = true

  4. Remove consecutive duplicate elements from a list.
    Example: removedup [1; 2; 2; 2; 3; 4; 4] = [1; 2; 3; 4]

  5. Duplicate all the elements of a list.
    Example: duplicate [1; 2; 3; 4] = [1; 1; 2; 2; 3; 3; 4; 4]

  6. Replicate all the elements of a list a given number of times.
    Example: replicate 3 [1; 2; 3; 4] = [1; 1; 1; 2; 2; 2; 3; 3; 3; 4; 4; 4]

  7. Remove every nth element from a list.
    Example: removenth 3 [1; 2; 3; 4; 5; 6; 7; 8; 9] = [1; 2; 4; 5; 7; 8]

  8. Split a list in two parts where the length of the first part is given.
    Example: split 3 [1; 2; 3; 4; 5; 6; 7; 8; 9] = ([1; 2; 3], [4; 5; 6; 7; 8; 9])

  9. Insert an element just before a given position in a list (starting from 0).
    Example: insert 3 'x' ['a'; 'b'; 'c'; 'd'; 'e'; 'f'; 'g'] = ['a'; 'b'; 'c'; 'x'; 'd'; 'e'; 'f'; 'g']

  10. Create a list of all integers in a given range. 
    Example: range 3 10 = [3; 4; 5; 6; 7; 8; 9; 10]
Comments