Some exercises for working with Sequences.
Write a program called
addOne, that given a list of integers adds one to each element.- How many times will
addOnebe called on the list[1,2,3,4,5]?
- How many times will
This question is divided into two components:
Write a program which, given three integers
a,b, andc, returns true if:Write a second program that, given a list of integer triples, returns all the triples where:
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.
Write a program that sums the even values of a list of integers.
Write a program that returns
Trueif a character occurs twice in a row in a string, and False otherwise.- Hint
- Strings in Python, Dafny, and Idris are represented differently.
Now:
- provide a new program that work on lists of strings;
- provide a new program that works on lists of lists;
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.
Write a program that returns the character at a given position in a string.
Write a program that reverses lists of length 2 and leaves all other lists unchanged