answer exercise 18 (quick and dirty stackexchange version)