Use built-in enumeration methods

http://ideone.com/zWXeJX