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.

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.)

Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018

10

posted

0

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.

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 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.

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!!!

Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1013

3

posted

0

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.

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.

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....

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.

Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018

10

posted

0

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.

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.

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.

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}

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

Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018

10

posted

0

We seem to be going in circles now. I don't see anything new here. What "definitions for mathematical operation and mathematical functions" are you referring to? If we had any standard definition that folks agreed to, this would be a much better problem.

Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1013

3

posted

1

anirudh jagithyala wrote:Hi All,
So the solution given by Joanne

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

Joined: Dec 07, 2010
Posts: 41

posted

0

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.

Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018

10

posted

0

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.

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.....

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