Solution, never compiled, never run, written on a 4 inch smartphone