arrays - prime number test in Ruby -
i have array a = [1,2,3,4,5]
. want test of numbers prime , wanted produce output {1=>false, 2=>true, 3=>true, 4=>false, 5=>true}
.
any 1 liner appreciated.
the below work you,using prime#prime?
:
require 'prime' = [1,2,3,4,5] hash[a.zip(a.map(&prime.method(:prime?)))] # => {1=>false, 2=>true, 3=>true, 4=>false, 5=>true}
Comments
Post a Comment