Problem 539. Fun Race
- Given two unary functions foo and goo.
- Check whether foo(0) runs faster than goo(0).
- Output 1 if foo is faster, otherwise output 2.
- Please give the answer within 1/5 seconds.
Solution Stats
Problem Comments
-
3 Comments
Very entertaining puzzle.
Hint to the frustrated, as I was:
This is a "noise" exclusion problem. The 1-sigma uncertainty in the time measurement is greater than the "true" time delta between foo and goo.
The test suite method is also vey well executed.
Regardless of noise, the function sign should not be faster than the gamma function. The function Gamma is a factorial/integral calculation, while the function Sign requires looking at just one bit. Unless there is a way to evaluate the gamma function looking at just one bit, sign should be faster. I am guessing that someone's computer has optimization issues.
PS: The other two cases make sense str2num should be slower since it is working with strings, and calling a function that uses a function B should be slower than just calling the function B.
The problem is not valid (most probably since its inception, noted by the comments), as can be observed by the solutions submitted.
The (ridiculous) reference solution submitted by OP, which seems to be the basis of the incorrect test suite, is not working.
The test suite will be fixed soon, but the solutions will not be rescored.
Solution Comments
Show commentsProblem Recent Solvers33
Suggested Problems
-
226 Solvers
-
1001 Solvers
-
Convert a vector into a number
596 Solvers
-
286 Solvers
-
470 Solvers
More from this Author100
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!