Re: [Jprogramming] Quora Problem

2021-03-21 Thread 'Michael Day' via Programming
Back on the laptop,  running J903 rather than J701 which crashed on the less compendious iPad. Here's a somewhat speedier version of Bob Theriault's approach.  (I wasn't seeking to speed it up, but it wouldn't complete in reasonable time without a tweak or two.) rt =: 3 : 0 N  =. y n  =. >: i.

Re: [Jprogramming] Quora Problem

2021-03-21 Thread 'Mike Day' via Programming
OK... here’s what I should have sent earlier: 1. The required number includes all nn = n raised to n for which n are multiples of 3. 2. It also includes all nn for which n are already powers of 3 3. But we need to avoid double-counting nn for which both 1 & 2 apply. So: qprob =: 3 : 0 N =. y

Re: [Jprogramming] Quora Problem

2021-03-21 Thread 'Michael Day' via Programming
AH - neat but wrong problem!  Sorry. Now for breakfast M On 21/03/2021 09:16, 'Michael Day' via Programming wrote: I see Raul & Bob have replied while I was abed. SO,  before I look at their replies Not brute force,  but quite neat:    <.^(10%3)*^.10 14 For a smaller problem, check with

Re: [Jprogramming] Quora Problem

2021-03-21 Thread 'Michael Day' via Programming
I see Raul & Bob have replied while I was abed. SO,  before I look at their replies Not brute force,  but quite neat:    <.^(10%3)*^.10 14 For a smaller problem, check with 4^4:     +/(=<.)^&(%3)>:i.4^4 6 <.^(4%3)*^.4 6 QED? Cheers, Mike On 21/03/2021 02:57, Skip Cave wrote:

Re: [Jprogramming] Quora Problem

2021-03-21 Thread 'robert therriault' via Programming
I agree with 340, but this is the way that I approached it, n=. >: i. 1000 NB. set up list from 1 to 1000 _: 1000 NB. returns the prime exponents of 1000 3 0 3 (* _:) 1000 NB. returns the prime exponents of 1000^1000 3000 0 3000 (= <.)@:(3 %~ (* _:)) 1000 NB. divides the exponents

Re: [Jprogramming] Quora Problem

2021-03-21 Thread Raul Miller
Ah, good point, I should have thought about that. 1 was not the only one I needed to concern myself with. But I think it's this: +/(0=1|3%:n)+.0=3|n 340 I think we can agree that 32^32 isn't a cube 32^32x 1461501637330902918203684832716283019655932542976 32 is 2^5 and 5*32 is 160, but

Re: [Jprogramming] Quora Problem

2021-03-20 Thread 'robert therriault' via Programming
Thinking about it a bit further there are many more perfect cubes than that because integers such as 8^8 would not be captured by the %3 rule, but are still perfect cubes. My new answer which is certainly brute force. +/@:(=<.)@:(3&%:) n^n NB. take cube root of each n^n then set each

Re: [Jprogramming] Quora Problem

2021-03-20 Thread Raul Miller
If you meant, how do you find 1|3%:^~998x I don't have a better answer for you. You'd probably have to implement something like a newton-raphson root finder, I guess. Thanks, -- Raul On Sat, Mar 20, 2021 at 11:01 PM Raul Miller wrote: > >1++/0=3 | n > 334 > > p is a perfect cube if n

Re: [Jprogramming] Quora Problem

