Counting zeroes

User avatar
silverback
5StarLounger
Posts: 778
Joined: 29 Jan 2010, 13:30

Counting zeroes

Post by silverback »

Two questions for Loungers.

1. There was a poser question on the radio the other day; "If I write all the numbers from 1 to 1000 inclusive, how many times will I write the number zero?". (I missed the answer because I had to go to the loo. Gah - old age!)
Thinking about it, I had a sudden brainwave - I'll use AI.
So I asked CoPilot, ChatGPT and some other website that claimed to use ChatGPT logic - and got three different answers! 111, 192 and 300.
What is the correct answer, please?

2. Also, I am trying to use Excel functions to solve this but I rarely use functions. I've generated the numbers 1 to 1000 as text, by putting ' in front of each number. I've tried to use COUNTIF, but it obstinately returns 0 as its answer. What Excel function will solve this problem, please?
Silverback

User avatar
stuck
Panoramic Lounger
Posts: 8185
Joined: 25 Jan 2010, 09:09
Location: retirement

Re: Counting zeroes

Post by stuck »

Forget AI, simply type your question:
    If I write all the numbers from 1 to 1000 inclusive, how many times will I write the number zero
into Google and the first hit is this paper from the Maths Dept at Toronto Uni:
    https://www.math.utoronto.ca/barbeau/fn31.pdf

Ken

User avatar
HansV
Administrator
Posts: 78558
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Counting zeroes

Post by HansV »

The numbers 10, 20, ..., 1000 have a 0 at the end. So there are 100 zeros at the end.
The numbers 100 - 109, 201 -209, ..., 901 - 909 and 1000 have a 0 in the next to last place. So there are 10*9+1 = 91 zeros in the next to last place.
Finally, 1000 has a 0 in the second to last place.
Total: 100+91+1 = 192.

Let's say you have the numbers 1 to 1000 as text in A1:A1000.
The formula

=SUM(LEN(A1:A1000)-LEN(SUBSTITUTE(A1:A1000, "0", "")))

returns the number of zeros. If you do not have Microsoft 365 or Office 2021, confirm by pressing Ctrl+Shift+Enter.
Best wishes,
Hans

User avatar
silverback
5StarLounger
Posts: 778
Joined: 29 Jan 2010, 13:30

Re: Counting zeroes

Post by silverback »

Hans
Thanks for this, although I had to try each function to see what they would do before I could understand what was going on!

Ken - I tried AI because it's supposed to be the new saviour for humanity (or its nemesis). Just thought it was interesting that I got three different answers.
Going to ask it how I should vote in the forthcoming General Election next :innocent:
Silverback

User avatar
stuck
Panoramic Lounger
Posts: 8185
Joined: 25 Jan 2010, 09:09
Location: retirement

Re: Counting zeroes

Post by stuck »

silverback wrote:
24 Apr 2024, 16:29
Going to ask it how I should vote in the forthcoming General Election next
:hushmouth: Rule 10 forbids me to express my opinion on that matter :hushmouth:

Ken

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15641
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Counting zeroes

Post by ChrisGreaves »

silverback wrote:
24 Apr 2024, 14:44
- and got three different answers!
Please see also ChatGPt versus Google
Cheers, Chris
He who plants a seed, plants life.