Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Tim Cooke
• Ron McLeod
• Jeanne Boyarsky
• Paul Clapham
Sheriffs:
• Liutauras Vilda
• Henry Wong
• Devaka Cooray
Saloon Keepers:
• Tim Moores
• Stephan van Hulst
• Tim Holloway
• Al Hobbs
• Carey Brown
Bartenders:
• Piet Souris
• Mikalai Zaikin
• Himai Minh

# puzzle made me trouble

Ranch Hand
Posts: 1283
• Number of slices to send:
Optional 'thank-you' note:
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

lowercase baba
Posts: 13063
67
• Number of slices to send:
Optional 'thank-you' note:
I think a better spot for this would be programming diversions...

Bartender
Posts: 4568
9
• Number of slices to send:
Optional 'thank-you' note:
I can reach 120 easily enough. Not yet convinced 125 is possible!

Kaustubh G Sharma
Ranch Hand
Posts: 1283
• Number of slices to send:
Optional 'thank-you' note:
yup 120 is kinda easy if you follow the hint:-

fact(fact(0)+fact(0)+fact(0)+fact(0)+fact(0))=120

but i think 125 is not possible

Rancher
Posts: 3742
16
• Number of slices to send:
Optional 'thank-you' note:

Kaustubh G Sharma wrote:yup 120 is kinda easy if you follow the hint:-

fact(fact(0)+fact(0)+fact(0)+fact(0)+fact(0))=120

but i think 125 is not possible

Is cubing a number allowed ?
cube (fact(0) + fact(0) + fact(0) + fact(0) + fact(0))

Matthew Brown
Bartender
Posts: 4568
9
• Number of slices to send:
Optional 'thank-you' note:

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
• Number of slices to send:
Optional 'thank-you' note:

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.

fred rosenberger
lowercase baba
Posts: 13063
67
• Number of slices to send:
Optional 'thank-you' note:
if you look at the windows calculator (in scientific mode) there is a cube button, so I think Joanne's solution is spot-on!

Bartender
Posts: 612
7
• Number of slices to send:
Optional 'thank-you' note:
Or......

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

Joanne Neal
Rancher
Posts: 3742
16
• Number of slices to send:
Optional 'thank-you' note:
I'm not sure concatenating strings or converting a number to a string can be considered mathematical operations.

Rancher
Posts: 4251
57
• Number of slices to send:
Optional 'thank-you' note:

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.

Bartender
Posts: 1205
22
• Number of slices to send:
Optional 'thank-you' note:
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
Rancher
Posts: 4251
57
• Number of slices to send:
Optional 'thank-you' note:
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.

Kaustubh G Sharma
Ranch Hand
Posts: 1283
• Number of slices to send:
Optional 'thank-you' note:

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

Kaustubh G Sharma
Ranch Hand
Posts: 1283
• Number of slices to send:
Optional 'thank-you' note:

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

Mike Simmons
Rancher
Posts: 4251
57
• Number of slices to send:
Optional 'thank-you' note:
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.

Kaustubh G Sharma
Ranch Hand
Posts: 1283
• Number of slices to send:
Optional 'thank-you' note:

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.

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

Mike Simmons
Rancher
Posts: 4251
57
• Number of slices to send:
Optional 'thank-you' note:
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

Kaustubh G Sharma
Ranch Hand
Posts: 1283
• Number of slices to send:
Optional 'thank-you' note:

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

fred rosenberger
lowercase baba
Posts: 13063
67
• Number of slices to send:
Optional 'thank-you' note:

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
Bartender
Posts: 1205
22
• Number of slices to send:
Optional 'thank-you' note:
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.

Kaustubh G Sharma
Ranch Hand
Posts: 1283
• Number of slices to send:
Optional 'thank-you' note:

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

Sheriff
Posts: 3036
12
• Number of slices to send:
Optional 'thank-you' note:
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
Rancher
Posts: 4251
57
• Number of slices to send:
Optional 'thank-you' note:

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.

Kaustubh G Sharma
Ranch Hand
Posts: 1283
• Number of slices to send:
Optional 'thank-you' note:

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

Kaustubh G Sharma
Ranch Hand
Posts: 1283
• Number of slices to send:
Optional 'thank-you' note:
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.

Ranch Hand
Posts: 41
• Number of slices to send:
Optional 'thank-you' note:
Hi All,

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
Rancher
Posts: 4251
57
• Number of slices to send:
Optional 'thank-you' note:
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
Bartender
Posts: 1205
22
• 1
• Number of slices to send:
Optional 'thank-you' note:

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
• Number of slices to send:
Optional 'thank-you' note:
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
Rancher
Posts: 4251
57
• Number of slices to send:
Optional 'thank-you' note:
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.

Kaustubh G Sharma
Ranch Hand
Posts: 1283
• Number of slices to send:
Optional 'thank-you' note:

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

Kaustubh G Sharma
Ranch Hand
Posts: 1283
• Number of slices to send:
Optional 'thank-you' note:

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

Ranch Hand
Posts: 40
1
• Number of slices to send:
Optional 'thank-you' note:
(.008)^(-(0!))

2 0's make an 8

Kaustubh G Sharma
Ranch Hand
Posts: 1283
• Number of slices to send:
Optional 'thank-you' note:

Tak Ming Laio wrote:(.008)^(-(0!))

2 0's make an 8

What you mean by this?

Mike Simmons
Rancher
Posts: 4251
57
• Number of slices to send:
Optional 'thank-you' note:
Look at the number 8. It is written with two loops, that look like two zeroes. Sort of.

It may or may not be a valid solution (based on rules that were never properly defined, after all) but at least it was creative.

 Don't get me started about those stupid light bulbs.