Homework 3
CS1210, Fall 2021
Due Friday, Sep. 24, 2021, by 8:00pm
6 points

Note: you may not use list comprehensions or similar Python constructs not taught yet in this course. You may not use dictionaries. See notes for individual problem for any additional constraints.
1. Write a function, q1(inputString, minLetter), that takes as input a string of letters and returns six things: the lexicographically smallest letter (z/Z > y/Y > ... > a/A) greater or equal to minLetter, the smallest index at which that letter occurs, the third smallest letter greater than or equal to minLetter, the smallest index at which that letter occurs, the most common letter, and how many times the most common letter occurs. The third smallest letter must be distinct from the second smallest which must be distinct from the smallest. E.g. 'b' is the second smallest and 'c' is the third smallest in 'ababdc'

Ignore case during computation. E.g. 'z' and 'Z' are considered the same letter. Use lower case when returning letters.

Return None for smallest and third smallest letters and corresponding indices when appropriate.

You may not assume that the input string contains at least three different characters (or even any characters at all). Make sure to recognize various situations where fewer than three different letters appear in the string, and where there is no third smallest or smallest greater than minLetter.

If two or more letters tie for most common, return the lexicographically largest one.

For example:
>>> q1('aacyYcqyQQqyqc', 'b')
('c', 2, 'y', 3, 'q', 5)

>>> q1('aacyYcqyQQqyqc', 'r')
('y', 3, None, None, 'q', 5)

>>> q1 ('adbc', 'a')
('a', 0, 'c', 3, 'd', 1)

Important note: Use one or more simple loops, and simple comparison (<,>, ==, !=) operators only. You may use [] to access single characters of a string. You may not use built-in min, max, sort, or sorted functions (you should also not write your own sorting method). You may not use any built-in string methods other than .lower()). You may not use lists or dictionaries or the ord() function.

2. Implement function, q2(L, goalX, goalY), that takes a non-empty list, L, of [x,y] pairs, and two goal numbers, and returns tuple (closestXY, XorY) where closestXY is the item from L whose x distance from goal X or whose y distance from goalY is the minimum among all distances, and XorY is 'XMIN' if x distance is minimized and 'YMIN' otherwise. You may assume there is a unique answer. Note: You may not use built-in min or max functions.
>>> q2([[4, 4], [10, 10]], 1, 8)
([10,10], 'YMIN')
>>> q2([[10, 25], [2, 2], [49, 200]], 50, 8)
([49,200],  'XMIN')
3. Implement function q3(L) that takes as input a (possibly empty) list of (possibly empty) lists of numbers and returns a three-element list. The first element is a list of the sums of corresponding lists in L, the second element is the number of lists in L that contain more positive than negative values, and the third element is the maximum value among all items in all lists (or None if there is no maximum). Notes: you may NOT use Python's sum(), min(), or max() functions; instead, compute sums and max within a loop or loops. 0 (zero) is neither positive nor negative!
For example,
>>> q3([[1, 2, 2], [3]])
[[5, 3], 2, 3]
>>> q3([[0, 1, 0], [], [-1, 100]])
[[1, 0, 99], 1, 100]

Submit to ICON one python file containing the required functions. The file must not contain any code (other than, perhaps, "import math") that is not part of a function definition.