-3

I just started exploring APL. Though, familiar with C++ and python, I got stuck executing a simple program 'Print first n odd numbers' where n is the input in APL. Please help APL coders.

sepp2k
  • 363,768
  • 54
  • 674
  • 675

1 Answers1

5

You mean you got stuck implementing that APL program?

Mathematically, odd numbers are of the form 2i+1. In APL the expression ⍳n gives us the integers 0 through n-1 (assuming index origin 0). To obtain the desired result, multiply those by two and add one:

1+2×⍳n
ngn
  • 7,763
  • 6
  • 26
  • 35