« first day (2643 days earlier)      last day (35 days later) » 

8:10 AM
As LdBeth points out your isPrime "incorrectly" reports 1 as prime.
Reading your isPrime, your definition of a prime number would be: A number which doesn’t have a factor in the set ]1;number[
As far as I'm aware the most widely used definition of a prime number is: A number that have exactly two positive factors.
If we go by this latter definition of a prime number we can make small changes to your APL code to make it fit: IsPrime←{2=+/0=⍵ |⍨ ⍳⍵}
Your definition of a prime number is of course not unheard of, and it is a good implementation of it :)
 
8:40 AM
@Haruki i think a better way might be implementing a sieve – filtering numbers by whether they're multiples of other numbers
something like {(1↓⍳⍵)~(,∘.×⍨1↓⍳⍵)}
this can probably be made tacit
yeah, (⊢~(,∘.×⍨))1↓⍳ seems to work
ah, interestingly aplcart has (⊢~∘.×⍨)1↓⍳ without the ravel, didn't realize that would work
 
thank you guys, i woke up recently. I will soon look deeper into suggestions made. I am aware 1 is not prime, I seem to missed it yesterday as I am still very much a novice haha
 
i think the code i sent (especially the dfn version) is somewhat parseable, but of course if you need help in understanding it just ask!
 
 
4 hours later…
12:46 PM
@Haruki Btw, expr/⍳⍵ is ⍸expr
 
 
10 hours later…
10:48 PM
I altered code for me to help understand it:
(⊢~∘.×⍨)2 3 4 5 6 7 8 9 10
but I still need some help to understand the code. I think commute operator is confusing me a bit. I get it takes list of numbers from 2 to n and removes numbers got through outer product, but i dont get it all the way
 
(⊢)~((∘.×)⍨)
((∘.×)⍨)A ←→ A (∘.×) A, and (⊢~f)A ←→ A~f A
 
11:12 PM
oh I learned smth new, I might have missed it.
if commute has arrays/scalars on both sides it swaps them places and if there is only function on left of it then it insert right argument to be left argument as well.
I am getting better ^^
 

« first day (2643 days earlier)      last day (35 days later) »