开发者

Get the results as 120 using five zeros

开发者 https://www.devze.com 2023-02-15 03:06 出处:网络
One of my friend was asked this question in the interview. You have 5 zeros. using these 5 zeros and any mathematical functions, you have to get the result of 120.

One of my friend was asked this question in the interview.

You have 5 zeros. using these 5 zeros and any mathematical functions, you have to get the result of 120.

He could not answer this. Neither I am able to see any valid answers.

Does anyone have any solution to this开发者_如何学Go?


( 0! + 0! + 0! + 0! + 0! ) ! = 120


(cos(0) + cos(0) + cos(0) + cos(0) + cos(0))!


I can do it with 4 zeros: ((0! + 0! + 0!)! - 0!)!


Use factorial

0! = 1
(0! + 0! + 0! + 0! + 0!)! = 120


I recently came across this beautiful approach to represent any number using one zero!


The explanation is as follows:
Consider a right-angled triangle with sides (1,1,√2). Thus,
√2 = Sec ( Tan-1( 0! ) ).
Now, consider a another right-angled triangle with sides (1,√2, √3). Here,
√3 = Sec ( Tan-1 (Sec ( Tan-1( 0! ) ) ) ).
Extrapolating this idea futher, for any number x, we can represent √x using one 0 as,
√x = Sec ( Tan-1 (…… Sec ( Tan-1 (0!)) ……)), where Sec ( Tan-1 ….) is taken x-1 times.


There you go, 120 can be represented as,
√14400 = Sec ( Tan-1 (…… Sec ( Tan-1 (0!)) ……)), with Sec ( Tan-1 ….) taken 14399 times.


I would buy the pure solution by @Iarsman, but I bet they were looking for something like:

factorial(not(0)+not(0)+not(0)+not(0)+not(0))


If you want to show you really know mathematical functions better than the interviewer, state it in terms of http://en.wikipedia.org/wiki/Peano_axioms:

SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS0 = 120

Or if you want to be too clever by half:

0/0 = 120 [Yes, that's not good practice, but it's as justifiable as any other answer]

Or if you want to show that mathematicians are often also comfortable using programming operators in the right circumstance:

(!0+!0+!0+!0+!0)!

I admit when I first saw it I was confused, because mostly this sort of question assumes that by mathematical function you mean "plus times minus divide" and maybe exponentiation. And I agree factorials are the intended answer. I agree it's an amusing question, and maybe it's sour grapes, but I really don't see the point of distinguishing people who've seen too many of these "think of the trick" questions from those who haven't, which is what this question does. (OK, it also sorts out who's never heard of a factorial, but so would asking "what's a factorial". This just makes sure you get the middle ground.)


"Mathematical" functions, hmmm, what else? Chemical ones?

let
   zeroes = [0,0,0,0,0]
   five = length zeroes
in five*five*five - five

Turns out we do not even need the zeores:

let
   zeroes = [[], [], [], [], []]
   five = length zeroes
in five*five*five - five


Use Factorial . 

fact(fact(0)+....+fact(0))


0^0*1111 = 1111 (2 zeroes)

1111000 = 120 in binary (remaining 3 zeroes used here)


(0!0!*0!0!)-0! =(11*11) -1 =121-1 =120 is how i solved in an interview and the interviewer was amazed :)


how about one zero :P

(((((0!)++)++)++)++)!


RoL(RoL(RoL(RoL(NOT(RoL(NOT(RoL(NOT(RoL(NOT(0))))))))))) One zero strictly logical using Windows Programming Calc

0

精彩评论

暂无评论...
验证码 换一张
取 消