Re: [Jprogramming] Generating "music" in J (or otherwise)

2020-04-24 Thread HH PackRat
On 4/23/20, Brian Schott wrote: > Harvey, > Your explanations were very helpful. Especially of the second line of > RSLTNT output. > There is no listing of the notes that go with the example RSLTNT 5 3, are > there? Your explanation just understands what notes are typical and the > meaning of "int

[Jprogramming] Factoring

2020-04-24 Thread Skip Cave
I want to find all the integer factors of a positive integer, which includes 1 and the integer. Here's a brute force verb I wrote: fac=:3 : 'a#~0=(a=.1+i.y)|y' Test it: fac each 40+i.5 │1 2 4 5 8 10 20 40│1 41│1 2 3 6 7 14 21 42│1 43│1 2 4 11 22 44│ However my fac verb is inefficient, slow, an

Re: [Jprogramming] Factoring

2020-04-24 Thread Roger Hui
See https://code.jsoftware.com/wiki/Essays/Factorings On Fri, Apr 24, 2020 at 11:29 AM Skip Cave wrote: > I want to find all the integer factors of a positive integer, > which includes 1 and the integer. > Here's a brute force verb I wrote: > fac=:3 : 'a#~0=(a=.1+i.y)|y' > > Test it: > > fac e

Re: [Jprogramming] Factoring

2020-04-24 Thread Hauke Rehr
using builtin q: I get correct results using /:~ ~.@, ((*/)@#"1~ #:@:i.@(2&^)@#) 1,q: 4711 1 7 673 4711 /:~ ~.@, ((*/)@#"1~ #:@:i.@(2&^)@#) 1,q: 42 1 2 3 6 7 14 21 42 less brute force but it’s just a first attempt Am 24.04.20 um 20:28 schrieb Skip Cave: I want to find all the integer f

Re: [Jprogramming] Factoring

2020-04-24 Thread Skip Cave
I have used the wrong terminology. I want to find all the positive integer *divisors* of an integer n (not just primes) which includes 1 and the integer. Here's a brute force verb I wrote: div=:3 : 'a#~0=(a=.1+i.y)|y' Test it: div each 40+i.5 │1 2 4 5 8 10 20 40│1 41│1 2 3 6 7 14 21 42│1 43│1 2

Re: [Jprogramming] Factoring

2020-04-24 Thread Hauke Rehr
does counting suffice? then that would be φ which I’m sure someone must have written code for already Am 24.04.20 um 21:09 schrieb Skip Cave: I have used the wrong terminology. I want to find all the positive integer *divisors* of an integer n (not just primes) which includes 1 and the integer.

Re: [Jprogramming] Factoring

2020-04-24 Thread 'Michael Day' via Programming
Euler's phi function?  That's    5 p: ] or   5&p: the "totient" Not what Skip is looking for,  though? On 24/04/2020 20:14, Hauke Rehr wrote: does counting suffice? then that would be φ which I’m sure someone must have written code for already Am 24.04.20 um 21:09 schrieb Sk

Re: [Jprogramming] Factoring

2020-04-24 Thread Hauke Rehr
Sorry, I must have confused things. This is not at all the correct answer. I thought it should be (- φ) n, but obviously it’s wrong. (tested with some numbers) Thanks for pointing to 5&p: for φ, though. Am 24.04.20 um 21:31 schrieb 'Michael Day' via Programming: Euler's phi function?  That's  

Re: [Jprogramming] Generating "music" in J (or otherwise)

