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.
SELECT ISDATE('a')
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)
726 Comments. Leave new
Hi, My code is
SELECT ISDATE(”)
Here are my two successful answers:
SELECT @@ERROR –len 14
SELECT ISDATE(”) –len 17
This really doesn’t qualify on output or arithmetic unless you’re really generous with your definitions:
print abs($)
SELECT ISDATE(”)
This one is better than last, same length, exact output, but uses math function:
print log(1)
–honest way
SELECT LOG(1) –14 symbols
–Dishonest way
1
— try to execute one digit in SSMS and you’ll see 0 in error message (Msg 102, Level 15, State 1…))
OK, I should’ve tested more, this is my final one (no math, but prints decimals):
print $
This matches output perfectly, but uses math function:
print sin($)
Arithmetic function is there (SIN). I guess it should not be there.
SELECT @@ERROR
SELECT sin(”)
SELECT abs(”)
select char(48)
got too excited, still contains numbers
SELECT SIN(”)
select @@error
PRINT CHAR(48)
select @@FETCH_STATUS
select floor(rand())–20 characters (including space).
select sign(”)–15 characters.
select str(”)–14 characters.
select abs(”)
Below are trhe answers where mathematical function and numbers are not used.
SELECT STR(”)
SELECT ABS(”)
SELECT ISDATE(”)
select str(”)
SELECT SIGN(”)