First crack at solving the first problem. Currently not correct