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 1e6.
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
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 in
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 thi
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 wrote:
> Taking advant
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, t
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 - 3*i.<.
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
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
+-+-+-+-+-+-+-
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 integers and are positive)?"
The quora statement of the issue is slightly different, but
substantially the same:
"How many
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 integers and are positi
11 matches
Mail list logo