Chicken McNugget Numbers

29

4

Description

Chicken McNugget numbers are numbers that can be expressed as a sum of 6, 9 or 20 - the initial sizes of the famous Chicken McNuggets boxes sold by McDonald's. In that sum, a number may occur more than once, so 6 + 6 = 12 is such a number too, and the number must "contain" at least one of the mentioned sizes. The first Chicken McNugget numbers are:

6
9
6 + 6 = 12
6 + 9 = 15
9 + 9 = 6 + 6 + 6 = 18
20
6 + 6 + 9 = 21
...

Challenge

Your task is to write a program or function, that, given a positive integer, determines whether this number can be expressed in the described way, therefore is such a Chicken McNugget number. It should then output a truthy or falsy value based on its decision.

Test cases

6 -> true
7 -> false
12 -> true
15 -> true
21 -> true
40 -> true
42 -> true

This is , so the shortest answer in bytes wins and the standard loopholes apply!

racer290

Posted 2017-07-16T18:05:34.523

Reputation: 1 043

15

It should be noted that "All integers are McNugget numbers except 1, 2, 3, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 22, 23, 25, 28, 31, 34, 37, and 43." (mathworld)

– Leaky Nun – 2017-07-16T18:06:38.323

1Well, then let's take it as a compression challenge, but thanks for the note – racer290 – 2017-07-16T18:08:24.187

@Leaky Nun Also, I haven't spotted a proof for that yet.. – racer290 – 2017-07-16T18:14:43.067

1@racer290 With 6 and 9 you can get to any multiple of 3 which is >3. By subtracting 0,20,40 from your number you will get to a multiple of 3 and therefore there can't be any McNuggets number >43. – ovs – 2017-07-16T18:21:26.253

Related – HyperNeutrino – 2017-07-16T18:21:44.267

@HyperNeutrino Hell yea when i posted it on meta another one was mentioned but not this one. – racer290 – 2017-07-16T18:27:15.043

3Anybody have an OEIS link for this??? – CraigR8806 – 2017-07-17T11:44:50.883

2

What do you have against the 4 piece nugget pack? https://www.mcdonalds.com/us/en-us/product/chicken-mcnuggets-4-piece.html

– Dan is Fiddling by Firelight – 2017-07-17T19:25:51.003

@LeakyNun it's not a competitive approach though heh... https://codegolf.stackexchange.com/a/132856/59376

– Magic Octopus Urn – 2017-07-17T22:16:57.583

2numberphile... – Jason C – 2017-07-17T22:20:22.973

Answers

37

Python, 27 bytes

lambda n:0x82492cb6dbf>>n&1

Try it online!

Anders Kaseorg

Posted 2017-07-16T18:05:34.523

Reputation: 29 242

11What is this magical code o_O this is amazing – HyperNeutrino – 2017-07-16T19:17:27.303

You can remove the ~ because you can swap the outputs. – Leaky Nun – 2017-07-16T19:52:12.293

1Also, 8953174650303 has the exact same length with 0x82492cb6dbf (albeit less readable). – Leaky Nun – 2017-07-16T19:52:55.357

2@HyperNeutrino the magic number has only those bits set which correspond to numbers that are not Chicken McNugget numbers. Look at its binary representation and it'll be much clearer. – David Z – 2017-07-16T20:44:43.687

@DavidZ Oh hm. That is very smart. Nice. – HyperNeutrino – 2017-07-16T20:45:35.690

1Shame you can't easily use this same idea with base 64 – Jacob Garby – 2017-07-18T01:39:29.413

Shouldn’t you add ^1? It’s supposed to say true for CMNN. – FrownyFrog – 2017-10-10T12:41:22.117

@FrownyFrog See this comment.

– Anders Kaseorg – 2017-10-10T20:54:30.497

29

Python 3, 24 bytes

lambda n:0<=n--n%3*20!=3

Try it online!

Explanation

With 6 and 9 alone, one can make all integers divisible by 3 which are greater than 3, as is stated in ovs's comment to the challenge. It is assumed that one can also make 0. In conclusion, one can make 0,6,9,12,15,....

With one instance of 20, one can make: 20,26,29,32,35,....

With two instances of 20, one can make: 40,46,49,52,55,....

