prime number test in Ruby
来源:互联网 发布:淘宝如何上首页 编辑:程序博客网 时间:2024/05/21 17:37
I have an array a = [1,2,3,4,5]
. I want to test which of the numbers areprime and wanted to produce the output {1=>false, 2=>true, 3=>true, 4=>false, 5=>true}
.
Any one liner will be appreciated.
require 'prime'a = [1,2,3,4,5]Hash[a.zip(a.map(&Prime.method(:prime?)))]# => {1=>false, 2=>true, 3=>true, 4=>false, 5=>true}
I posted this as a comment.
require 'prime'a = (1..5).to_aHash[a.map{ |x| [x, x.prime?] }]=> {1=>false, 2=>true, 3=>true, 4=>false, 5=>true}
0 0
- prime number test in Ruby
- Prime Test
- Prime Test
- Prime Test
- Prime Number
- Prime number
- Prime Number
- Prime Number
- prime number
- how to test observe with rspec in ruby on rails.
- Seeing numbers in Ruby with r attached to the number
- POJ 1811 Prime Test
- poj 1811 Prime Test
- POJ 1811 Prime Test
- POJ 1811 Prime Test
- poj 1811 Prime Test
- poj 1811 Prime Test
- POJ1811 Prime Test
- web dao查到数据库然后显示页面
- android xml解析
- [转]Golang适合高并发场景的原因分析
- 程序员必须知道的10大基础实用算法及其讲解
- C++ 习题 输出日期时间--友元函数
- prime number test in Ruby
- pydev-python 链接mysql数据库(mac系统)
- iOS APNS远程推送(最详细解析)
- ubuntu12.04用cross over运行sketchup 8的错误解决办法
- JavaScript-RegExp对象只能使用一次问题解决方法
- 数据挖掘:网络挖掘技术——微博文本特征提取
- iOS中单例有那些
- Ubuntu上HBase伪分布的配置
- 网络编程