added working solution to 4 (not mine)