Three instances is never necessary, for 3 x 20 = 10 x 6.


Notice that the cases where no 20 is needed is also divisible by 3; the cases where one 20 is needed leaves a remainder of 2; the cases where two 20 is needed leaves a remainder of 1.

The number of 20 needed can hence be calculated by (-n)%3. Then, we do n-(((-n)%3)*20) to remove the number of 20 needed from the number. We then check that this number is non-negative, but is not 3.

Leaky Nun

Posted 2017-07-16T18:05:34.523

Reputation: 45 011

39 bytes – Mr. Xcoder – 2017-07-16T18:41:14.973

@Mr.Xcoder updated. – Leaky Nun – 2017-07-16T18:43:24.803

f=lambda n:n%3<1<n-2or n>20and f(n-20) does that work? – Zacharý – 2017-07-16T18:43:51.930

@Zacharý thanks, updated. – Leaky Nun – 2017-07-16T18:45:16.610

37 bytes. – notjagan – 2017-07-16T18:46:07.267

@notjagan wow, I didn't know that chaining is short-circuiting. – Leaky Nun – 2017-07-16T18:47:50.283

1You can remove the f= now since it's not recursive. – notjagan – 2017-07-16T19:13:59.770

@xnor Is it ok now? – Leaky Nun – 2017-07-16T19:27:29.400

Ah, you ninja'd me! I was about to suggest this, but yours is shorter anyhow.

– notjagan – 2017-07-16T19:27:58.557

Yes, checked it. Nice method!

– xnor – 2017-07-16T19:29:43.250

i'm assuming there is a general mathematical theory similar to the technique used here, for solving generalized versions of the same problem. do you know what it's called? – Jonah – 2017-07-16T20:21:00.573

@Jonah Chinese Remainder Theorem? – Leaky Nun – 2017-07-16T20:26:20.590

@LeakyNun that'll do just fine. ty. – Jonah – 2017-07-16T20:37:32.797

Looks like the post has been updated to exclude 0; I think that saves you a byte? – David Z – 2017-07-16T20:38:17.737

@DavidZ The 0 is still needed for 20 and 40. – Leaky Nun – 2017-07-16T20:47:27.397

Ah, true. But still the function currently gives an incorrect result for input 0. – David Z – 2017-07-16T20:48:38.893

8

Python 2, 28 bytes

lambda n:-n%3-n/20<(n%20!=3)

Try it online!

xnor

Posted 2017-07-16T18:05:34.523

Reputation: 115 687

Using some trial-and-error and mapping the first part to the range, I have a rough idea of how it works. However, I would like to know how you came up with this solution. – Leaky Nun – 2017-07-16T19:51:42.777

@LeakyNun Funny, I thought this was the natural method and yours was the clever one :). I noted the possible values of (n%3,n/20) from your excluded list are {(2, 0), (1, 0), (1, 1)}. Using -n%3 instead gave an inequality n/20>=(-n)%3. From there, I fiddled a while to reverse {3,23,43} which are 3 mod 20 without affecting 63,83,... I found shifting the inequality endpoint for these worked nicest. – xnor – 2017-07-16T19:58:43.447

Well my method involves really solving the problem whereas your method is fiddling with the values in the excluded list, so I'd say that my method is more natural :) – Leaky Nun – 2017-07-17T04:08:58.570

7

Jelly, 11 bytes

ṗ3’æ.“©µÞ‘ċ

Try it online!

How it works

ṗ3’æ.“©µÞ‘ċ  Main link. Argument: n

ṗ3           Cartesian power; yield all 3-tuples over [1, ..., n].
  ’          Decrement all coordinates.
     “©µÞ‘   Yield [6, 9, 20].
   æ.        Take the dot product of each 3-tuple and [6, 9, 20].
          ċ  Count the occurrences of n (Positive for Chicken McNuggets numbers).

Dennis

Posted 2017-07-16T18:05:34.523

Reputation: 196 637

4Chicken McNuggets™ and Jelly! Mmmm!!! – CJ Dennis – 2017-07-17T03:14:47.493

@CJDennis Actually it's Chicken McNuggets© and Jelly. – caird coinheringaahing – 2017-07-17T05:20:59.850

@cairdcoinheringaahing Actually it's Chicken McNuggets® and Jelly. – Dan – 2017-07-18T16:35:55.927

