Puzzle: Write a Shortest Code to Produce Zero.
It has been a long time since we have puzzle on this blog. So I have decided to post this puzzle. You have to write a shortest code which produces digit 0 (zero).
If you think this puzzle is easy, it is not true. I have two very simple but interesting condition for you.
Condition 1: Do not use numbers and arithmetic calculation
Condition 2: Do not use 0 in the code
Condition 3: Do not use function len()
Well, that’s it. So if you were thinking to write code like SELECT 1-1 or PRINT 0 or SELECT LEN(”). You can’t do that. You are not allowed to use numbers, arithmetic calculation or the digit 0 in the code.
Let me show you one valid solution.
Now, here is the challenge for you. The above code produces the result 0 (zero) and the length of the code is 18.
Here is the final condition for you,
Condition 4: Your Solution should have length lesser than 18 characters.
Now think of the interesting solution and post the result in the comment.
I will be happy to see what you can come up with. If you are also subscribed to my newsletter at https://blog.sqlauthority.com/contact-me/sign-up/ please expect a surprise gift for you if you get the correct answer.
Reference: Pinal Dave (https://blog.sqlauthority.com)
Any single character will produce a 0 when executed. It will result in an error 102, which contains a 0. You cannot go any shorter and there are many right answers if you treat every possible character as an answer.
Only exceptions to the above are digits and mathematical symbols, since those are not allowed according to rule 1.
One more exception, A space does not produce this error message and I guess there will be some more characters like this.
When I was going through all other comments I found out someone already posted a similar answer like mine.
Working it out myself, I came up with PRINT @@ERROR. However from reading the comments, I think “PRINT STR($)” is my favorite. Just printing $ gets you 0.00 (at least in my environment) which I don’t think is the proper answer.
I’m pretty sure 48 is a number.
Doh I posted the same thing!
select @@ROWCOUNT – @@ROWCOUNT
Good chance there will be a 0 somewhere, no debate about a space character being required or not.
Although many comments have been already posted. A function which is independent of any parameters(object) may return a zero as output.Take a look.
Ex -> select @@error
Just saw the 18 char limit!
Use of numbers is not allowed.
print $ –> 7 characters
And I didn’t read the rules! Ignore that!