+ Reply to Thread
Results 1 to 15 of 15

Reverse calculation from doubling a number

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-07-2005
    Location
    England
    MS-Off Ver
    Office 2019 Enterprise
    Posts
    473

    Reverse calculation from doubling a number

    Totally useless title and I apologise for that!

    Hoping someone can help with this please?

    If I start with 1 and keep doubling 1, 2 , 4, 8, 16

    The total of all of those numbers is 31

    Is there an excel formula available for me to say, my start number is 1 and my end number is 16, tell me what the total is - and the formula would calculate 31.

    Thanks
    John

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Reverse calculation from doubling a number

    Try this

    =IF(MOD(LOG(endnum,2),1)=0,((2*startnum)^(LOG(endnum,2)+1))-1,NA())

  3. #3
    Forum Contributor ianh's Avatar
    Join Date
    11-19-2010
    Location
    Newcastle
    MS-Off Ver
    Excel 2010
    Posts
    114

    Re: Reverse calculation from doubling a number

    Quote Originally Posted by Bob Phillips View Post
    Try this

    =IF(MOD(LOG(endnum,2),1)=0,((2*startnum)^(LOG(endnum,2)+1))-1,NA())
    That excellent bob
    2+2=5 for extremely large values of 2.

  4. #4
    Forum Contributor ianh's Avatar
    Join Date
    11-19-2010
    Location
    Newcastle
    MS-Off Ver
    Excel 2010
    Posts
    114

    Re: Reverse calculation from doubling a number

    Example.xlsx

    Have a look at my example attached
    Put the numbers in the spaces next to start and end and the results should be correct in the total.

    Its a bit of a hashed work around and im sure there will be better solutions

  5. #5
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Reverse calculation from doubling a number

    Quote Originally Posted by ianh View Post
    Attachment 136009

    Have a look at my example attached
    Put the numbers in the spaces next to start and end and the results should be correct in the total.

    Its a bit of a hashed work around and im sure there will be better solutions
    Shouldn't the formula in B8 be

    =MATCH(B6,B2:U2,1)+1

  6. #6
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Reverse calculation from doubling a number

    In fact you might as well do it all in one formula in B7

    =SUM(A2:INDIRECT(ADDRESS(2,MATCH(B6,B2:U2,1)+1,3,1,)))

  7. #7
    Forum Contributor ianh's Avatar
    Join Date
    11-19-2010
    Location
    Newcastle
    MS-Off Ver
    Excel 2010
    Posts
    114

    Re: Reverse calculation from doubling a number

    Quote Originally Posted by Bob Phillips View Post
    Shouldn't the formula in B8 be

    =MATCH(B6,B2:U2,1)+1
    Yes, it should.

    I'd left the intermittent steps in to show how id got to the end product but yes it could be done in one.

    The advantage of this way would be if you didn't know the final "number" in the sequence. it will giv you the nearest matching value.
    You could probably add a cell to then tell you the remainder/correct highest possible value in the sequence.

  8. #8
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Reverse calculation from doubling a number

    Quote Originally Posted by ianh View Post
    Yes, it should.

    I'd left the intermittent steps in to show how id got to the end product but yes it could be done in one.

    The advantage of this way would be if you didn't know the final "number" in the sequence. it will giv you the nearest matching value.
    You could probably add a cell to then tell you the remainder/correct highest possible value in the sequence.
    I took a different approach, the final number has to be in the desired sequence .

  9. #9
    Forum Contributor ianh's Avatar
    Join Date
    11-19-2010
    Location
    Newcastle
    MS-Off Ver
    Excel 2010
    Posts
    114

    Re: Reverse calculation from doubling a number

    your solution in much more elegant bob, and probably what the OP is asking for.
    I'm learning as i go with excel and try to have a stab at the problems on here to help me learn.

  10. #10
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,453

    Re: Reverse calculation from doubling a number

    A couple of different ideas:

    1) Use the SERIESSUM(x,n,m,a) function. x=2, n=0, m=1, and a is an array of 1's as large as you need (a might be the hardest parameter to piece together). So =SERIESSUM(2,0,1,{1,1,1,1,1}) returns 31

    2) Because each term is going to be a power of 2, the problem could be expressed as a conversion from a binary number to a decimal number, which has its own function in Excel. =BIN2DEC(11111) returns 31.

  11. #11
    Forum Contributor ianh's Avatar
    Join Date
    11-19-2010
    Location
    Newcastle
    MS-Off Ver
    Excel 2010
    Posts
    114

    Re: Reverse calculation from doubling a number

    and today i have learnt three new things.
    never used seriessum before. Can you talk me through it in a little more detail MrShorty, if you have time.

  12. #12
    Forum Contributor
    Join Date
    07-07-2005
    Location
    England
    MS-Off Ver
    Office 2019 Enterprise
    Posts
    473

    Re: Reverse calculation from doubling a number

    Hi Bob, exactly what I was looking for thanks very much.

    Thanks for the other replies as well but the first reply did what I needed.

    Cheers!

    John

  13. #13
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Reverse calculation from doubling a number

    Quote Originally Posted by MrShorty View Post
    A couple of different ideas:

    1) Use the SERIESSUM(x,n,m,a) function. x=2, n=0, m=1, and a is an array of 1's as large as you need (a might be the hardest parameter to piece together). So =SERIESSUM(2,0,1,{1,1,1,1,1}) returns 31

    2) Because each term is going to be a power of 2, the problem could be expressed as a conversion from a binary number to a decimal number, which has its own function in Excel. =BIN2DEC(11111) returns 31.
    Nice ideas.

    As you say, it needs to cater for variable end numbers

    =SERIESSUM(2,0,1,ROW(INDIRECT("1:"&LOG(endnum,2)+1))^0)

    and

    =BIN2DEC(LEFT(REPT(1,99),LOG(endnum,2)+1))

    and it should also cater for a non valid end number.

  14. #14
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,453

    Re: Reverse calculation from doubling a number

    never used seriessum before. Can you talk me through it in a little more detail MrShorty, if you have time.
    I'm sure I could, but I don't use it that much myself, so everything I could say about it would pretty much be straight out of its help file. Basically, I use it mostly as a formula for building generic polynomials.

    I know the OP said he was satisfied with the first answer, but it was still an intriguing question. I just had a thought. Can't we show (maybe by induction) that sum(2^i) (for i=0 to n) = 2^(n+1) - 1? I can show this is true for n=0, and the example he uses (n=4) fits. (sum(2^0...2^4)=31=2^5-1 is true.)

    Since it has been a long time since I've tried a proof by induction, I gave it a shot, and I think I succeeded in proving this to be true. If we can adequately convince ourselves, then a formula we can use will be =2^(endpower+1)-1 if we want to give it n, or =2^(log(endnum,2)+1)-1 if we want the formula to figure n from the last number in the series.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1