ruby 编码 : Sequence of number pairs "x,y" such that x ranges from 0 to 3 and y from 5 to 7

标签 ruby

我被困在这个问题上了。我尝试用 Ruby 解决它。

我的答案是

4.times{|i| puts "#{i}"} && 5.upon(7){|i| puts "#{i}}

但是,我不确定它是否正确。

最佳答案

这应该适合你

result = (0..3).to_a.product((5..7).to_a)
puts result.inspect
#=> [[0, 5], [0, 6], [0, 7], [1, 5], [1, 6], [1, 7], [2, 5], [2, 6], [2, 7], [3, 5], [3, 6], [3, 7]]

关于 ruby 编码 : Sequence of number pairs "x,y" such that x ranges from 0 to 3 and y from 5 to 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13486739/

相关文章:

ruby - 如何按定义的顺序对数组进行划分和排序

ruby-on-rails - 文字和构造函数之间的区别? ([] 与 Array.new 和 {} 与 Hash.new)

ruby - Ruby 中的赋值没有按预期工作

ruby - 如何将 "商品编号"转换为 "\u5546\u54c1\u7f16\u53f7"

Ruby rspec 测试命令 : could not locate Gemfile

ruby-on-rails - Ruby On Rails 与 Windows Vista - 最佳设置?

ruby-on-rails - 如何仅在使用 ElasticSearch 和 Tire 存在时按属性过滤搜索?

html - 将表单文本字段中的值拉到 ruby​​ on rails html 中的其他位置

ruby - 如何指向哈希中的深层嵌套元素?

ruby - 搜索多个数据源