3 ms·
So basically you already have an arbitrary list of 1000 numbers. That may or may not be prime? And you want to know how many are prime? (Let me know if I am wr
by max_ 3y ago
So basically you already have an arbitrary list of 1000 numbers.
That may or may not be prime? And you want to know how many are prime? (Let me know if I am wrong)
1. Pick the highest number, H in the arbitrary list of 1000 numbers.
2. Generate all prime numbers up to the highest number, H.
3. Use e., Verb also known as member of to check for prime numbers present in arbitrary list. +/(all prime numbers up to H e. arbitrary list of 1000 numbers) will give you the number of items in the arbitrary list that are prime.
> will J cleverly optimize away the i.1000 array?
The primitives & verbs in array languages are designed to be as fast and efficient as possible.
So even if your code is mediocre, it will perform better that any mediocre imperative code.
- dzaima 3y agoI believe J doesn't have any optimizations specifically for the problem of large temporary arrays (not to say that such can't exist, but I don't think anyone's written such yet). With multiple temporary operations, each making a temporary array larger than cache, it could in fact end up slower than mediocre imperative scalar code.
- max_ 3y agoThanks for the insight.