2020-04-24 Thread HH PackRat
It occurred to me that I had forgotten two other ways that the "rhythm" resultant of 3 2 1 3 1 2 3 could be used--namely, for volume (dynamics) and for speed (tempo) of some music. The point is that any resultant of "interference" of 2 or more rhythms (whether constant "beats" or including another

Re: [Jprogramming] Factoring

2020-04-24 Thread Hauke Rehr
I now have an answer for the number of results: */ >: +/"1 (=/~ ~.) q: 4711 4 */ >: +/"1 (=/~ ~.) q: 42 8 I hesitate using =/~ (it’s actually deprecated) but I wouldn’t know a better way in this case Am 24.04.20 um 21:09 schrieb Skip Cave: I have used the wrong terminology. I want to fi

Re: [Jprogramming] Factoring

2020-04-24 Thread Roger Hui
The number of ways a prime p can participate in a list of divisors is 1+e where e is its exponent in the prime factorization of x . __ q: x gives you the primes and the corresponding exponents. Therefore: # div 24 8 */ 1 + {: __ q: 24 8 # div 64e8 135 */ 1 + {: __ q: 64e8 135 On

Re: [Jprogramming] Factoring

2020-04-24 Thread 'Mike Day' via Programming
I think this is near to the approved way: (*/"1@:>:@(_& q:))24 360 4711 8 24 4 Mike Sent from my iPad > On 24 Apr 2020, at 21:13, Hauke Rehr wrote: > > I now have an answer for the number of results: > > */ >: +/"1 (=/~ ~.) q: 4711 > 4 > */ >: +/"1 (=/~ ~.) q: 42 > 8 > > I hesitate u

[Jprogramming] Dyadic "cut" with Boolean left argument

2020-04-24 Thread Devon McCormick
I seem to recall there is a way to use the "cut" conjunction with a Boolean left argument specifying partition boundaries but I cannot find where this is mentioned on the J wiki. Is there a way to do this? Thanks, Devon -- Devon McCormick, CFA Quantitative Consultant

Re: [Jprogramming] Dyadic "cut" with Boolean left argument

2020-04-24 Thread Devon McCormick
I must have been thinking of "key", e.g. 1 0 1 0 wrote: > I seem to recall there is a way to use the "cut" conjunction with a > Boolean left argument specifying partition boundaries but I cannot find > where this is mentioned on the J wiki. > > Is there a way to do this? > > Thanks, > > Devon

Re: [Jprogramming] Dyadic "cut" with Boolean left argument

2020-04-24 Thread Hauke Rehr
but in that case a boolean left argument will give a partition with at most two elements in general you need n different values for partitioning into n sets this way Am 24.04.20 um 23:45 schrieb Devon McCormick: I must have been thinking of "key", e.g. 1 0 1 0 wrote: I seem to recall the

Re: [Jprogramming] Dyadic "cut" with Boolean left argument

2020-04-24 Thread Joey K Tuttle
Or not ... 1 0 1 0 0 +/;.1 ]i. 5 1 9 > On 2020Apr 24, at 14:45, Devon McCormick wrote: > > I must have been thinking of "key", e.g. > 1 0 1 0 +---+---+ > |0 2|1 3| > +---+---+ > > > On Fri, Apr 24, 2020 at 5:37 PM Devon McCormick wrote: > >> I seem to recall there is a way to use th

Re: [Jprogramming] Factoring

2020-04-24 Thread 'Jon' via Programming
This is missing a few divisors. It seems Skip's original method would be difficult to beat. It's O(n) in time and space. You could improve space complexity by doing a simple loop, but as far as I can see there are no shortcuts, and the best way is to just "brute force" it. ⁣Sent from BlueMail ​

Re: [Jprogramming] Factoring

2020-04-24 Thread 'Mike Day' via Programming
Numbers of divisors below, not the divisors themselves... the thread had split! I was attempting to comment on Hauke Rehr’s post. M Sent from my iPad > On 24 Apr 2020, at 23:52, 'Jon' via Programming > wrote: > > This is missing a few divisors. It seems Skip's original method would be > diff

Re: [Jprogramming] Factoring

2020-04-24 Thread Devon McCormick
I found this one in my bag of tricks: allFactors=: */&>@{@((^ i.@>:)&.>/)@q:~&__ #,allFactors */p:i.10 1024 On Fri, Apr 24, 2020 at 7:15 PM 'Mike Day' via Programming < [email protected]> wrote: > Numbers of divisors below, not the divisors themselves... the thread had > split! I w