2021-03-20 Thread 'robert therriault' via Programming
Same reasoning as Raul, but quicker and uses less space because we make use of the structure of n (1 + [: <. 3 %~ {:) n 334 100 timespacex '1++//0=3 |n' 2.69e_5 11200 100 timespacex '(1 +[: <. 3 %~ {:) n' 5.5e_7 1728 Cheers, bob > On Mar 20, 2021, at 20:01, Raul Miller wrote: > >

Re: [Jprogramming] Quora Problem

2021-03-20 Thread Raul Miller
1++/0=3 | n 334 p is a perfect cube if n is 1 or if n is a multiple of 3. (1 is the only whole power of 3 which is not a multiple of 3.) FYI, -- Raul On Sat, Mar 20, 2021 at 10:58 PM Skip Cave wrote: > > How do you solve this problem using J (brute force) > n =. >: i. 1000 > p =. n^n >

[Jprogramming] Quora Problem

2021-03-20 Thread Skip Cave
How do you solve this problem using J (brute force) n =. >: i. 1000 p =. n^n How many p are perfect cubes? Skip Cave Cave Consulting LLC -- For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Quora problem

2019-10-28 Thread 'Rob Hodgkinson' via Programming
4|21|21| >> +--+--+--+ >> >> (as) and (as2) give only the (2!n+1) consecutive subsets, not all (2^n) >> subsets. >> >> >> R.E. Boss >> >> >>> -Oorspronkelijk bericht- >>> Van: Programming >>> Namen

Re: [Jprogramming] Quora problem

2019-10-28 Thread Raul Miller
+ > > (as) and (as2) give only the (2!n+1) consecutive subsets, not all (2^n) > subsets. > > > R.E. Boss > > > > -Oorspronkelijk bericht- > > Van: Programming > > Namens 'Rob Hodgkinson' via Programming > > Verzonden: zondag 27 oktober 2019 2

Re: [Jprogramming] Quora problem

2019-10-28 Thread R.E. Boss
Programming > Verzonden: zondag 27 oktober 2019 22:26 > Aan: jonghough via Programming > Onderwerp: Re: [Jprogramming] Quora problem > > Using RE’s and Henry’s suggestions, a slight generalisation to your #3 … > > as2=: ;(#\ <@<"1@([\) ]) ‘abcdef' > > Rob &

Re: [Jprogramming] Quora problem

2019-10-27 Thread 'Rob Hodgkinson' via Programming
;> >>> >>> >>> On Thu, Oct 24, 2019 at 12:30 PM R.E. Boss wrote: >>> >>>> Obviously the squares >2018 don't play any role whatsoever, so you can >>>> restrict yourself to %:2018 >>>> >>>>> a#~2018=>+/

Re: [Jprogramming] Quora problem

2019-10-27 Thread R.E. Boss
Festina lente, sed festina. > -Oorspronkelijk bericht- > Van: Programming > Namens 'Mike Day' via Programming > Verzonden: zondag 27 oktober 2019 17:50 > Aan: programm...@jsoftware.com > Onderwerp: Re: [Jprogramming] Quora problem > > Thanks. I haven’t got tim

Re: [Jprogramming] Quora problem

2019-10-27 Thread 'Mike Day' via Programming
gt; 2030 4 > 2051 7 > 2054 13 > > > R.E. Boss > > >> -Oorspronkelijk bericht- >> Van: Programming >> Namens 'Mike Day' via Programming >> Verzonden: donderdag 24 oktober 2019 11:08 >> Aan: programm...@jsoftware.com >> Onderwe

Re: [Jprogramming] Quora problem

2019-10-27 Thread R.E. Boss
985 2 2010 5 2018 12 2025 1 2030 3 2030 4 2051 7 2054 13 R.E. Boss > -Oorspronkelijk bericht- > Van: Programming > Namens 'Mike Day' via Programming > Verzonden: donderdag 24 oktober 2019 11:08 > Aan: programm...@jsoftware.com > Onderwerp: Re: [Jprogramming] Quor

Re: [Jprogramming] Quora problem

2019-10-27 Thread R.E. Boss
amming > Namens R.E. Boss > Verzonden: donderdag 24 oktober 2019 21:29 > Aan: programm...@jsoftware.com > Onderwerp: Re: [Jprogramming] Quora problem > >;(<@(''"_`# @.(2018=+/))\.)\2^~i.>.%:2018 > 12 > > > R.E. Boss > > > > -Oorspronkelijk b

Re: [Jprogramming] Quora problem

2019-10-25 Thread Skip Cave
%:2018 > > > > > >>a#~2018=>+/ each a=.;<@(<\.)\2^~i.>.%:2018 > > > 49 64 81 100 121 144 169 196 225 256 289 324 > > > > > > R.E. Boss > > > > > > > > > > -Oorspronkelijk bericht- > > > >

Re: [Jprogramming] Quora problem

2019-10-25 Thread R.E. Boss
See also https://www.wikiwand.com/en/Stigler%27s_law_of_eponymy R.E Boss > -Oorspronkelijk bericht- > Van: Programming > Namens R.E. Boss > Verzonden: vrijdag 25 oktober 2019 13:31 > Aan: programm...@jsoftware.com > Onderwerp: Re: [Jprogramming] Quora problem > &

Re: [Jprogramming] Quora problem

2019-10-25 Thread R.E. Boss
Good ideas have many parents. R.E. Boss > -Oorspronkelijk bericht- > Van: Programming > Namens Roger Hui > Verzonden: donderdag 24 oktober 2019 21:30 > Aan: programm...@jsoftware.com > Onderwerp: Re: [Jprogramming] Quora problem > > The "all prefixes o

Re: [Jprogramming] Quora problem

2019-10-24 Thread Roger Hui
>a#~2018=>+/ each a=.;<@(<\.)\2^~i.>.%:2018 > > 49 64 81 100 121 144 169 196 225 256 289 324 > > > > R.E. Boss > > > > > > > -Oorspronkelijk bericht- > > > Van: Programming > > > Namens Skip Cave > > > Verzonde

Re: [Jprogramming] Quora problem

2019-10-24 Thread R.E. Boss
;(<@(''"_`# @.(2018=+/))\.)\2^~i.>.%:2018 12 R.E. Boss > -Oorspronkelijk bericht- > Van: Programming > Namens R.E. Boss > Verzonden: donderdag 24 oktober 2019 19:30 > Aan: programm...@jsoftware.com > Onderwerp: Re: [Jprogramming] Quora problem > >

Re: [Jprogramming] Quora problem

2019-10-24 Thread Roger Hui
gt; > > > > > -Oorspronkelijk bericht- > > > Van: Programming > > > Namens Skip Cave > > > Verzonden: donderdag 24 oktober 2019 19:12 > > > Aan: programm...@jsoftware.com > > > Onderwerp: Re: [Jprogramming] Quora problem > > >

Re: [Jprogramming] Quora problem

2019-10-24 Thread Skip Cave
100 121 144 169 196 225 256 289 324 > > R.E. Boss > > > > -Oorspronkelijk bericht- > > Van: Programming > > Namens Skip Cave > > Verzonden: donderdag 24 oktober 2019 19:12 > > Aan: programm...@jsoftware.com > > Onderwerp: Re: [Jprogramming] Qu

Re: [Jprogramming] Quora problem

2019-10-24 Thread R.E. Boss
amens Skip Cave > Verzonden: donderdag 24 oktober 2019 19:12 > Aan: programm...@jsoftware.com > Onderwerp: Re: [Jprogramming] Quora problem > > To me it seems that R. E. Boss provided the simplest approach. > Don't know about efficiency, but the results appear instantly: > > >a

Re: [Jprogramming] Quora problem

2019-10-24 Thread Skip Cave
To me it seems that R. E. Boss provided the simplest approach. Don't know about efficiency, but the results appear instantly: >a#~2018=>+/ each a=.;<@(<\.)\2^~i.100 49 64 81 100 121 144 169 196 225 256 289 324 Skip -- For

Re: [Jprogramming] Quora problem

2019-10-24 Thread 'Mike Day' via Programming
ual to (4&$.$.) > > > R.E. Boss > > >> -Oorspronkelijk bericht- >> Van: Programming >> Namens 'Mike Day' via Programming >> Verzonden: donderdag 24 oktober 2019 11:08 >> Aan: programm...@jsoftware.com >> Onderwerp: Re: [Jprogrammi

Re: [Jprogramming] Quora problem

2019-10-24 Thread 'Rob Hodgkinson' via Programming
Somewhat clumsy, as uses each for the loop. The key idiom is to use subarrays to iterate a window over the vector … x u;.3 y So to see subarrays of various lengths … here length 8 in i.10 (there are 3) and then length 9 in i.10 (there are 2) … the 2 results (for length 8 and length 9

Re: [Jprogramming] Quora problem

2019-10-24 Thread R.E. Boss
Your ixbin is equal to (4&$.$.) R.E. Boss > -Oorspronkelijk bericht- > Van: Programming > Namens 'Mike Day' via Programming > Verzonden: donderdag 24 oktober 2019 11:08 > Aan: programm...@jsoftware.com > Onderwerp: Re: [Jprogramming] Quora problem > > (I

Re: [Jprogramming] Quora problem

2019-10-24 Thread 'Mike Day' via Programming
(I see RE Boss has just posted, while I was drafting - sorry if it's the same!) I thought to exploit the property that S3(n) = sum i^2, i <: n, is n(n+1)(2n+1)%6 but solving S(n) - S(m) = 2018 isn't that easy! Anyway, we could define S3  =:  6 <.@%~ (* (>: * >:@+:)) but as we need a string

Re: [Jprogramming] Quora problem

2019-10-24 Thread R.E. Boss
> -Oorspronkelijk bericht- > Van: Programming > Namens Skip Cave > Verzonden: donderdag 24 oktober 2019 08:36 (...) > > Is there a way to do this search without explicit looping? > > > Skip > Yes. Consider <@(<\.)\i.5

[Jprogramming] Quora problem

2019-10-24 Thread Skip Cave
I occasionally try to solve Quora math problems to polish my J skills. Here's a problem that * "The integer 2018 can be written uniquely as the sum of consecutive squared integers. How many squares does the sum contain?"* a=.2^~i.100 NB. Find how many consecutive squared integers it takes to

Re: [Jprogramming] Quora problem

2019-04-17 Thread 'Mike Day' via Programming
Probably why I continue having trouble solving those Project Euler problems involving partitions directly or indirectly... not to mention most other recent PE problems! Cheers, Mike Please reply to mike_liz@tiscali.co.uk. Sent from my iPad > On 17 Apr 2019, at 14:16, Roger Hui

Re: [Jprogramming] Quora problem

2019-04-17 Thread Devon McCormick
The late Howard Peelle covered this problem in depth: https://code.jsoftware.com/wiki/User:Devon_McCormick/HAP_AIP . There is also a general page on this problem: https://code.jsoftware.com/wiki/Essays/AllPartitions . On Wed, Apr 17, 2019 at 9:17 AM Roger Hui wrote: > An amusing note about the

Re: [Jprogramming] Quora problem

2019-04-17 Thread Roger Hui
An amusing note about the memo operator and partition calculations. In *A History of APL in 50 Functions *, chapter 16, it is estimated that computing pn 200 without memo, would take 4.15407e34 years. On Wed, Apr 17, 2019 at 1:01 AM 'Mike Day' via Programming

Re: [Jprogramming] Quora problem

2019-04-17 Thread 'Mike Day' via Programming
Over breakfast just now,  I've spotted two typos in my msg, below. It said "Sent from my iPad" which explains the two gratuitous capitalisations of " i.  " below - they should have been " i.-3 " and " i.7 " While I have the opportunity,  it's perhaps worth pointing out that the other J wiki

Re: [Jprogramming] Quora problem

2019-04-16 Thread Nimp O
. 7 h 100 108869 From: Programming on behalf of 'Skip Cave' via Programming Sent: Tuesday, April 16, 2019 5:13 PM To: programm...@jsoftware.com Subject: [Jprogramming] Quora problem I ran across this problem on Quora... How many ways can 100 be written as a s

Re: [Jprogramming] Quora problem

2019-04-16 Thread 'Mike Day' via Programming
I’ve worked up a number of variant explicit partition functions. One of these is mpart; m mpart n yields all m-partitions of n, with no zeros, but allowing repeats. So, for example, using a smallish example: 3 mpart 7. NB. there are four 3-partitions of 7 3 2 2 3 3 1 4 2 1 5 1 1

Re: [Jprogramming] Quora problem

2019-04-16 Thread Roger Hui
If no repeats are permitted, the largest number in the sum would be 79 and the others would be 21 = +/ 1 2 3 4 5 6. Work down from 79. The memo operator M. would come in handy, I expect. From your description, it is not required to exhibit the sums, just to calculate the number of sums, so you

[Jprogramming] Quora problem

2019-04-16 Thread 'Skip Cave' via Programming
I ran across this problem on Quora... How many ways can 100 be written as a sum of 7 ordered positive integers? (no repeats) The obvious brute force approach in J would be: odo=: #: i.@(*/) NB. Odometer verb #b=.~./:~"1 a#~100=+/"1 a=.odo 7#100 |limit error: odo | #b=:~./:~"1 a#~100=+/"1 a=:

Re: [Jprogramming] Quora Problem

2018-08-16 Thread 'Mike Day' via Programming
I was wrong in my first attempt to generalise the problem. I’d said: a + b * i, where a and b are integer scalars, and i is an integer vector, i0,i1,i2..., which is correct, but not sufficient. The Quora problem also requires, or perhaps just implies, that i’s elements are

Re: [Jprogramming] Quora Problem

2018-08-15 Thread Raul Miller
Yes, well... Consider this sequence: 7541 5333 3377 11993 20 Thanks, — Raul On Wednesday, August 15, 2018, Jose Mario Quintana < jose.mario.quint...@gmail.com> wrote: > > I do not see any attempt in the question at generalizing—so technically > the > > answer would be a number. > > In

Re: [Jprogramming] Quora Problem

2018-08-15 Thread Jose Mario Quintana
> Sorry for the confusion, I was also confused by the description of the problem (as is implied in my first post to this thread). :) On Wed, Aug 15, 2018 at 6:12 AM, 'Mike Day' via Programming < programm...@jsoftware.com> wrote: > Yes, I think it was ok to generalise, but I’d missed what

Re: [Jprogramming] Quora Problem

2018-08-15 Thread 'Mike Day' via Programming
Yes, I think it was ok to generalise, but I’d missed what they meant by proportionality. So, if I define a different quadruplet, q=: 6 + 7*1 2 5 10 where 1:2 = 5:10, Jose’s function works fine: (-/ .* % -/ .+)@:(2 2&$) q 6 which is the required offset. fwiw, dgcd q. NB. gcd

Re: [Jprogramming] Quora Problem

2018-08-14 Thread Raul Miller
I do not see any attempt in the question at generalizing—so technically the answer would be a number. But I expect that easy to describe (but accurate) general approaches would fit right in... Thanks, — Raul On Tuesday, August 14, 2018, Jose Mario Quintana < jose.mario.quint...@gmail.com>

Re: [Jprogramming] Quora Problem

2018-08-14 Thread Jose Mario Quintana
After I saw your message I searched for the particular Quora problem and this is what I found, https://www.quora.com/What-number-must-be-subtracted-from-21-38-55-and-106-each-so-that-the-remainders-technically-differences-are-proportional It seems to me that the shape of the array is restricted

Re: [Jprogramming] Quora Problem

2018-08-14 Thread 'Mike Day' via Programming
It should work on arrays of the form a + b * i, where a and b are integer scalars, and i is an integer vector. So, if q=: 6 + 7*1 2 5 11 23, applying this function yields (-/ .* % -/ .+)@:(2 2&$) q 7.4 I think you need instead something like Difference’s greatest common divisor,

Re: [Jprogramming] Quora Problem

2018-08-14 Thread Jose Mario Quintana
That post did not travel well; trying again, (-/ .* % -/ .+)@:(2 2&$)21 38 55 106 4 On Tue, Aug 14, 2018 at 5:30 PM, Jose Mario Quintana < jose.mario.quint...@gmail.com> wrote: > > A direct solution without the assumption that the solution is a whole > number > > . > > . > > . > > (-/ .*

Re: [Jprogramming] Quora Problem

2018-08-14 Thread Jose Mario Quintana
A direct solution without the assumption that the solution is a whole number . . . (-/ .* % -/ .+)@:(2 2&$) 21 38 55 106 4 On Tue, Aug 14, 2018 at 1:37 PM, Jose Mario Quintana < jose.mario.quint...@gmail.com> wrote: > A brute-force approach assuming that the solution is a whole number, and

Re: [Jprogramming] Quora Problem

2018-08-14 Thread Jose Mario Quintana
A brute-force approach assuming that the solution is a whole number, and I am understanding the problem correctly, follows after a few blank lines... ((0 = -/ .*@:(2 2$21 38 55 106 - ])"0) # ]) i.111 4 Checking, -/ .* (2 2$21 38 55 106 - 4) 0 Indeed, 17 is a

Re: [Jprogramming] Quora Problem

2018-08-14 Thread 'Mike Day' via Programming
Spot the non-deliberate editing error! M On 14/08/2018 16:16, Mike Day wrote: How about these snapshots? q =: 21, 38, 55, 106    }.+/\inv q NB. 1st differences 21 17 17 51    +./}.+/\inv q NB. gcd of 1st diffs 17 NB. or    2 -/\ q _17 _17 _51    +./2 -/\ q 17    17|q  NB. So,

Re: [Jprogramming] Quora Problem

2018-08-14 Thread 'Mike Day' via Programming
How about these snapshots? q =: 21, 38, 55, 106    }.+/\inv q NB. 1st differences 21 17 17 51    +./}.+/\inv q NB. gcd of 1st diffs 17 NB. or    2 -/\ q _17 _17 _51    +./2 -/\ q 17    17|q  NB. So, what is the required offset? 4 4 4 4    17%~ q-4 NB. what are the required

Re: [Jprogramming] Quora Problem

2018-08-14 Thread Don Guinn
Brute force. >:I.1=(#@~.)"1(>:i.21)|/21 38 55 106 1 17 17|21 38 55 106 4 4 4 4 On Tue, Aug 14, 2018 at 12:08 AM Skip Cave wrote: > Attempting to solve the following Quora problem: > > What number must be subtracted from 21, 38, 55, and 106 each so that the > remainders (technically

[Jprogramming] Quora Problem

2018-08-14 Thread Skip Cave
Attempting to solve the following Quora problem: What number must be subtracted from 21, 38, 55, and 106 each so that the remainders (technically differences) are proportional? Subtract the integers 0-9 from all four integers in the problem. Then find the prime factors of each set of four

Re: [Jprogramming] Quora Problem

2018-05-20 Thread Don Guinn
Thank you, Raul. I stand corrected. On Sun, May 20, 2018 at 6:27 PM, Raul Miller wrote: > Where do you get the requirement that the numbers must be unique? > > The problem stated here was: > > "How many distinct triplets have a sum of 1,000,000 (provided all numbers > are

Re: [Jprogramming] Quora Problem

2018-05-20 Thread Don Guinn
Yes, I had a bug in my previous definition for triplescount. Stupid. Should have checked more before speaking. But As I understand the problem, the numbers in each triple should be unique. Looking at has several triples with duplicate numbers. t #~ 3=#&>t

Re: [Jprogramming] Quora Problem

2018-05-20 Thread S H Makdisi
There seems to be a typo in Roger's solution; +/ <.@(%&2)@<: n - 3*i.<.n-3 [ n=: 1e2 _2207 The last '-' in the line should be division, '%' +/ <.@(%&2)@<: n - 3*i.<.n%3 [ n=: 1e2 883 +/ <.@(%&2)@<: n - 3*i.<.n%3 [ n=: 1e4 833 +/ <.@(%&2)@<: n - 3*i.<.n%3 [ n=: 1e6 833

Re: [Jprogramming] Quora Problem

2018-05-20 Thread Skip Cave
Raul, I can follow most of your solution, and it looks right. What is bothering me is that I cut & pasted Roger's solution into my JQt and got a different answer: Roger's post: +/ <.@(%&2)@<: n - 3*i.<.n-3 [ n=: 1e2 833 +/ <.@(%&2)@<: n - 3*i.<.n-3 [ n=: 1e3 8 +/ <.@(%&2)@<: n -

Re: [Jprogramming] Quora Problem

2018-05-20 Thread Raul Miller
If you are looking for a way of verifying Henry's and Roger's approaches, perhaps this: A partition of three integers summing to X can be broken down into an integer Y and a partition of two integers Z. We want X=Y+Z and we want both integers in Z to not exceed Y. If we ignore the Y constraint,

Re: [Jprogramming] Quora Problem

2018-05-20 Thread Skip Cave
I can follow Henry's clever solution. 0 ": 6 %~ (-: 98 * 99) + 3 * -: 98 833 I tried to replicate Roger's partition approach, and ran into memory issues. Roger must have more memory on his machine: pnk 4 : 0"0 n=. 0>.x [ k=. y if. 1>:n<.k do. x: (0

Re: [Jprogramming] Quora Problem

2018-05-20 Thread Henry Rich
Taking advantage of the fact that thepartitions have only 3 elements. If the first number is i, the second number can be anything from 1 to 99-iand the third number is then uniquely fixed. Since ican run from 1 to 98, the total number of such choices is (-: 98 * 99). But

Re: [Jprogramming] Quora Problem

2018-05-20 Thread Henry Rich
Looking at Don's first paragraph, it seems he is trying to generate triplets of unique numbers rather than unique triplets of numbers.  I haven't looked at the code. Henry Rich On 5/20/2018 10:24 AM, Roger Hui wrote: There is a mistake in your derivation somewhere, because: Using the code

Re: [Jprogramming] Quora Problem

2018-05-20 Thread Roger Hui
There is a mistake in your derivation somewhere, because: Using the code in http://code.jsoftware.com/wiki/Essays/Partitions : t=: part 10 $t 42 7 6$t ┌───┬───┬─┬───┬─┬───┐ │10 │9 1│8 2 │8 1

Re: [Jprogramming] Quora Problem

2018-05-20 Thread Don Guinn
​Couldn't sleep last night so as often, worked on problems. Never saw the actually Quora problem, but as I understand it it wants all unique positive integers that add to 100. So far it looks like people are trying to generate all possible number triples and keeping only those that add to

Re: [Jprogramming] Quora Problem

2018-05-20 Thread Roger Hui
> sets of three positive integers that sum to 1,000,000 That's a partition of size 3 (of 1e6). http://en.wikipedia.org/wiki/Partition_(number_theory) On Sat, May 19, 2018 at 11:17 PM, Skip Cave wrote: > The problem is to find and count all of the unique sets of

Re: [Jprogramming] Quora Problem

2018-05-20 Thread Skip Cave
ill try later. > > > -------- > On Sun, 5/20/18, Skip Cave <s...@caveconsulting.com> wrote: > > Subject: [Jprogramming] Quora Problem > To: "programm...@jsoftware.com" <programm...@jsoftware.com> > Date: Sunday, May 20, 2018, 5

Re: [Jprogramming] Quora Problem

2018-05-19 Thread Roger Hui
The number of triplets is the number of size 3 partitions of 1e6. Using the function in http://code.jsoftware.com/wiki/Essays/Partitions#Partitions_with_k_Parts pnk=: 4 : 0 " 0 n=. 0>.x [ k=. y if. 1>:n<.k do. x: (0

Re: [Jprogramming] Quora Problem

2018-05-19 Thread 'Jon Hough' via Programming
to modify it into an iterative approach, but will try later. On Sun, 5/20/18, Skip Cave <s...@caveconsulting.com> wrote: Subject: [Jprogramming] Quora Problem To: "programm...@jsoftware.com" <programm...@jsoftware.com> Date: Sunday, M

Re: [Jprogramming] Quora Problem

2018-05-19 Thread james faure
tware.com> Sent: Sunday, May 20, 2018 1:06:09 AM To: programm...@jsoftware.com Subject: Re: [Jprogramming] Quora Problem This is more math, than eager/lazy evaluation issue. Though if lazy (programmer), you might use solution for 10 and 100 to guess at 1M. It's an extention of unique pairs

Re: [Jprogramming] Quora Problem

2018-05-19 Thread 'Pascal Jasmin' via Programming
est of the triplets, for eacch "largest triplet" From: Henry Rich <henryhr...@gmail.com> To: programm...@jsoftware.com Sent: Saturday, May 19, 2018 6:41 PM Subject: Re: [Jprogramming] Quora Problem I don't think it's the interpreter's strategy that

Re: [Jprogramming] Quora Problem

2018-05-19 Thread Henry Rich
behalf of Skip Cave <s...@caveconsulting.com> Sent: Saturday, May 19, 2018 10:43 PM To: programm...@jsoftware.com Subject: [Jprogramming] Quora Problem Another interesting quora problem: How many distinct triplets have a sum of 1,000,000 (provided all numbers are integers and are posit

Re: [Jprogramming] Quora Problem

2018-05-19 Thread james faure
loop, which hurts. From: Programming <programming-boun...@forums.jsoftware.com> on behalf of Skip Cave <s...@caveconsulting.com> Sent: Saturday, May 19, 2018 10:43 PM To: programm...@jsoftware.com Subject: [Jprogramming] Quora Problem Another inter

[Jprogramming] Quora Problem

2018-05-19 Thread Skip Cave
Another interesting quora problem: How many distinct triplets have a sum of 1,000,000 (provided all numbers are integers and are positive)?

Re: [Jprogramming] Quora Problem

2018-04-09 Thread Raul Miller
I think I'd do it like this: #10#.(#~ 36=*/@|:) 1+(6#3)#:i.3^6 90 In other words, generate all 729 possibilities as lists of digits and keep those whose product is 36. That said, technically we don't actually need to combine them into single numbers: #(#~ 36=*/@|:) 1+(6#3)#:i.3^6 90

Re: [Jprogramming] Quora Problem

2018-04-09 Thread 'Mike Day' via Programming
, Regarding point 1:, that was me, Jon Hough. On Mon, 4/9/18, 'Mike Day' via Programming <programm...@jsoftware.com> wrote: Subject: Re: [Jprogramming] Quora Problem To: programm...@jsoftware.com Date: Monday, April 9, 2018, 5:33 PM Hell

Re: [Jprogramming] Quora Problem

2018-04-09 Thread 'Mike Day' via Programming
Hello Skip Points: 0: is this the same Quora which keeps sending me e-messages with headers such as "What are the best things for Oxford students to do on weekends?" "What is the best and most prestigious English university nowadays? Oxford? Cambridge?" - both received yesterday/today! 1: A

Re: [Jprogramming] Quora Problem

2018-04-09 Thread 'Mike Day' via Programming
Sorry - pressed send instead of paste! Trying again: = Hello Skip Points: 0: is this the same Quora which keeps sending me e-messages with headers such as "What are the best things for Oxford students to do on weekends?" "What

Re: [Jprogramming] Quora Problem

2018-04-09 Thread 'Jon Hough' via Programming
Hi Mike, Regarding point 1:, that was me, Jon Hough. On Mon, 4/9/18, 'Mike Day' via Programming <programm...@jsoftware.com> wrote: Subject: Re: [Jprogramming] Quora Problem To: programm...@jsoftware.com Date: Monday, April 9, 2018, 5

Re: [Jprogramming] Quora Problem

2018-04-09 Thread 'Jon Hough' via Programming
- (3^4) + (3*3*3*2) + (3*3*2*3) + (3*2*2*3) + (3*2*2) 492 On Mon, 4/9/18, 'Jon Hough' via Programming <programm...@jsoftware.com> wrote: Subject: Re: [Jprogramming] Quora Problem To: programm...@jsoftware.com Date: Monday, April 9, 2018, 3

Re: [Jprogramming] Quora Problem

2018-04-09 Thread 'Jon Hough' via Programming
Not the fastest method... f=: -.@:(1)@:(#@:~."1)@(3&(]\))`0:@.(1@:('0456789'))@:": D=: 1e5 + i. 1e6 - 1e5 +/ f"0 D 492 On Mon, 4/9/18, Skip Cave <s...@caveconsulting.com> wrote: Subject: [Jprogramming] Quora Problem To: &

[Jprogramming] Quora Problem

2018-04-08 Thread Skip Cave
Here's a fun math challenge on Quora: Find the number of 6-digit numbers made up of the digits 1, 2, and 3 which have no digit recurring three or more times, consecutively? The link to my answer on Quora is: https://goo.gl/BzBDQe Skip Cave Cave Consulting LLC

Re: [Jprogramming] Quora problem

2017-08-15 Thread Raul Miller
In this case? I'd probably use ;: but for the general case it's probably safer to use <"1 (if I understand your intent properly). Thanks, -- Raul On Tue, Aug 15, 2017 at 2:40 PM, Skip Cave wrote: > How could you box each string? > > Skip Cave > Cave Consulting LLC >

Re: [Jprogramming] Quora problem

2017-08-15 Thread Skip Cave
How could you box each string? Skip Cave Cave Consulting LLC On Tue, Aug 15, 2017 at 12:07 PM, Raul Miller wrote: > I'd meet that specification like this: > > require'stats' > perms=: A.~ ! > > gen=:4 :0 > x{~,/(perms y){"1/y comb #x > ) > > But note that the result

Re: [Jprogramming] Quora problem

2017-08-15 Thread 'Pascal Jasmin' via Programming
st 15, 2017 1:47 PM Subject: Re: [Jprogramming] Quora problem Completely agree with Skip as I'm also at the beginning of the learning curve. One of the idioms that really amazed me is the way Raul does the selection of the combinations with the permutations using the table verb: (perms 3) {&q

Re: [Jprogramming] Quora problem

2017-08-15 Thread Jimmy Gauvin
Completely agree with Skip as I'm also at the beginning of the learning curve. One of the idioms that really amazed me is the way Raul does the selection of the combinations with the permutations using the table verb: (perms 3) {"1 /1+3 comb 9 I was working along similar lines with this

Re: [Jprogramming] Quora problem

2017-08-15 Thread Raul Miller
I'd meet that specification like this: require'stats' perms=: A.~ ! gen=:4 :0 x{~,/(perms y){"1/y comb #x ) But note that the result format is different. Thanks, -- Raul On Tue, Aug 15, 2017 at 12:58 PM, Skip Cave wrote: > I believe that the general case would

Re: [Jprogramming] Quora problem

2017-08-15 Thread Skip Cave
I believe that the general case would be: Design a J verb that will generate all possible unique strings of a specific fixed length using only specified set of symbols, where each generated string has no repeated symbols. x gen y Where x specifies a set of symbols (characters, numbers), and

Re: [Jprogramming] Quora problem

2017-08-15 Thread Don Guinn
For really big problems you could go to a larger base than 10 like hexadecimal. Or even bigger using more letters. On Tue, Aug 15, 2017 at 10:10 AM, Raul Miller wrote: > To compare them for equality you need to sort them. > > However, the task was to generate the

Re: [Jprogramming] Quora problem

2017-08-15 Thread Raul Miller
To compare them for equality you need to sort them. However, the task was to generate the integers. (If the example list of numbers was a part of the specification then we probably should not be considering seven digit integers as relevant.) Thanks, -- Raul On Tue, Aug 15, 2017 at 10:37 AM,

Re: [Jprogramming] Quora problem

2017-08-15 Thread 'Mike Day' via Programming
are.com] On Behalf Of 'Mike Day' via Programming Sent: maandag 14 augustus 2017 22:01 To: programm...@jsoftware.com Subject: Re: [Jprogramming] Quora problem Yes, much better! cf my suggestion a few days ago, and another constructive one using tap and comb, q_tap_comb : ... time & space for Ski

Re: [Jprogramming] Quora problem

2017-08-15 Thread Arie Groeneveld
To compare both you need to do the following: 10 ts 'R=./:~,10#.(perms 7){"1/1+7 comb 9' 0.0288779 2.4132e7 10 ts 'G=.,10 #. ((],"1 0 -."1)^:6 ,.)1+i.9' 0.0258377 2.30737e7 R-:G 1 Looks like a draw. Op 15-08-17 om 16:16 schreef Raul Miller: I cannot comment on elegance, but I can

Re: [Jprogramming] Quora problem

2017-08-15 Thread Raul Miller
: Programming [mailto:programming-boun...@forums.jsoftware.com] >> On Behalf Of 'Mike Day' via Programming >> Sent: maandag 14 augustus 2017 22:01 >> To: programm...@jsoftware.com >> Subject: Re: [Jprogramming] Quora problem >> >> Yes, much better! >>

Re: [Jprogramming] Quora problem

2017-08-15 Thread R.E. Boss
t; Sent: maandag 14 augustus 2017 22:01 > To: programm...@jsoftware.com > Subject: Re: [Jprogramming] Quora problem > > Yes, much better! > > cf my suggestion a few days ago, and another constructive one using tap and > comb, q_tap_comb : > > ... time & sp

Re: [Jprogramming] Quora problem

2017-08-15 Thread Skip Cave
After studying the many diverse methods that were put forward to solve my "3-integers, no repeats or zeros" problem, I find I have learned quite a few new J idioms, as well as some new uses for familiar primitives. Thanks all so much for your efforts in all the solutions. Quora has hundreds of

Re: [Jprogramming] Quora problem

2017-08-14 Thread 'Mike Day' via Programming
Sorry for my poor coding of your suggestion! Either I hadn't spotted your own code, or perhaps I'd forgotten you'd posted it. Mike On 14/08/2017 21:21, Raul Miller wrote: If you are going to time one of my implementations, I'd really prefer you time the second one rather than the first

Re: [Jprogramming] Quora problem

2017-08-14 Thread 'Mike Day' via Programming
Yes, much better! cf my suggestion a few days ago, and another constructive one using tap and comb, q_tap_comb : ... time & space for Skip's original problem: ts'10 #.(,/@:(],"1 0 -."1)^:2 ,.)>:i.9'NB. AG 0.000120949 40448 ts'10#.(#~(-:~.)"1) >: 9#.inv i. 9^3' NB. MD 0.000774292

Re: [Jprogramming] Quora problem

2017-08-14 Thread Arie Groeneveld
My version of variations (without repetitions) : 10 #. (,/@:(],"1 0 -."1)^:2 ,.)1+i.9 More general: (3) 4 :'y,/@:(],"1 0 -."1)^:(x-1) ,.y' 'abcd' Op 12-08-17 om 11:16 schreef Skip Cave: How can I use J to generate all the possible 3-digit integers that can be constructed using the digits

Re: [Jprogramming] Quora problem

2017-08-12 Thread 'Mike Day' via Programming
-- On Sat, 8/12/17, 'Pascal Jasmin' via Programming <programm...@jsoftware.com> wrote: Subject: Re: [Jprogramming] Quora problem To: "programm...@jsoftware.com" <programm...@jsoftware.com> Date: Saturday, August 12, 2017, 8:33 PM a gen

  1   2   >