5

Haskell, 36 bytes

f n|n<1=n==0
f n=any(f.(n-))[6,9,20]

Try it online!

Explanation

This solution is about as straightforward as it can get. The first line declares that for any number less than 1 it is a McNugget number if n==0. That is to say that 0 is a McNugget number and all negative numbers are not.

The second line declares that for all other numbers, n is a McNugget number if it minus any of the Nugget sizes is a McNugget number.

This is a pretty simple recursive search.

Post Rock Garf Hunter

Posted 2017-07-16T18:05:34.523

Reputation: 55 382

3

Jelly, 11 bytes

_20$%3$¿o>3

Try it online!

Port of my Python answer, but slightly modified: subtract 20 until divisible by 3, then check whether it belongs to 0,6,9,... by mapping 0 to the input (by using or), and then check if it is greater than 3.

The only three numbers that produce 0 upon completing the first step is 0, 20, or 40, with the first one being out of the domain, and the rest being greater than 3.

Leaky Nun

Posted 2017-07-16T18:05:34.523

Reputation: 45 011

I dont get how to enter the input.. – racer290 – 2017-07-16T18:32:11.957

@racer290 Command-line argument. – Erik the Outgolfer – 2017-07-16T18:32:33.867

3

Python 3, 48 46 42 bytes

lambda n:n+50in b'2345679:<=?@BCEHIKNQTW]'

Try it online!

Switches True and False.

notjagan

Posted 2017-07-16T18:05:34.523

Reputation: 4 011

You can switch True and False by default – Mr. Xcoder – 2017-07-16T18:43:06.420

3

Mathematica, 53 bytes

