# puzzle made me trouble

posted 5 years ago

In an interview I have asked to get 125 while performing any kind of mathematical operation between five 0....

ie I have 0 0 0 0 0 and by doing any mathematical operation between them I need to get digit 125...

HINT :- factorial of 0 =1

ie I have 0 0 0 0 0 and by doing any mathematical operation between them I need to get digit 125...

HINT :- factorial of 0 =1

No Kaustubh No Fun, Know Kaustubh Know Fun..

Matthew Brown

Bartender

Posts: 4568

9

Joanne Neal

Rancher

Posts: 3742

16

Matthew Brown

Bartender

Posts: 4568

9

posted 5 years ago

I would have thought not - it ought to be 5^3, so you need a 3 from somewhere. But I suppose it shows lateral thinking.

In which case:

0 + 0 + 0 + 0 + 0 + one hundred and twenty five

Joanne Neal wrote:Is cubing a number allowed ?

cube (fact(0) + fact(0) + fact(0) + fact(0) + fact(0))

I would have thought not - it ought to be 5^3, so you need a 3 from somewhere. But I suppose it shows lateral thinking.

In which case:

0 + 0 + 0 + 0 + 0 + one hundred and twenty five

Joanne Neal

Rancher

Posts: 3742

16

posted 5 years ago

But you could argue that the 3 is a mathematical operator (meaning raise to the third power) rather than a digit.

Matthew Brown wrote:Joanne Neal wrote:Is cubing a number allowed ?

cube (fact(0) + fact(0) + fact(0) + fact(0) + fact(0))

I would have thought not - it ought to be 5^3, so you need a 3 from somewhere.

But you could argue that the 3 is a mathematical operator (meaning raise to the third power) rather than a digit.

Joanne

posted 5 years ago

Or......

