0

How many integer numbers are in the vector 20.88 10 ¯2.3 0 .555 222 ¯0 2 3.3 9?

I need to do it using APL.

Please also recommend any links to learn the APL language.

Mikhail Kholodkov
  • 23,642
  • 17
  • 61
  • 78
Artyr
  • 21
  • 2
  • 3
    Welcome to SO Artyr! You'll get more receptive responses if you show us what you've attempted, as this will help us guide you in the correct direction. – Joel Nov 01 '18 at 12:39
  • Which APL version do you use? – Adám Nov 01 '18 at 12:58

1 Answers1

6

Counting integers

You can check if a number x is an integer with x=⌊x, but of course APL processes entire arrays at a time, so using the name v for your vector, v=⌊v gives you a Boolean vector indicating integers (0 1 0 1 0 1 1 1 0 1 in your case) and +/v=⌊v is the sum of the Boolean vector, that is the count of integers.

Try it on TryAPL!

Links to learn APL

For learning APL, The APL Orchard is a good place to hang out. There are people there who can help you and an APL chat bot to evaluate small expression. The chat bot's profile has a collection of links to APL resources.

You can also find transcripts of the APL Cultivation lessons which were held in the APL Orchard.

Alternative integer counting method

1|x is the division remainder when x is divided by one. This gives you the fractional part of x. If that fractional part is zero, x is an integer: 0=1|x. Continue as per the above method. TryAPL!

Community
  • 1
  • 1
Adám
  • 6,573
  • 20
  • 37