Brain Teasers

Sorry, the expression for n is wrong:

n = (((3 + 8<SUP>0.5</SUP>)<SUP>t</SUP> + (3 - 8<SUP>0.5</SUP>)<SUP>t</SUP>)/2-1)/2

The formula is, however, right and so are the (m,n) pairs in the table.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hi Pedro,

How did you come up with the formula?

A friend of mine came up with a sort of a brute force method... (A1 denotes the upper limit of numbers it will check)

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> Test()<br>    left1 = 0<br>    right1 = 0<br>    a = 0<br>    b = 0<br>    c = 0<br>    result = 0<br>    limit1 = Range("A1").Value<br>    <SPAN style="color:#00007F">For</SPAN> a = Start <SPAN style="color:#00007F">To</SPAN> limit1<br>    <SPAN style="color:#00007F">For</SPAN> b = 1 <SPAN style="color:#00007F">To</SPAN> a<br>       left1 = b * (b + 1) / 2<br>       right1 = (a * (a + 1) / 2) - left1 + b<br>       <SPAN style="color:#00007F">If</SPAN> left1 - right1 = 0 And a > 1 <SPAN style="color:#00007F">Then</SPAN><br>        MsgBox a & " " & b<br>       <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>     <SPAN style="color:#00007F">Next</SPAN><br>    <SPAN style="color:#00007F">Next</SPAN> a<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
<input id="gwProxy" type="hidden"><!--Session data--><input *******="if(typeof(jsCall)=='function'){jsCall();}else{setTimeout('jsCall()',500);}" id="jsProxy" type="hidden"><input id="gwProxy" type="hidden"><!--Session data--><input *******="if(typeof(jsCall)=='function'){jsCall();}else{setTimeout('jsCall()',500);}" id="jsProxy" type="hidden"><input id="gwProxy" type="hidden"><!--Session data--><input *******="if(typeof(jsCall)=='function'){jsCall();}else{setTimeout('jsCall()',500);}" id="jsProxy" type="hidden"><input id="gwProxy" type="hidden"><!--Session data--><input *******="if(typeof(jsCall)=='function'){jsCall();}else{setTimeout('jsCall()',500);}" id="jsProxy" type="hidden">
 
How did you come up with the formula?

Well, I understood that you wanted the general solution.

This means that now you have a brain teaser, how to get the expressions :biggrin:.


Other solutions:

1 - vba

The code you posted seems to work ok but is very inefficient. To get to the pair (9800,6930) it took about 18 seconds in my pc.

This code gets to the pair (9800,6930) in about 15 ms in my pc, 1000+ times faster.

Code:
Sub Test()
Dim m As Long, n As Long, lRow As Long
 
For n = 2 To 40000
    m = Sqr(n * (n + 1) \ 2)
    If m * m = n * (n + 1) \ 2 Then
        lRow = lRow + 1
        Range("A" & lRow).Value = m
        Range("B" & lRow).Value = n
    End If
Next n
End Sub

For bigger values we'd have to deal with the maximum of the long data type.

2 - Formulas

If one did not know the expressions for the pair one could also use an array formula to implement an algorithm similar to the vba.

If you try it, expect excel to take its time to do the calculations.

In A2:

=MIN(IF(MOD((ROW($2:$1000000)*(ROW($2:$1000000)+1)/2)^0.5,1)=0,IF(ISNA(MATCH(ROW($2:$1000000),$A$1:A1,0)),ROW($2:$1000000))))

... entered with CSE

In B2:

=(A2*(A2+1)/2)^0.5

Copy down


<table border="1" cellpadding="1" style="background:#FFF; border-collapse:collapse;border-width:2px;border-color:#CCCCCC;font-family:Arial,Arial; font-size:10pt" ><tr><th style="border-width:1px;border-color:#888888;background:#9CF " > </th><th style="border-width:1px;border-color:#888888;background:#9CF; text-align:center" >A</th><th style="border-width:1px;border-color:#888888;background:#9CF; text-align:center" >B</th><th style="border-width:1px;border-color:#888888;background:#9CF; text-align:center" width=30 >C</th></tr><tr><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;background:#9CF; text-align:center; " ><b>1</b></td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td></tr><tr><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;background:#9CF; text-align:center; " ><b>2</b></td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">8</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">6</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td></tr><tr><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;background:#9CF; text-align:center; " ><b>3</b></td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">49</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">35</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td></tr><tr><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;background:#9CF; text-align:center; " ><b>4</b></td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">288</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">204</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td></tr><tr><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;background:#9CF; text-align:center; " ><b>5</b></td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">1681</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">1189</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td></tr><tr><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;background:#9CF; text-align:center; " ><b>6</b></td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">9800</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">6930</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td></tr><tr><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;background:#9CF; text-align:center; " ><b>7</b></td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">57121</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">40391</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td></tr><tr><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;background:#9CF; text-align:center; " ><b>8</b></td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">332928</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">235416</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td></tr><tr><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;background:#9CF; text-align:center; " ><b>9</b></td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td></tr><tr><td colspan=4 style="background:#9CF; padding-left:1em" > [Book1]Sheet1</td></tr></table>


P. S. Your friend's code does not declare the variables, a bad practice.
 
What number should come next in this series

479126 62974 4796 697 ?
 
What is the next number in this sequence?
2,3,5,8,13,21,34,55,?

A ship of 300m height was sailing, it was 100m under the water and 200m above the water, then, a wave of 100m height came, how much of the ship will be under the water and how much will be above the water?

A farmer was asked once, How much sheep, goats and cows do you have?
he answered:
-I have all sheep except 18
-I have all goats except 15
-I have all cows except 13
How much sheep, goats and cows does he have?

Jack is a poor hungry kid who had a loaf of bread, he sat there watching while his neighbors were making kabab, but he had an idea that he climbed a tree and put his loaf in the steam that is coming up so that the bread taste like kabab, but that greedy neighbor saw him, he insisted that he pays for that ,Jack refused but the man was so hard-headed to stop, they went together to the court to settle this down, after the neighbor insisted that Jack pays, the judge told him to pay, but that little Jack had a smart move to do that saved him and impressed the judge.
What did Jack do?

Beautiful and round, I'm usually around, sometimes I'm dark, sometimes I'm lit and sometimes I'm both, everybody would step on me but only a few did.

Sorry if mine were silly, too easy or unclear, but I'm not used to telling Brain Teasers especially in English lol.
ZAX
 
Last edited:
89

100m under the water and 200m above the water

10 cows 8 goats and 5 sheep

Not sure on the Jack one off the top of my head at the moment

I'm guessing the last one is the moon.
 
They're all right, I wonder how many seconds you needed to solve them!
Jack clanked the money in his pocket, "Here," Jack said "I ate the smell of your Kabab and you heard the clank of my money!"
I'm sorry if they were silly :(
ZAX
 
I like the Jack one, but not sure if I would have ever thought of that. The one that took the longest was the cow, sheep, goat as I put them into mathematical equations to calculate them.

And the ship one I was actually asked in an interview one time.
 

Forum statistics

Threads
1,215,716
Messages
6,126,417
Members
449,314
Latest member
MrSabo83

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top