same exercise in scala