The Chick Peck Problem

So, my plans for my blog through 2017 have not quite gone to plan, but things have been horrendously busy, and it seems like the rest of the year is likely to continue this way.

But I did get a chance to do some recreational mathematics, spurred on my a story in the news. It's to do with a problem presented at the 2017 Raytheon MATHCOUNTS® National Competition and reported in the New York Times. Here's the question as presented in the press:

Kudos to 13 year old Texan, Luke Robitialle, who got this right.

With a little thought, you should be able to realise that the answer is 25. For any particular chick, there are four potential out comes, each with equal probability. Either the chick is
• pecked from the left
• pecked from the right
• pecked from left and right
• not pecked at all
Only one of these options results in the chick being unpecked, and so the expected number of chicks unpecked in a circle of 100 is one quarter of this number, or 25.

ABC journalist and presenter extraordinaire, Leigh Sales, tweeted
But it's the kind of maths that makes me ask more questions.

While 25 is the expected number of unpecked chicks, what is the distribution of unpecked chicks? What I mean by this is that they peck left or right at random, there might be 24 unpecked chicks for one group of a hundred chicks, 25 for the next, and 23 for the next. So, the question is, given a large number of 100 chick experiments, what's the distribution of unpecked chicks?

I tried to find an analytic solution, but my brain is old, and so I resorted to good old numerical methods. Generate lots of experiments on a computer, and see what the outcomes look like. But there is an issue that we have to think about, namely the question of how many different configurations of chicks pecking left and right can have?

Well, left and right are two options, and for 100 chicks, the number of possible left and right configurations is

That's a lot of possibilities! How are we going to sample these?

Well, if we treat a 0 as "chick pecks to the left", and 1 as "check pecks to the right", then if we choose a random integer between 0 and 2100-1,  and represent it as a binary number, then that will be a random sampling of the pecking order (pecking order, get it!) As an example, all chicks peck to the left would be 100 0s in binary, where as all the chicks peck to the right would be 100 1s in binary.

Let's try a randomly drawn integer in the range. We get (in base 10) 333483444300232384702347234. In binary this is

`0000000000010001001111011001110111011011110101101010111100001100011100100110100100000111011111100010`
`So, the first bunch of chicks peck to the left, then we have a mix of right to left pecks. `
`But how many of these chicks are unpecked (remembering what the original question)? Well, for any particular chick, it will be unpecked if the chick to its left pecks to the left, and the chick to its right pecks to the right. So, we're looking for sequences of '001' and '011', with the middle digit representing the chick we are interested in. `
`So, we can chick this into a little python code (had to learn it, all the cool kids are using it these days) and this is what I have`
`There is a little extra in there to account for the fact that the chicks are sitting in a circle, but as you can see, the code is quite compact.`
`OK. Let's run for the 100 chicks in the question. What do we get?`
`Yay! The unpecks peak at 25, but there is a nice distribution (which, I am sure, must have an analytic solution somewhere. `
`But given the simplicity of the code, I can easily change the number of chicks. What about 10 chicks in circle?`
`Hmmm. Interesting. What about 1000 chicks?`
`And 33 chicks?`
`Most likely number of unpecked chicks is 8, but again, a nice distribution. `
`Now, you might be sitting there wondering why the heck I am doing this? Well, firstly, because it is fun! And interesting! It's a question and it is fun to find the answer. `
`Secondly it is not obvious what the distribution would be, and how complex it would be to derive, or even if it exists, and so a numerical approach allows us to find an answer. `
`Finally, I can easily generalize this to questions like "what if the left pecks are more likely than right pecks by a factor of two, what would the distribution be like?" It would just take a couple of lines of code and I would have an answer. `
`And if you can't see how such curiosity led examinations are integral to science, then you don't know what science is.`

1. I have re-blogged this at https://newtonexcelbach.wordpress.com/2017/06/16/counting-non-pecked-chicks/ with some added Excel and VBA versions.

You probably won't be very impressed with the pure Excel versions (which are much slower), but you might like the Excel/xlwings link to your Python code.

2. I cannot truly enable but admire your weblog, your weblog is so adorable and great.It has given me courage to try scarier things. I tend to steer clear of them but not anymore.

3. Packers and Movers Gurgaon Provide Reliable, Safe and Certified Service Provider list, Get Free ***Best Price Quotaition and Compare Charges. ???Hassle free Household Shifting Services, High Quality packing Material, Office Relocation, Car Transportaion, ###Local and Domestic Shifting Service @
Packers And Movers Gurgaon

4. Excellent and decent post. I found this much informative, as to what I was exactly searching for. Thanks for such post and please keep it up.
Transportation Service Packer & Mover in Gurgaon

5. Really impressive post. I read it whole and going to share it with my social circules. I enjoyed your article and planning to rewrite it on my own blog
Packers And Movers Gurgaon
Packers And Movers Mirpur Gurgaon
Packers And Movers Khor Gurgaon
Packers And Movers Jawasi Gurgaon
Packers And Movers Indir Mewat Gurgaon

6. A suggested Incall or Outcall Mumbai Escorts Service ability in five star Hotels (Dial-9100000000).A wide variety of Independent Escorts in Mumbai

Mumbai Escorts Models | Mumbai Model Escorts | Cheap Mumbai Escorts | Mumbai Independent Escorts | Escorts Girls in Mumbai | Mumbai Escorts Girls | Call Girls Mumbai | College Escort in Mumbai | Escorts Service Mumbai| Mumbai Escorts

7. QuickBooks Error 12152 is most common errors that everyone may face these problems ,
our team at QuickBooks Customer Service provide solutions for your quickbooks accounting software

8. Nice blog !! Are You looking for QuickBooks Solution QuickBooks Software For any issue then
connect our team at QuickBooks Customer Service

9. Really I m feeling very happy after read your article just click get QuickBooks Solution information at QuickBooks Customer Service

10. Your post is truly awesome. It is appreciable piece of efforts done by you.

Kirti Pathak

11. Such a Nice and Informative Post. Thanks for Sharing
Pakistan Cargo Dubai