bin2dec (string2bin(( string(fact(0)) + string (0) + string(fact(0))) ^ + bin2dec(string2bin( string(fact(0)) + string(fact(0)))

bin2dec (string2bin(( string(fact(0)) + string (0) + string(fact(0))) ^ + bin2dec(string2bin( string(fact(0)) + string(fact(0)))

Joanne Neal

Rancher

Posts: 3742

16

Mike Simmons

Ranch Hand

Posts: 3090

14

posted 5 years ago

Well, if you use the calculator argument, most calculators have mc, m+, mr for accessing a single memory register. With that, you can easily create

More to the point, I really don't buy the argument that x^3 is not a digit. However it does seem probable that this is the solution that the interviewer expected, since none of us can come up with a better one. To me, that means this is an extremely flawed interview problem. It really needs to be better specified.

fred rosenberger wrote:if you look at the windows calculator (in scientific mode) there is a cube button, so I think Joanne's solution is spot-on!

Well, if you use the calculator argument, most calculators have mc, m+, mr for accessing a single memory register. With that, you can easily create

*any*integer, with a suitable number of presses to the m+ key. You don't even need the factorial hint - cos(0) has the same result. I think allowing arbitrary calculator key makes things too easy.

More to the point, I really don't buy the argument that x^3 is not a digit. However it does seem probable that this is the solution that the interviewer expected, since none of us can come up with a better one. To me, that means this is an extremely flawed interview problem. It really needs to be better specified.

Ryan McGuire

Ranch Hand

Posts: 1078

4

posted 5 years ago

Start with... 0 = 0

Multiply both sides by 125: 125 * 0 = 125 * 0

Evaluate the left side: 0 = 122 * 0

Divide both sides by 0: 0/0 = 125

Add 0: 0/0 + 0 = 125 + 0

Subtract 0: 0/0 + 0 - 0 = 125

Add 0 again: 0/0 + 0 - 0 + 0 = 125 + 0

Evaluate the right side: 0/0 + 0 - 0 + 0 = 125

(I'm sure there are more subtle ways to hide the division by zero.)

Multiply both sides by 125: 125 * 0 = 125 * 0

Evaluate the left side: 0 = 122 * 0

Divide both sides by 0: 0/0 = 125

Add 0: 0/0 + 0 = 125 + 0

Subtract 0: 0/0 + 0 - 0 = 125

Add 0 again: 0/0 + 0 - 0 + 0 = 125 + 0

Evaluate the right side: 0/0 + 0 - 0 + 0 = 125

(I'm sure there are more subtle ways to hide the division by zero.)

Mike Simmons

Ranch Hand

Posts: 3090

14

posted 5 years ago

Heh. I actually like that argument better than the cubing solution.

Though I should add - should have added in the last post, really - that Joanne does deserve kudos for considering the cubing solution, rather than just rejecting it out of hand as others had (me, at least). I don't like it, but it is certainly worth considering the possibility that this is what the interviewer meant.

Though I should add - should have added in the last post, really - that Joanne does deserve kudos for considering the cubing solution, rather than just rejecting it out of hand as others had (me, at least). I don't like it, but it is certainly worth considering the possibility that this is what the interviewer meant.

posted 5 years ago

Not true because as Matthew told you need to generate cube by some mathematical operation or by this 5 zeros......

Matthew Brown wrote:Joanne Neal wrote:Is cubing a number allowed ?

cube (fact(0) + fact(0) + fact(0) + fact(0) + fact(0))

I would have thought not - it ought to be 5^3, so you need a 3 from somewhere. But I suppose it shows lateral thinking.

In which case:

0 + 0 + 0 + 0 + 0 + one hundred and twenty five

Not true because as Matthew told you need to generate cube by some mathematical operation or by this 5 zeros......

No Kaustubh No Fun, Know Kaustubh Know Fun..

posted 5 years ago

Ryan McGuire wrote:Start with... 0 = 0

Multiply both sides by 125: 125 * 0 = 125 * 0

//fine till here

Evaluate the left side: 0 = 122 * 0

// from where you've got this 122?

Divide both sides by 0: 0/0 = 125

//then how you get the above step?

Add 0: 0/0 + 0 = 125 + 0

Subtract 0: 0/0 + 0 - 0 = 125

Add 0 again: 0/0 + 0 - 0 + 0 = 125 + 0

Evaluate the right side: 0/0 + 0 - 0 + 0 = 125

(I'm sure there are more subtle ways to hide the division by zero.)

No Kaustubh No Fun, Know Kaustubh Know Fun..

Mike Simmons

Ranch Hand

Posts: 3090

14

posted 5 years ago

ohk then what about this line

Divide both sides by 0: 0/0 = 125 didn't get it... {Hope this will not throw any exception}

Mike Simmons wrote:Kaustubh, obviously the 122 was a typo; he meant 125. Just pretend he wrote 125 there, and it makes perfect sense.

Well, as much as dividing by zero ever makes sense.

ohk then what about this line

Divide both sides by 0: 0/0 = 125 didn't get it... {Hope this will not throw any exception}

No Kaustubh No Fun, Know Kaustubh Know Fun..

Mike Simmons

Ranch Hand

Posts: 3090

14

posted 5 years ago

ohk

Mike Simmons wrote:If the previous line was

0 = 125 * 0

(corrected from 122)

and we divide both sides by 0 (pretending for a moment that this isn't an inherently horrible idea), we get (naively)

0/0 = (125 * 0)/0

which simplifies to

0/0 = 125

ohk

No Kaustubh No Fun, Know Kaustubh Know Fun..

posted 5 years ago

I wouldn't consider m+ a mathematical function, although I think cos(0) would be valid.

and I agree 100% that interview questions like this are flawed. But they are fun puzzles!!!

Mike Simmons wrote:

Well, if you use the calculator argument, most calculators have mc, m+, mr for accessing a single memory register. With that, you can easily createanyinteger, with a suitable number of presses to the m+ key. You don't even need the factorial hint - cos(0) has the same result. I think allowing arbitrary calculator key makes things too easy.

I wouldn't consider m+ a mathematical function, although I think cos(0) would be valid.

and I agree 100% that interview questions like this are flawed. But they are fun puzzles!!!

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

Ryan McGuire

Ranch Hand

Posts: 1078

4

posted 5 years ago

But seriously we can't give up yet!

What can you do with one zero to get other numbers?

0! = 1

That adds 1 to our "single zero" set.

asin(1) = 90 degrees, pi/2 radians or 100

So we're up to 0, 1, 90, 100, and pi/2.

We can square root any of those numbers:

sqrt(90) = 9.someodd

sqrt(100) = 10

sqrt(pi/2) = 1.someodd

If we add int(x) (aka floor(x)) to bag of tricks, we can add 9 and 10 to the numbers we can get to starting with a single 0.

we can apply sqrt() and int() again to 9 and/or 10 to get a 3.

So a single 0 can give us, 0, 1, 3, 9, 10, 90, 100 (among others plus a bunch of irrational numbers).

As a reminder here's how we got each of those:

0 = 0

1 = cos(0)

90 = the angle, in degrees, that has a sin of 1 = asind(1) = asind(cos(0))

100 = the angle, in gradians, that has a sin of 1 = asing(1) = asing(cos(0))

9 = int(sqrt(90)) = int(sqrt(asind(cos(0))))

10 = sqrt(100) = sqrt(asing(cos(0)))

3 = sqrt(9) = sqrt(int(sqrt(asind(cos(0)))))

After a little fiddling around, I found a way to combine 5 of those numbers to come up with 125.

125 = 100 + 10 + 9 + 3 + 3

125 = asing(cos(0)) + sqrt(asing(cos(0))) + int(sqrt(asind(cos(0)))) + sqrt(int(sqrt(asind(cos(0))))) + sqrt(int(sqrt(asind(cos(0)))))

BUT...

It pains me to use both asing() and asind(). I'd like to restrict myself to either one or the other.

I know, how about...

125 = 90 + (9*(3 + 1)) - 1

125 = asind(cos(0)) + ( int(sqrt(asind(cos(0)))) * ( sqrt(int(sqrt(asind(cos(0))))) + cos(0) )) - 0!

...where asind(x) = arcsin(x) in degrees.

What can you do with one zero to get other numbers?

0! = 1

That adds 1 to our "single zero" set.

asin(1) = 90 degrees, pi/2 radians or 100

So we're up to 0, 1, 90, 100, and pi/2.

We can square root any of those numbers:

sqrt(90) = 9.someodd

sqrt(100) = 10

sqrt(pi/2) = 1.someodd

If we add int(x) (aka floor(x)) to bag of tricks, we can add 9 and 10 to the numbers we can get to starting with a single 0.

we can apply sqrt() and int() again to 9 and/or 10 to get a 3.

So a single 0 can give us, 0, 1, 3, 9, 10, 90, 100 (among others plus a bunch of irrational numbers).

As a reminder here's how we got each of those:

0 = 0

1 = cos(0)

90 = the angle, in degrees, that has a sin of 1 = asind(1) = asind(cos(0))

100 = the angle, in gradians, that has a sin of 1 = asing(1) = asing(cos(0))

9 = int(sqrt(90)) = int(sqrt(asind(cos(0))))

10 = sqrt(100) = sqrt(asing(cos(0)))

3 = sqrt(9) = sqrt(int(sqrt(asind(cos(0)))))

After a little fiddling around, I found a way to combine 5 of those numbers to come up with 125.

125 = 100 + 10 + 9 + 3 + 3

125 = asing(cos(0)) + sqrt(asing(cos(0))) + int(sqrt(asind(cos(0)))) + sqrt(int(sqrt(asind(cos(0))))) + sqrt(int(sqrt(asind(cos(0)))))

BUT...

It pains me to use both asing() and asind(). I'd like to restrict myself to either one or the other.

I know, how about...

125 = 90 + (9*(3 + 1)) - 1

125 = asind(cos(0)) + ( int(sqrt(asind(cos(0)))) * ( sqrt(int(sqrt(asind(cos(0))))) + cos(0) )) - 0!

...where asind(x) = arcsin(x) in degrees.

posted 5 years ago

It bounces over my head .I've not tried to read it fully because I have maths phobia . May be some one from good maths background can check it's correctness....

Ryan McGuire wrote:But seriously we can't give up yet!

What can you do with one zero to get other numbers?

0! = 1

That adds 1 to our "single zero" set.

asin(1) = 90 degrees, pi/2 radians or 100

So we're up to 0, 1, 90, 100, and pi/2.

We can square root any of those numbers:

sqrt(90) = 9.someodd

sqrt(100) = 10

sqrt(pi/2) = 1.someodd

If we add int(x) (aka floor(x)) to bag of tricks, we can add 9 and 10 to the numbers we can get to starting with a single 0.

we can apply sqrt() and int() again to 9 and/or 10 to get a 3.

So a single 0 can give us, 0, 1, 3, 9, 10, 90, 100 (among others plus a bunch of irrational numbers).

As a reminder here's how we got each of those:

0 = 0

1 = cos(0)

90 = the angle, in degrees, that has a sin of 1 = asind(1) = asind(cos(0))

100 = the angle, in gradians, that has a sin of 1 = asing(1) = asing(cos(0))

9 = int(sqrt(90)) = int(sqrt(asind(cos(0))))

10 = sqrt(100) = sqrt(asing(cos(0)))

3 = sqrt(9) = sqrt(int(sqrt(asind(cos(0)))))

After a little fiddling around, I found a way to combine 5 of those numbers to come up with 125.

125 = 100 + 10 + 9 + 3 + 3

125 = asing(cos(0)) + sqrt(asing(cos(0))) + int(sqrt(asind(cos(0)))) + sqrt(int(sqrt(asind(cos(0))))) + sqrt(int(sqrt(asind(cos(0)))))

BUT...

It pains me to use both asing() and asind(). I'd like to restrict myself to either one or the other.

I know, how about...

125 = 90 + (9*(3 + 1)) - 1

125 = asind(cos(0)) + ( int(sqrt(asind(cos(0)))) * ( sqrt(int(sqrt(asind(cos(0))))) + cos(0) )) - 0!

...where asind(x) = arcsin(x) in degrees.

It bounces over my head .I've not tried to read it fully because I have maths phobia . May be some one from good maths background can check it's correctness....

No Kaustubh No Fun, Know Kaustubh Know Fun..

Mike Simmons

Ranch Hand

Posts: 3090

14

posted 5 years ago

Yeah, it's unclear. But one possible answer is that you don't need a numeral 2 to write a square root sign, but you do need a numeral 3 to write a cube root.

On the other hand, I

Regardless, I haven't checked Ryan's solution carefully myself, but it looks good, and I'm pretty confident it's right if he says it is. So kudos to him for his solution.

Greg Charles wrote:The math looks right to me, and it's pretty brilliant. However, it does bring into question what operations are permitted. Why should we allow square roots (i.e., x ^ 0.5), but not allow cubes (i.e. x ^ 3)?

Yeah, it's unclear. But one possible answer is that you don't need a numeral 2 to write a square root sign, but you do need a numeral 3 to write a cube root.

On the other hand, I

*was*considering using a % sign as a possible operation, when I was looking for solutions. That's pretty borderline even by my interpretation - depends if you're thinking of those two circles as being actual zeroes, or just part of the symbol.

Regardless, I haven't checked Ryan's solution carefully myself, but it looks good, and I'm pretty confident it's right if he says it is. So kudos to him for his solution.

posted 5 years ago

But we can't allow cubes Greg ...

Greg Charles wrote:The math looks right to me, and it's pretty brilliant. However, it does bring into question what operations are permitted. Why should we allow square roots (i.e., x ^ 0.5), but not allow cubes (i.e. x ^ 3)? If we do allow cubes, then Joanne's solution is much simpler.

But we can't allow cubes Greg ...

posted 5 years ago

For me it's damn difficult to do this....

Ryan McGuire wrote:But seriously we can't give up yet!

What can you do with one zero to get other numbers?

0! = 1

That adds 1 to our "single zero" set.

asin(1) = 90 degrees, pi/2 radians or 100

So we're up to 0, 1, 90, 100, and pi/2.

We can square root any of those numbers:

sqrt(90) = 9.someodd

sqrt(100) = 10

sqrt(pi/2) = 1.someodd

If we add int(x) (aka floor(x)) to bag of tricks, we can add 9 and 10 to the numbers we can get to starting with a single 0.

we can apply sqrt() and int() again to 9 and/or 10 to get a 3.

So a single 0 can give us, 0, 1, 3, 9, 10, 90, 100 (among others plus a bunch of irrational numbers).

As a reminder here's how we got each of those:

0 = 0

1 = cos(0)

90 = the angle, in degrees, that has a sin of 1 = asind(1) = asind(cos(0))

100 = the angle, in gradians, that has a sin of 1 = asing(1) = asing(cos(0))

9 = int(sqrt(90)) = int(sqrt(asind(cos(0))))

10 = sqrt(100) = sqrt(asing(cos(0)))

3 = sqrt(9) = sqrt(int(sqrt(asind(cos(0)))))

After a little fiddling around, I found a way to combine 5 of those numbers to come up with 125.

125 = 100 + 10 + 9 + 3 + 3

125 = asing(cos(0)) + sqrt(asing(cos(0))) + int(sqrt(asind(cos(0)))) + sqrt(int(sqrt(asind(cos(0))))) + sqrt(int(sqrt(asind(cos(0)))))

BUT...

It pains me to use both asing() and asind(). I'd like to restrict myself to either one or the other.

I know, how about...

125 = 90 + (9*(3 + 1)) - 1

125 = asind(cos(0)) + ( int(sqrt(asind(cos(0)))) * ( sqrt(int(sqrt(asind(cos(0))))) + cos(0) )) - 0!

...where asind(x) = arcsin(x) in degrees.

No Kaustubh No Fun, Know Kaustubh Know Fun..

anirudh jagithyala

Ranch Hand

Posts: 41

posted 5 years ago

Hi All,

Firstly look at the problem

use of factorial function is valid ie

So the solution given by Joanne

is absolutely right....

Check out the definitions for mathematical operation and mathematical functions........

Firstly look at the problem

In an interview I have asked to get 125 while performing any kind of mathematical operation between five 0....

ie I have 0 0 0 0 0 and by doing any mathematical operation between them I need to get digit 125...

HINT :- factorial of 0 =1

use of factorial function is valid ie

**use of mathematical functions is valid**{ factorial is not the basic mathematical operation but a specialised mathematical function}So the solution given by Joanne

cube (fact(0) + fact(0) + fact(0) + fact(0) + fact(0))

is absolutely right....

Check out the definitions for mathematical operation and mathematical functions........

Mike Simmons

Ranch Hand

Posts: 3090

14

Ryan McGuire

Ranch Hand

Posts: 1078

4

posted 5 years ago

Yeah, we get that. The issue (I hesitate to call it a "problem") with that solution is whether or not cube(x) is a "valid" basic mathematical operation / function for the sake of this problem.

If push comes to shove, I could define my own function that takes five arguments and returns 125:

Then all I need to do is point out that onetwentyfive(0, 0, 0, 0, 0) = 125 and declare the problem solved.

If you say that that function is invalid because it has the constant 125 embedded in it, then I could just as easily argue that cube(x) is invalid because it has an implicit 3 embedded in it:

I can see the counterargument that cube(x)

I would then counter by saying onetwentyfive() could also be written without any constants:

I admit that my own solution depends on int(x) qualifying as a valid mathematical operation / function. The criteria I used for determining the validity of a operation / function was whether or not

Granted, in the absence of explicit instructions in the original post, using

- 1

anirudh jagithyala wrote:Hi All,

So the solution given by Joanne

cube (fact(0) + fact(0) + fact(0) + fact(0) + fact(0))

is absolutely right....

Check out the definitions for mathematical operation and mathematical functions........

Yeah, we get that. The issue (I hesitate to call it a "problem") with that solution is whether or not cube(x) is a "valid" basic mathematical operation / function for the sake of this problem.

If push comes to shove, I could define my own function that takes five arguments and returns 125:

Then all I need to do is point out that onetwentyfive(0, 0, 0, 0, 0) = 125 and declare the problem solved.

If you say that that function is invalid because it has the constant 125 embedded in it, then I could just as easily argue that cube(x) is invalid because it has an implicit 3 embedded in it:

I can see the counterargument that cube(x)

*could*be written without the 3:

I would then counter by saying onetwentyfive() could also be written without any constants:

I admit that my own solution depends on int(x) qualifying as a valid mathematical operation / function. The criteria I used for determining the validity of a operation / function was whether or not

*I*use any additional numbers when using the function in hand-written equations. When using the int() function, I use either "int()" or the "floor" operator, which looks like an uppercase "L" but taller and narrower plus the mirror image of that. In contrast, when cubing a number, I don't write out "cube"; I use a superscript "3". What about square root? There are a handful of notations for that: a bare radical sign, a radical with a small 2, a superscript "0.5" or maybe, caret and a 0.5 and the sqrt() function. I use the bare radical more often than the other options combined. Using my own personal practice as the standard, sqrt() and int() are valid, while sqr(), cube(), and cubert() are invalid.

Granted, in the absence of explicit instructions in the original post, using

*your*own personal practice or even some some other criteria to determine valid functions/operators is as correct as anything I've done. However, I'm not convinced that using cube() is "absolutely correct".

anirudh jagithyala

Ranch Hand

Posts: 41

posted 5 years ago

i looked at the requirements from my point of view......

This argument would continue endless until the requirement is exactly fixed as all of us are assuming our own assumptions.

It would be better for the person who posted originally kaustabh to give the fixed set of requirements and constraints.

This argument would continue endless until the requirement is exactly fixed as all of us are assuming our own assumptions.

It would be better for the person who posted originally kaustabh to give the fixed set of requirements and constraints.

Mike Simmons

Ranch Hand

Posts: 3090

14

posted 5 years ago

What to do guys I only know the question and struggling with the answer that's why I posted it here....I think I have to find that interviewer who asked me this.....

anirudh jagithyala wrote:i looked at the requirements from my point of view......

This argument would continue endless until the requirement is exactly fixed as all of us are assuming our own assumptions.

It would be better for the person who posted originally kaustabh to give the fixed set of requirements and constraints.

What to do guys I only know the question and struggling with the answer that's why I posted it here....I think I have to find that interviewer who asked me this.....

No Kaustubh No Fun, Know Kaustubh Know Fun..

posted 5 years ago

Because I was given the same parameter for the task...I am not very good with maths to figure out whether this is possible or not... that's why I posted it over here...Just too good to be true

Mike Simmons wrote:Agreed. I only objected because you were using terms like "absolutely" and repeating "use of mathematical functions" in bold, without acknowledging the ambiguities we've been talking about.

Because I was given the same parameter for the task...I am not very good with maths to figure out whether this is possible or not... that's why I posted it over here...Just too good to be true

No Kaustubh No Fun, Know Kaustubh Know Fun..