Problem 539. Fun Race
Solution Stats
Problem Comments
-
2 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.
Solution Comments
-
1 Comment
Could someone please give me a hint as to why this doesn't work? Thanks!
-
1 Comment
The function timeit takes care of any noise that may be when evaluating a function by running it several times and extracting the median of them all (doc timeit). Even so, the function gamma obviously looses.
-
1 Comment
Indeed the solution is random...
-
1 Comment
since tic toc didn't give me results, I tried the cody size approach
-
2 Comments
I tried a lot of times this solution without sucess
As did I, even with 10,000 iterations in the loop. My problem was that gamma took longer than sign did, despite the test suite saying it shouldn't. After four or five tries, I had to add an ugly hack that checked if foo was gamma.
Good to know this method does occasionally work, though...
Problem Recent Solvers34
Suggested Problems
-
Extract leading non-zero digit
1755 Solvers
-
Least common multiple of many numbers
217 Solvers
-
Flip the main diagonal of a matrix
625 Solvers
-
Are all the three given point in the same line?
363 Solvers
-
Get the elements of diagonal and antidiagonal for any m-by-n matrix
443 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!