All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
Continued Division and Parentheses Crossed Positive Integer Determination Poser (Posted on 2023-08-16) Difficulty: 3 of 5
Consider this expression:
1/2/3/4/5/6
Using one or more pairs of open and closed parentheses, that is: (), determine the total number of resulting distinct positive integers.

See The Solution Submitted by K Sengupta    
Rating: 5.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solution Comment 2 of 2 |
clearvars,clc
global src stackN stackS  ct 
ct=0;
src=1:6;
stackN=[];
stackS=string.empty;
addon();
ct

function addon()
global src stackN stackS  ct 
  if length(stackN)>1
     ssN=stackN; ssrc=src; ssS=stackS;
    stackN(1)=stackN(2)/stackN(1);
    stackN(2:end-1)=stackN(3:end);
    stackN(end)=[];
    if length(char(stackS(1)))>1
      if length(char(stackS(2))) > 1
        stackS(1)=['(' char(stackS(2)) ')/(' char(stackS(1)) ')'];
      else
        stackS(1)=[  char(stackS(2)) '/(' char(stackS(1)) ')'];
      end
    else
      if length(char(stackS(2))) > 1
        stackS(1)=['(' char(stackS(2)) ')/' char(stackS(1)) ];
      else
        stackS(1)=[  char(stackS(2)) '/' char(stackS(1)) ];
      end
    end
    stackS(2:end-1)=stackS(3:end);
    stackS(end)=[];
    if isempty(src) && length(stackS)==1
      fprintf('%-30s %17.14f\n',stackS,stackN)
      ct=ct+1;
    else
     
      addon
     
    end    
     stackN=ssN; src=ssrc; stackS=ssS;
  end
  if ~isempty(src)
    ssN=stackN; ssrc=src; ssS=stackS;
    stackN(2:end+1)=stackN(1:end);
    stackS(2:end+1)=stackS(1:end);
    stackN(1)=src(1); src(1)=[];
    stackS(1)=string(stackN(1));
    
    addon

    stackN=ssN; src=ssrc; stackS=ssS;
  end 
end


((((1/2)/3)/4)/5)/6             0.00138888888889
(((1/2)/3)/4)/(5/6)             0.05000000000000
(((1/2)/3)/(4/5))/6             0.03472222222222
((1/2)/3)/((4/5)/6)             1.25000000000000
((1/2)/3)/(4/(5/6))             0.03472222222222
(((1/2)/(3/4))/5)/6             0.02222222222222
((1/2)/(3/4))/(5/6)             0.80000000000000
((1/2)/((3/4)/5))/6             0.55555555555556
(1/2)/(((3/4)/5)/6)            20.00000000000000
(1/2)/((3/4)/(5/6))             0.55555555555556
((1/2)/(3/(4/5)))/6             0.02222222222222
(1/2)/((3/(4/5))/6)             0.80000000000000
(1/2)/(3/((4/5)/6))             0.02222222222222
(1/2)/(3/(4/(5/6)))             0.80000000000000
(((1/(2/3))/4)/5)/6             0.01250000000000
((1/(2/3))/4)/(5/6)             0.45000000000000
((1/(2/3))/(4/5))/6             0.31250000000000
(1/(2/3))/((4/5)/6)            11.25000000000000
(1/(2/3))/(4/(5/6))             0.31250000000000
((1/((2/3)/4))/5)/6             0.20000000000000
(1/((2/3)/4))/(5/6)             7.20000000000000
(1/(((2/3)/4)/5))/6             5.00000000000000
1/((((2/3)/4)/5)/6)           180.00000000000000
1/(((2/3)/4)/(5/6))             5.00000000000000
(1/((2/3)/(4/5)))/6             0.20000000000000
1/(((2/3)/(4/5))/6)             7.20000000000000
1/((2/3)/((4/5)/6))             0.20000000000000
1/((2/3)/(4/(5/6)))             7.20000000000000
((1/(2/(3/4)))/5)/6             0.01250000000000
(1/(2/(3/4)))/(5/6)             0.45000000000000
(1/((2/(3/4))/5))/6             0.31250000000000
1/(((2/(3/4))/5)/6)            11.25000000000000
1/((2/(3/4))/(5/6))             0.31250000000000
(1/(2/((3/4)/5)))/6             0.01250000000000
1/((2/((3/4)/5))/6)             0.45000000000000
1/(2/(((3/4)/5)/6))             0.01250000000000
1/(2/((3/4)/(5/6)))             0.45000000000000
(1/(2/(3/(4/5))))/6             0.31250000000000
1/((2/(3/(4/5)))/6)            11.25000000000000
1/(2/((3/(4/5))/6))             0.31250000000000
1/(2/(3/((4/5)/6)))            11.25000000000000
1/(2/(3/(4/(5/6))))             0.31250000000000
ct =
    42

Of the 42 possibilities, 4 are integers: 20, 5, 180 and 5 again. Since we want distinct integers, there are 3 of these: 5, 20 and 180.

  Posted by Charlie on 2023-08-16 14:03:26
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (9)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information