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
I found below
SELECT ISDATE(”)
Hi Pinal
How about this:
select char(48)
Jerry
Is below a valid solution?
PRINT ISDATE(”)
select patindex(‘.’,”)
Um, sorry, previous one had numbers try this:
select @@error;
Jerry
You can do simple query select Isdate(”)
go
select @@ERROR
SELECT @@ERROR
SELECT ISDATE(”)
select char(48)
PRINT @@ERROR
Select @@Error and it’s length is 14
SELECT ISDATE(”)
SELECT month(”)
And my second solution has 15 chars.
The first one: select char(’48’) has more chars, returns a 0 but not as a digit.
How about:
select @@rowcount
Or
print @@rowcount
17 and 16 characters respectively. If you haven’t executed a select beforehand, 0 will be returned. Or just run it in a new query window.
I got down to 13. I’m sure there’s a more clever way to display data than using PRINT:
PRINT ISJSON(”) — 16
PRINT @@LANGID –14
PRINT ABS(”) — 13
CODE provided by you itself have 18 character
Select @@ERROR
select str(”)
Open a new query window and enter either select @@rowcount or print @@rowcount – this will return 0. Length of these are 17 and 16 characters.