If every whole number from 1 to 1000 inclusive is written down, then which digit is written the least?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Very nice. Clever :-)
Nice, but what does 'digs' do?
1 2 3 4 5 6 7 8 9 10 11 12 |
|
1 2 |
|
You cheated! But a really nice one...
To be honest, I only used logic and assumption here. The number 0 (literally) appears in front of every number of 1 (read as 0001), until 999 (read as 0999). Since the question only covers 1 to 1000, then I assume that 0 itself has been "disregarded" the most (Three zeroes per one-digit number, then two per two-digit number, and then one per three-digit number), and by logic 0 will appear in the least frequency.
SAME LOGIC
Through 1 to 1000 each other than 0 gets a fair chance of ocurring from a min of 0 times to a maximum of 3 times (excluding 1 which appears in the number 1000). Since the count starts from the number 1, the number 0 appears 1 time lesser than any other
1 to 1000 means nos are - 1---- single digits (0 loses here as it cant be placed b/w 1 to 9) 2----- 2 digits (0 is again a loser as its there only in mutiples of 10 whereas other nos can be at unit place as well as ones ones place ) 3---- 3 digits (0 again a loser as it can only be at ones and tens place .. whereas others are present at ones tens and hundreds ) 4----- 4 digit ( 0 is a first time winner here with 3 places ) but its insignificant as the loss in earlier case is more than the profit here
Best answer amongst all!!
It is simple logic, no need to write any program and find the proof. In the number sequence the number '0' is used less compare to other numbers. Example: Since we never use '1' as '01', but the combination 11,21,31,41,51,61,71,81,91 will give meaning full values. Similarly, 011 is not used but we use 111,211,311,411,511,..
--Here are a couple of solutions using SQL server. Cut and paste into a query and run
--Create the holders for each digit and some count integers
DECLARE @myVar Varchar(5000) = ''
DECLARE @myVar2 Varchar(5000)
DECLARE @myVar3 Varchar(5000)
DECLARE @iLen as Int
DECLARE @iTest as Int
DECLARE @myInt int = 0
DECLARE @0Count int = 0
DECLARE @1Count int = 0
DECLARE @2Count int = 0
DECLARE @3Count int = 0
DECLARE @4Count int = 0
DECLARE @5Count int = 0
DECLARE @6Count int = 0
DECLARE @7Count int = 0
DECLARE @8Count int = 0
DECLARE @9Count int = 0
--count to 1000 and Concatinate the numbers to a variable called @myVar
WHILE (@myInt <=1000)
BEGIN
SET @myVar2 = @myVar
SET @myVar3 = CAST(@myInt as varchar)
SET @myVar = @myVar2 + CAST(@myInt as varchar)
SET @myInt = @myInt + 1
END
--Reset this as a Counting Integer
SET @myInt = 1
--PRINT @myVar
--So there are now 2894 characters in @myVar. We just now read each character and count the digit.
--Note, there is one extra zero in this String from the initialisation.
SET @iLen = LEN(@myVar)
PRINT @iLen
WHILE (@myInt <= @iLen)
BEGIN
--Use Substring to scroll through each 2894 digits
SET @iTest = SUBSTRING(@myVar,@myInt,1)
--PRINT @iTest
IF @iTest = 1
BEGIN
SET @1Count = @1Count + 1
END
ELSE IF @iTest = 2
BEGIN
SET @2Count = @2Count + 1
END
ELSE IF @iTest = 3
BEGIN
SET @3Count = @3Count + 1
END
ELSE IF @iTest = 4
BEGIN
SET @4Count = @4Count + 1
END
ELSE IF @iTest = 5
BEGIN
SET @5Count = @5Count + 1
END
ELSE IF @iTest = 6
BEGIN
SET @6Count = @6Count + 1
END
ELSE IF @iTest = 7
BEGIN
SET @7Count = @7Count + 1
END
ELSE IF @iTest = 8
BEGIN
SET @8Count = @8Count + 1
END
ELSE IF @iTest = 9
BEGIN
SET @9Count = @9Count + 1
END
ELSE IF @iTest = 0
BEGIN
SET @0Count = @0Count + 1
END
SET @myInt = @myInt + 1
END
-- Remember you initialised @0Count at the beggining so there are one too many zero's in this variable SELECT @0Count - 1 AS [ZEROS], @1Count AS [Ones], @2Count AS [Twos], @3Count AS [Threes], @4Count AS [Fours], @5Count AS [Fives] , @6Count AS [Sixes], @7Count AS [Sevens], @8Count AS [Eights], @9Count AS [Nines]
-- Or this way works just as quickly
DECLARE @myVar11 Varchar(5000) = '' DECLARE @myVar12 Varchar(5000) DECLARE @myVar13 Varchar(5000)
DECLARE @myInt0 int = 0 DECLARE @10Count int = 0 DECLARE @11Count int = 0 DECLARE @12Count int = 0 DECLARE @13Count int = 0 DECLARE @14Count int = 0 DECLARE @15Count int = 0 DECLARE @16Count int = 0 DECLARE @17Count int = 0 DECLARE @18Count int = 0 DECLARE @19Count int = 0
--count to 1000 and Concatinate the numbers to a variable called @myVar11
WHILE (@myInt0 <=1000)
BEGIN
SET @myVar12 = @myVar11
SET @myVar13 = CAST(@myInt0 as varchar)
SET @myVar11 = @myVar12 + CAST(@myInt0 as varchar)
SET @myInt0 = @myInt0 + 1
END
--Again there are now 2894 characters in @myVar11. This time we remove each digit in turn and subtract the difference
--Note, there is still one extra zero in this String from the initialisation.
SET @10Count = len(@myVar11) - len(replace(@myVar11, 0, ''))
SET @11Count = len(@myVar11) - len(replace(@myVar11, 1, ''))
SET @12Count = len(@myVar11) - len(replace(@myVar11, 2, ''))
SET @13Count = len(@myVar11) - len(replace(@myVar11, 3, ''))
SET @14Count = len(@myVar11) - len(replace(@myVar11, 4, ''))
SET @15Count = len(@myVar11) - len(replace(@myVar11, 5, ''))
SET @16Count = len(@myVar11) - len(replace(@myVar11, 6, ''))
SET @17Count = len(@myVar11) - len(replace(@myVar11, 7, ''))
SET @18Count = len(@myVar11) - len(replace(@myVar11, 8, ''))
SET @19Count = len(@myVar11) - len(replace(@myVar11, 9, ''))
-- Remember you initialised @0Count at the beggining so there are one too many zero's in this variable SELECT @10Count - 1 AS [ZEROS], @11Count AS [Ones], @2Count AS [Twos], @13Count AS [Threes], @14Count AS [Fours], @15Count AS [Fives] , @16Count AS [Sixes], @17Count AS [Sevens], @18Count AS [Eights], @19Count AS [Nines]
The formatting has gone since I pasted into this site. You'll need to copy and paste the whole answer, not just the bits in the boxes.
-- Lua Roblox Solution
local digits = {}
for dig = 0, 9 do digits[dig]= 0 end
-- Acumulating Digits for numbers = 1, 1000 do
local hashString = tostring(numbers)
for indexHashString = 1, #hashString do
subString = tonumber( string.sub ( hashString, indexHashString, indexHashString ))
digits[subString] = digits[subString] + 1
end
end
-- Output for k,v in pairs(digits) do print(k, " = ", v) end
--[[ Output
1 = 301 2 = 300 3 = 300 4 = 300 5 = 300 6 = 300 7 = 300 8 = 300 9 = 300 0 = 192
]]--
If you start with the number one, every number through ten is used once. From eleven to twenty, every number is used again while the number one is used far more often. The same is said about all of the numbers except Zero, which is only used in multiples of ten. This means that Zero is used less frequently than all of the other numbers.
Problem Loading...
Note Loading...
Set Loading...
This is my programming approach, which will print the number of times each digit is written: Let digits = {i:0 for i in range(10)}
After letting the program run, the output is
{0 : 192, 1 : 301, 2 : 300, 3 : 300, 4 : 300, 5 : 300, 6 : 300, 7 : 300, 8 : 300, 9 : 300}
meaning the digit "0" is represented the least.