Problem 8 in Julia