Count to a million in Python - Theory

I am learning Python and came across a question that sounded like "How long does it take to count up to 1,000,000 out loud?" The only parameter he gave was "you average 1 digit per second". I made this problem, which was not very difficult. Then I started thinking about counting out loud, indicating each digit. This option seems unavailable to me, and indeed Google's answer only gives one question: "how long to count to a million" suggests this. Given that each number in the sequence takes a longer time (exponential increase?), There must be a better way.

Any ideas or general guidance would be helpful. Will there be samples of different people "counting rates" at different intervals? Will programming # of syllables work? I'm really curious and have looked all over SO and Google for solutions that don't revolve around this seemingly imprecise "average time".

Thanks, and sorry if this is off-topic or in the appropriate place. I've been catching for a long time, but new to posting, so let me know if you need more information or anything else. Thank!

+3


source to share


1 answer


For the sake of simplicity, let's say that you don't say 1502 as "fifteen hundred and two," but as "fifteen hundred and two." Then we can break it hierarchically.

And let it ignore the fact that you say "and" or not ( although, apparently, this is more said than ). I'll use this link (and British English because I like it better and it's more consistent: http://forum.wordreference.com/showthread.php?t=15&langid=6 ) for how to pronounce numbers.

In fact, to formally describe this, let's t

say is a number set function that tells you how long it takes to pronounce each number in that set. Then your question is how to calculate t([1..1000000])

and we will useM=t([1..999])

Time of triplet in function of previous

To read a large number, we start from the left and read three-digit groups. The group on the left, of course, can only have one or two digits.

Thus, for each number of x

thousands, you say x thousand y

where y

will describe all the numbers from 1 to 999.

Thus, the time spent in x thousand ...

is 1000 t({1000x}) + M

as follows:

detail of t (1000x)

Note that this formula generalizes to numbers below 1000 by simply defining t({0}) = 0

.

Now the time to say "x thousand" is, according to our hypothesis, equal to the time to say "x" plus the time to say "thousand" (when x> 0). So your answer is:

sum to a million

Where tau (thousand)is the time it takes to say the word thousand. This assumes that you say 1000 as "thousand". You can delete 1000 tau("one")

if you only said "thousand".

As much as I link to the link:

Numbers 100-199 start with a hundred ... or a hundred ...

You can express the time it takes to count to a billion from tau (million)and above in the same way , etc. for all large powers 10 3 i.e. generalization

Taking into account the "and"



There is a small amendment. Suppose that M

is the time it takes to pronounce the numbers 1 through 999 when preceded by at least a group of non-0 numbers, including the leading "and" s .

Our link (well, the wordreference link I linked) says this:

What do we say to join the groups? We usually don't use a single word. The last group is an exception. If the last group after thousands is 1-99, it connects with and.

Thus, our correction only applies to numbers from 0 to 999 (where there is no non-zero group preceding):

time from 1 to 999

Getting M

Rather, let it turn out t ([1.999]), since it is more natural, and we know how it is related to M.

Let C = t([1..99])

, X = t([1..9])

.

Between 1 and 999 we have all the numbers from [1.99] and all nine exact hundreds where you don't say "and", that is, 108 cases. There are 900 numbers with a prefix of hundreds.

Thus, from 1 to 999

C is probably hard to break, so I won't try.

Final result

Corrected formula: count to 1 billion as f (M)

And as a function of C and X: count to 1 billion as f (C, X)

Note that your measures tau (word), C and X must be very precise if you plan to do this multiplication and have any correct order of magnitude.

Conclusion: Brits end up saying "and" a lot. The best part about the last wording is that you can remove all the "and" s if you decide you don't really want to say them.

+3


source







All Articles