## McNugget Numbers

### December 9, 2011

At McDonalds’ Restaurants, the Chicken McNugget meals are available in sizes of 6 McNuggets, 9 McNuggets, or 20 McNuggets. A number is a McNugget number if it can be the sum of the number of McNuggets purchased in an order (before eating any of them). Henri Picciotto devised the math of McNugget numbers in the 1980s while dining with his son at McDonald’s, working the problem out on a napkin.

Your task is to determine all numbers that are not McNugget numbers. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

[…] today’s Programming Praxis exercise, our goal is to determine all the numbers that are not McNugget […]

My Haskell solution (see http://bonsaicode.wordpress.com/2011/12/09/programming-praxis-mcnugget-numbers/ for a version with comments):

[…] response to this challenge McNugget numbers I wrote C code based on a different approach than exhibited in the LISP solution and obviously […]

My independent C solution: http://ctopy.wordpress.com/2011/12/09/mcnugget-numbers-c-solution/

[…] I heard from my friend about the new programming praxis problem I started thinking how to implement the solution. I wrote down the numbers from 1 to 20 and […]

Python solution along the same lines as the C one, but self-documenting,

My thinking is described here: http://ctopy.wordpress.com/2011/12/09/mcnugget-numbers-python-solution/

I’ve tried to make a Haskell solution using somewhat less mathematical knowlegde (for example the one that we only have to check the numbers smaller than 180).

The ugly function mc calculates the infinite list of McNugget numbers in increasing order. For example the first 50:

And notmc gives the solution /it stops if 6 consecutive McNugget numbers are found, because each larger number can be generated easily by adding 6 to them repeatedly/:

Go version here: http://play.golang.org/p/WwY0X0PE3V

And a haskell copy of the popular solution of Tomasz Kwiatkowskis:

[/sourcecode]

notmc = helper [0] [1..]

where helper _ [] = []

helper is (x:xs)

| length is > 5 && head is – 5 == is!!5 = []

| otherwise = if any (\a-> elem a is) [x-6,x-9,x-20]

then helper (x:is) xs

else x:helper is xs

[/sourcecode]

Probably not the most efficient solution, but in relatively short Python:

The use of the procedures from the

`itertools`

module ensures no intermediate lists are constructed.I still don’t get why 181 or 182 is not a mcnugget number. You it can not summed using 6,9,20

22*6 + 1*9 + 2*20 = 181

24*6 + 2*9 + 1*20 = 182

Java approach:

Please I have a question … How it is determined that all numbers after LCM “180” are MCNuggets number?