Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Trips Date: Fri, 19 Mar 2010 18:48:02 +0000 (UTC) Organization: Iowa State University Lines: 30 Message-ID: <ho0gt2$cv$1@fred.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: webapp-02-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1269024482 415 172.30.248.37 (19 Mar 2010 18:48:02 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Fri, 19 Mar 2010 18:48:02 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 2186458 Xref: news.mathworks.com comp.soft-sys.matlab:618341 I am needing help with a problem. I posted this yesterday, but without my code I had so far. The problem is this: given a positive integer n, find all unique combination's of 3 positive integers whose product is n. For example, n=24, you have six triplets: 1 1 24 1 2 12 1 3 8 1 4 6 2 2 6 2 3 4 All of these sets of numbers multiply to 24. None of them repeat. Here is the code I have so far: n = input('Please enter a positive integer: '); for i = 1:n for j = 1:n for k = 1:n if i*j*k == n disp([i,j,k]); end end end end This displays only the combination's whose product is n. I can't seem to figure out how to display only the unique triplets. I have tried using unique( ) but it does some weird stuff to my results. Could anybody give me some help on this? Thanks!! Shaun