- 50.9k
- 11
- 133
- 364
Add++, 4835 bytes
D,f,@,3@%2@%3*1+10*
D,g,@,0@-3>
_
$f,?
-G
$g,x
OA6$%0=@20$%0=A3$%0=A8<A43<s1<
This works on the theory that all McNugget numbers are greater than 3 after having gone through the following process:
- modulo the number by 3
- modulo the result by 2
- multiply that by 3
- add 1
- multiply the number by 10
- subtract that from the initial value
- negate the result
Which is what the function f does in the code abovemonths later, I realised that this was invalid, and fixed it. The function g then checks whetherSomehow, that golfed it by 13 bytes. This is less than 3a function that takes one argument and returnstests whether that argument is a boolean valueChicken 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]
Add++, 48 bytes
D,f,@,3@%2@%3*1+10*
D,g,@,0@-3>
_
$f,?
-G
$g,x
O
This works on the theory that all McNugget numbers are greater than 3 after having gone through the following process:
- modulo the number by 3
- modulo the result by 2
- multiply that by 3
- add 1
- multiply the number by 10
- subtract that from the initial value
- negate the result
Which is what the function f does in the code above. The function g then checks whether it is less than 3 and returns a boolean value.
Add++, 35 bytes
D,f,@,A6$%0=@20$%0=A3$%0=A8<A43<s1<
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]
Add++, 48 bytes
D,f,@,3@%2@%3*1+10*
D,g,@,0@-3>
_
$f,?
-G
$g,x
O
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.
This works on the theory that all McNugget numbers are greater than 3 after having gone through the following process:
- modulo the number by 3
- modulo the result by 2
- multiply that by 3
- add 1
- multiply the number by 10
- subtract that from the initial value
- negate the result
Which is what the function f does in the code above. The function g then checks whether it is less than 3 and returns a boolean value.