In the last puzzle, user had to write the shortest code to produce 0. I have received around 700 valid answers and while reading through the answers, I had a blast. I personally learned quite a lot from just administrating the quiz. Since that puzzle, I have received quite a few emails requesting to come up with next puzzle.
Honestly, building a puzzle is very hard, but as you all wanted me to come up with another puzzle, here is the puzzle.
Puzzle: Write the shortest code to produce the number 1000000000 (One Billion)
Conditions:
1 You can use numbers in the code, but not One billion (1000000000) itself
2 You cannot use arithmetic operators
I guess, that’s it. This time, the puzzle is very simple. The shortest code which I have with me is of the total 10 characters (including spaces).
Now is the time, please get going with this puzzle and post your answers in the comments section. Please note that all the answers will be hidden till the next Monday. On the Monday morning, I will publish all the valid answers.
After finding the answer to this puzzle and if you still have time and you want to solve something more challenging here another small puzzle Select Unique Data From a Column Exist in Two Different Table, which I shared earlier last week.
Reference: Pinal Dave (https://blog.sqlauthority.com)
33 Comments. Leave new
select power(10,9)
select ‘1’ + replicate(‘0’,9)
select 1E9
Does the 10 count include a select at the start? Otherwise SELECT POWER(10,9)
I think scientific notation is the answer to this one:
SELECT 1E9
10 characters, including space.
I believe you are correct James!
select convert(int,’10000’+’00000′)
SELECT CAST(CONCAT(‘100000000′,’0’ ) AS INT)
SELECT POWER(10,9)
SELECT CONCAT(‘1’, ‘000000000’)
SELECT SQRT(1E18)
Let’s split hairs….
If you are obeying the rules you cannot use scientific notation. Rule 1 says you cannot use the number “One billion”. 1E9 is the number one billion, just represented differently.
It also doesn’t say that the output format must be standard notation. It says the number “One billion”. So, if Scientific notation is allowed, we can do:
PRINT 1E9
The rules don’t specify the value must be returned, just “produced”.
But if we can’t use scientific notation:
PRINT power(10,9)
But you may consider POWER to be an arithmetic operator, as it is in other languages. In VB you could say
Debug.Print 10^9
My final contribution then, is:
PRINT’1’+’000000000′
Where we drop the space after PRINT because it’s not required for parsing, and the ‘+’ is concatenation and not an arithmetic operator.
Hairs split. What a lovely parting I now have :-)
I love reading this comment. Such a brilliant note.