how to produce the equivalent apl's `10×⍳2+5` ? in ruby

In Ruby, you can achieve the equivalent of 10×⍳2+5 in APL using the following code:

main.rb
(0..(2+5-1)).map { |i| i * 10 }
32 chars
2 lines

Explanation:

  • (0..(2+5-1)) creates a range from 0 to 6 (2+5-1).
  • .map iterates over the range and applies the provided block to each element.
  • i * 10 multiplies each element in the range by 10.

Thus, the result will be [0, 10, 20, 30, 40, 50], just like in APL.

related categories

gistlibby LogSnag