!Flatten@Table[Tr/@Tuples[{6,9,20},i],{i,#}]~FreeQ~#&

J42161217

Posted 2017-07-16T18:05:34.523

Reputation: 15 931

Maybe you can use the FrobeniusSolve function. – alephalpha – 2017-07-17T00:39:01.413

3

Mathematica, 30 bytes

{6,9,20}~FrobeniusSolve~#!={}&

Try it on Wolfram Sandbox.

Keyu Gan

Posted 2017-07-16T18:05:34.523

Reputation: 2 028

3

Mathematica, 20 bytes

0<=#-20Mod[-#,3]!=3&

Anonymous function. Takes a number as input and returns True or False as output. Logic copied from Leaky Nun's answer, with some added abuse of Inequality.

LegionMammal978

Posted 2017-07-16T18:05:34.523

Reputation: 15 731

3

x86-64 Machine Code, 22 bytes

48 B8 41 92 34 6D DB F7 FF FF 83 F9 40 7D 03 48 D3 E8 83 E0 01 C3

The above bytes define a function in 64-bit x86 machine code that determines whether the input value is a Chicken McNugget number. The single positive integer parameter is passed in the ECX register, following the Microsoft 64-bit calling convention used on Windows. The result is a Boolean value returned in the EAX register.

Ungolfed assembly mnemonics:

; bool IsMcNuggetNumber(int n)
; n is passed in ECX
    movabs  rax, 0xFFFFF7DB6D349241   ; load a 64-bit constant (the bit field)
    cmp     ecx, 64
    jge     TheEnd                    ; if input value >= 64, branch to end
    shr     rax, cl
TheEnd:
    and     eax, 1                    ; mask off all but LSB
    ret

Obviously, this plays heavily off of Anders Kaseorg's solution in Python, in that it is based around a bit-field representing the values that are Chicken McNugget numbers. Specifically, each bit in this field that corresponds to a valid Chicken McNugget number is set to 1; all other bits are set to 0. (This considers 0 to be a valid Chicken McNugget number, but if you don't like that, your preference is a single-bit modification away.)

We start off by simply loading this value into a register. It is a 64-bit value, which already takes 8 bytes to encode, plus we need a one-byte REX.W prefix, so we are really being quite spendthrift in terms of bytes, but this is the heart of the solution, so I guess it's worth it.

We then shift the field right by the input value.* Finally, we mask off all but the lowest-order bit, and that becomes our Boolean result.

However, since you cannot shift by more than the number of bits actually in the value, this works only for inputs from 0–63. To support higher input values, we insert a test at the top of the function that branches to the bottom of the input value is >= 64. The only thing interesting about this is the we preload the bit-field constant in RAX, and then branch down to the instruction that masks off the lowest-order bit, thus ensuring that we always return 1.

Try it online!
(The C function call there is annotated with an attribute that causes GCC to call it using the Microsoft calling convention that my assembly code uses. If TIO had provided MSVC, this wouldn't be necessary.)

__
* As an alternative to a shift, we could have used the x86 BT instruction, but that's 1 byte longer to encode, so no advantage. Unless we were forced to use a different calling convention that didn't conveniently pass the input value in the ECX register. This would be a problem because SHR requires that its source operand be CL for a dynamic shift count. Therefore, a different calling convention would require that we MOVed the input value from whatever register it was passed in to ECX, which would cost us 2 bytes. The BT instruction can use any register as a source operand, at a cost of only 1 byte. So, in that situation, it would be preferable. BT puts the value of the corresponding bit into the carry flag (CF), so you would use a SETC instruction to get that value in an integer register like AL so it could be returned to the caller.


Alternative implementation, 23 bytes

Here is an alternative implementation that uses modulo and multiplication operations to determine whether the input value is a Chicken McNugget number.

It uses the System V AMD64 calling convention, which passes the input value in the EDI register. The result is still a Boolean, returned in EAX.

Note, though, that unlike the above code, this is an inverse Boolean (for implementation convenience). It returns false if the input value is a Chicken McNugget number, or true if the input value is not a Chicken McNugget number.

                    ; bool IsNotMcNuggetNumber(int n)
                    ; n is passed in EDI
8D 04 3F            lea    eax, [rdi+rdi*1]   ; multiply input by 2, and put result in EAX
83 FF 2B            cmp    edi, 43
7D 0E               jge    TheEnd             ; everything >= 43 is a McNugget number
99                  cdq                       ; zero EDX in only 1 byte
6A 03               push   3
59                  pop    rcx                ; short way to put 3 in ECX for DIV
F7 F1               div    ecx                ; divide input value by 3
6B D2 14            imul   edx, edx, 20       ; multiply remainder of division by 20
39 D7               cmp    edi, edx
0F 9C C0            setl   al                 ; AL = (original input) < (input % 3 * 20)
                 TheEnd:
C3                  ret

What's ugly about this is the need to explicitly handle input values >= 43 by a compare-and-branch at the top. There are obviously other ways of doing this that don't require branching, like caird coinheringaahing's algorithm, but this would take a lot more bytes to encode, so isn't a reasonable solution. I figure I'm probably missing some bit-twiddling trick that would make this work out more elegantly and be fewer bytes than the bitfield-based solution above (since encoding the bitfield itself takes so many bytes), but I've studied this for a while and still can't see it.

Oh well, try it online anyway!

Cody Gray

Posted 2017-07-16T18:05:34.523

Reputation: 2 639

3

05AB1E, 17 16 bytes

ŽGç₂в©IED®âO«]I¢

Try it online!

Explanation

  ŽGç₂в                 The list [6, 9, 20]
       ©                Store this list in register_c
        IE              Loop <input> number of times
           ®â           Cartesian product stack contents with list in register_c
             O          Sum up the contents of each sub array
          D   «         List duplicated before taking Cartesian product, concat
               ]        End for loop
                I¢      Count occurences of input

rev

Posted 2017-07-16T18:05:34.523

Reputation: 39

1You have duplicate TIO links. – Embodiment of Ignorance – 2019-03-12T20:27:44.787

