Some exercises for working with Sequences.

  1. Write a program called addOne, that given a list of integers adds one to each element.

    1. How many times will addOne be called on the list [1,2,3,4,5]?
  2. This question is divided into two components:

    1. Write a program which, given three integers a, b, and c, returns true if:

      a2+b2=c2 a^2 + b^2 = c^2

    2. Write a second program that, given a list of integer triples, returns all the triples where:

      a2+b2=c2 a^2 + b^2 = c^2

  3. Given a list of characters, write a program which returns:

    You’re Out!

    if it finds three occurrences of a given value in a list, and otherwise returns:

    all good

    Hint
    you may want to define a helper function.
  4. Write a program that sums the even values of a list of integers.

  5. Write a program that returns True if a character occurs twice in a row in a string, and False otherwise.

    Hint
    Strings in Python, Dafny, and Idris are represented differently.

    Now:

    1. provide a new program that work on lists of strings;
    2. provide a new program that works on lists of lists;
  6. Without using code from the standard library, write a program that computes the maximum value in a list of integers.

    Using your program, define a function that sorts a list of integers from smallest to largest.

  7. Write a program that returns the character at a given position in a string.

  8. Write a program that reverses lists of length 2 and leaves all other lists unchanged