1Nice answer. Welcome to PPCG and the world of 05AB1E. :) One thing to golf is to use for the string (there are buitins for 1-, 2-, and 3-char strings, being ', , and respectively). I have the feeling more can be golfed, perhaps by using a different approach, but regardless this is a nice first answer. +1 from me. – Kevin Cruijssen – 2019-03-13T11:52:27.780

1

Was indeed correct. Found a 12-byter by utilizing the builtin Åœ: … ÇIÅœåPOĀ. It's a completely different approach, so if you want me to post it as a separated answer rather than a golf of yours, let me know. PS: I'm not 100% sure if the unprintables are allowed in the 05AB1E codepage. It might have to be in a different encoding in that case, which would make some characters count as 2 bytes each instead.. In that case ŽBo21в could be an alternative for +1 byte.

– Kevin Cruijssen – 2019-03-13T12:12:47.173

Like Kevin mentions, neither of the 3 bytes in your string are in the 05ab1e code page and thus can't be used without counting the whole program in utf-8 which would make it a lot longer. You can however use ŽGç₂в instead of the string while simultaneously saving a byte in the process. – Emigna – 2019-03-13T12:32:21.963

Kevin, go for it. It'd be nice to see different approaches. Emigna, thanks for you suggestion, I will make the change – rev – 2019-03-13T13:00:38.937

2

JavaScript (ES6), 69 64 bytes

n=>'ABCDEFHIKLNOQRTWXZ]`cfl'.includes(String.fromCharCode(n+65))

f=
n=>'ABCDEFHIKLNOQRTWXZ]`cfl'.includes(String.fromCharCode(n+65))
<input onkeydown=a.innerHTML=f(this.value)>
<pre id=a>

Outputs false for Chicken McNugget numbers, true otherwise.

darrylyeo

Posted 2017-07-16T18:05:34.523

Reputation: 6 214

I'd like at least a "try it" link.. – racer290 – 2017-07-16T18:52:58.700

@racer290 Added. – darrylyeo – 2017-07-16T18:55:52.990

n=>~'ABCDEFHIKLNOQRTWXZ]`cfl'.search(String.fromCharCode(n+65)) for 63 bytes – Oki – 2017-07-16T23:00:34.353

2

Java, 21 57 24 bytes

Try it online!

Golfed:

n->(n-=n*2%3*20)>=0&n!=3

Ungolfed:

import java.util.*;

public class ChickenMcNuggetNumbers {

  private static final Set<Integer> FALSE_VALUES = new HashSet<>(Arrays.asList(
    new Integer[] { 0, 1, 2, 3, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 22, 23,
    25, 28, 31, 34, 37, 43 }));

  public static void main(String[] args) {
    for (int i = 0; i < 45; ++i) {
      System.out.println(i + " -> expected=" + !FALSE_VALUES.contains(i)
        + ", actual=" + f(n->(n-=n*2%3*20)>=0&n!=3, i));
    }
  }

  public static boolean f(java.util.function.Function<Integer, Boolean> f, int n) {
    return f.apply(n);
  }
}

user18932

Posted 2017-07-16T18:05:34.523

Reputation:

Result is wrong for 26 = 20 + 6. – Leaky Nun – 2017-07-17T04:01:10.267

@LeakyNun Algorithm was too naive. I had to go with plan B which added some bytes, but appears to produce correct results all of the time now. I should have iterated all of the values to begin with instead of relying on the test cases in the question. – None – 2017-07-17T04:10:53.237

35 bytes – Leaky Nun – 2017-07-17T04:34:14.577

25 bytes (with community override on 0) – Leaky Nun – 2017-07-17T04:38:24.473

124 bytes (see above) – Leaky Nun – 2017-07-17T05:26:15.600

1@LeakyNun thanks! I still have a lot to learn about golfing. – None – 2017-07-17T16:18:38.440

Could golf a byte with "&n>3" instead of "&n!=3" – Hugh Nolan – 2017-07-18T13:58:25.267

1

Python 2, 51 bytes

-1 byte thanks to @LeakyNun

lambda n:max(n>43,25<n>n%3>1,5<n>n%3<1,n in[20,40])

Try it online! Footer prints all non McNugget numbers

ovs

Posted 2017-07-16T18:05:34.523

Reputation: 21 408

n%3 can only be 0 or 1 or 2, so n%3==2 is equivalent to n%3>1. – Leaky Nun – 2017-07-16T18:51:24.173

1

Pyth, 15 bytes

fg.{CM"     "{T./

Try it online!

The string contains the characters corresponding to codepoints 6, 9, and 20.

notjagan

Posted 2017-07-16T18:05:34.523

Reputation: 4 011

1

Javascript, 92 78 72 bytes

*saved 14 bytes thanks to @Jonasw

a=>!(a in[0,1,2,3,4,5,7,8,10,11,13,14,16,17,19,22,23,25,28,31,34,37,43])

Uses the fact that "All integers are McNugget numbers except 1, 2, 3, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 22, 23, 25, 28, 31, 34, 37, and 43." from @LeakyNun's comment

SuperStormer

Posted 2017-07-16T18:05:34.523

Reputation: 927

using a simple array would save the bytes for .split ... – Jonas Wilms – 2017-07-17T09:23:46.010

@Jonas array is 108 bytes, splitted string is 73 bytes – SuperStormer – 2017-07-17T11:09:07.493

um http://jsbin.com/bucihuqefi/edit?console -11 bytes...

– Jonas Wilms – 2017-07-17T11:19:59.260

1

Haskell, 64 56 bytes

I didn't do any bit trickery, but looking at the other answers it might actually be shorter to import the Bits module and use those methods. This approach checks much more directly.

f x=(\l->elem x[i*6+j*9+k*20|i<-l,j<-l,k<-l,x/=0])[0..x]

qfwfq

Posted 2017-07-16T18:05:34.523

Reputation: 181

1

The byte count is 66 not 64. But you you can save a lot of parenthesis and put an x/=0 guard to save some bytes, see here.

– ბიმო – 2017-07-17T01:21:48.440

1

Add++, 35 bytes

D,f,@,A6$%0=@20$%0=A3$%0=A8<A43<s1<

Try it online!

Look ma, no while loops. Or strings. Or lists. Or really anything that helps save bytes. But mainly because Add++ doesn't know what any of those are.

3 months later, I realised that this was invalid, and fixed it. Somehow, that golfed it by 13 bytes. This is a function that takes one argument and tests whether that argument is a Chicken McNugget number or not.

How it works

D,f,@,                        - Create a monadic (one argument) function called f (example argument: 3)
A                             - Push the argument again; STACK = [3 3]
 6                            - Push 6;                  STACK = [3 3 6]
  $                           - Swap the top two values; STACK = [3 6 3]
   %                          - Modulo;                  STACK = [3 3]
    0                         - Push 0;                  STACK = [3 3 0]
     =                        - Are they equal?          STACK = [3 0]
      @                       - Reverse the stack;       STACK = [0 3]
       20                     - Push 20;                 STACK = [0 3 20]
         $                    - Swap the top two values; STACK = [0 20 3]
          %                   - Modulo;                  STACK = [0 3]
           0                  - Push 0;                  STACK = [0 3 0]
            =                 - Are they equal?          STACK = [0 0]
             A                - Push the argument;       STACK = [0 0 3]
              3               - Push 3;                  STACK = [0 0 3 3]
               $              - Swap the top two values; STACK = [0 0 3 3]
                %             - Modulo;                  STACK = [0 0 0]
                 0            - Push 0;                  STACK = [0 0 0 0]
                  =           - Are they equal?          STACK = [0 0 1]
                   A          - Push the argument;       STACK = [0 0 1 3]
                    8         - Push 8;                  STACK = [0 0 1 3 8]
                     <        - Less than;               STACK = [0 0 1 0]
                      A       - Push the argument;       STACK = [0 0 1 0 3]
                       43     - Push 43;                 STACK = [0 0 1 0 3 43]
                         <    - Less than;               STACK = [0 0 1 0 0]
                          s   - Sum;                     STACK = [1]
                           1  - Push 1;                  STACK = [1 1]
                            < - Less than;               STACK = [0]

caird coinheringaahing

Posted 2017-07-16T18:05:34.523

Reputation: 13 702

1

Excel, 87 bytes

=AND(OR(MOD(A1,3)*MOD(A1,20)*IF(A1>43,MOD(A1-40,3),1)*IF(A1>23,MOD(A1-20,3),1)=0),A1>5)

Alternatively, 92 bytes:

=CHOOSE(MOD(A1,3)+1,A1>3,IF(A1>43,MOD(A1-40,3)=0,A1=40),IF(A1>23,MOD(ABS(A1-20),3)=0,A1=20))

Wernisch

Posted 2017-07-16T18:05:34.523

Reputation: 2 534

1

APL (Dyalog), 19 bytes

⊢∊6 9 20+.×⍨∘↑∘⍳3⍴⊢

with ⎕IO←0

Same algorithm with Dennis's answer

Try it online!

TwiNight

Posted 2017-07-16T18:05:34.523

Reputation: 4 187

1

Retina, 26 bytes

.+
$*
^(1{6}|1{9}|1{20})+$

Try it online!

TwiNight

Posted 2017-07-16T18:05:34.523

Reputation: 4 187

1

PHP, 69+1 bytes

for($n=$argn;$n>0;$n-=20)if($n%3<1)for($k=$n;$k>0;$k-=9)$k%6||die(1);

exits with 1 for a Chicken McNugget Number, 0 else.

Run as pipe with -n or try it online.

Titus

Posted 2017-07-16T18:05:34.523

Reputation: 13 814

0

Python 2, 61 bytes

lambda n:n in[int(c,36)for c in'1234578ABDEGHJMNPSV']+[37,43]

Try it online!

Chas Brown

Posted 2017-07-16T18:05:34.523

Reputation: 8 959

Or you could use codepoints and decompress with chr. – Leaky Nun – 2017-07-16T18:42:09.310

0

Mathematica, 59 bytes

!Select[IntegerPartitions@#,{6,9,20}~SubsetQ~#&]=={}&&#!=0&

J42161217

Posted 2017-07-16T18:05:34.523

Reputation: 15 931

0

Pari/GP, 48 bytes

0 is falsy. everything else is truthy.

n->n*Vec(1/(1-x^6)/(1-x^9)/(1-x^20)+O(x^n++))[n]

Try it online!

alephalpha

Posted 2017-07-16T18:05:34.523

Reputation: 23 988

Irrelevant comment : what was the problem with this answer of yours?#~SetPrecision~1& ? – J42161217 – 2017-07-20T12:06:23.567

@Jenny_mathy It fails the 0.25 test case. – alephalpha – 2017-07-20T13:46:05.730

0

Javascript 37 bytes

Takes a positive integer n and outputs true for Chicken McNugget numbers and false for others.

F=n=>!(n<0||(n%6&&!F(n-9)&&!F(n-20)))

Explanation

F=n=>!(            // negate the internal test for non-Chicken McNugget numbers
    n<0 || (       // if n < 0, or
        n%6 &&     // if n % 6 is truthy,
        !F(n-9) && // and n-9 is not a Chicken McNugget number
        !F(n-20)   // and n-20 is not a Chicken McNugget number
                   // then n is not a Chicken McNugget number
    )
)

The recursion on this function is heinous, and for any sufficiently large n, you will exceed call stack limits. Here's a version that avoids those limits by checking if n is larger than the largest non-Chicken McNugget number (43 bytes [bonus points for being the largest non-Chicken McNugget number?]):

F=n=>n>43||!(n<0||(n%6&&!F(n-9)&&!F(n-20)))

F=n=>n>43||!(n<0||(n%6&&!F(n-9)&&!F(n-20)))

$('#input').on('keyup', () => $('#output').text(F(parseInt($('#input').val(), 10))))
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="input" />
<span id="output"></span>

asgallant

Posted 2017-07-16T18:05:34.523

Reputation: 309

0

JavaScript ES5, 46 bytes

n=>n>5&&(!(n%20)||(n<24?!(n%3):n<44?n%3-1:1));

Explicit boolean answer, 50 bytes:

n=>!!(n>5&&(!(n%20)||(n<24?!(n%3):n<44?n%3-1:1)));

Clumsy, but it gets the job done. Returns false or 0 for every value that isn't 0, 1, 2, 3, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 22, 23, 25, 28, 31, 34, 37, or 43, and true, -1, or 1 for everything else.

Explicit solution returns true or false only.

n=>!!(                                          ); forces Boolean type (optional)
      n>5                                          false for 0, 1, 2, 3, 4, 5 (and negative inputs)
            !(n%20)                                explicit true for 20, 40
                      n<24?!(n%3)                  false for 7, 8, 10, 11, 13, 14, 16, 17, 19, 22, 23
                                  n<44?n%3-1       false for 25, 28, 31, 34, 37, 43

ricdesi

Posted 2017-07-16T18:05:34.523

Reputation: 499

0

Clojure 33 bytes

An on ok quick attempt: #(-> %(rem 20)(rem 9)(rem 6)(= 0))

MONODA43

Posted 2017-07-16T18:05:34.523

Reputation: 131