A narcissist program is a program that only accepts its own source code. A bigotous program is a program that only accepts the source code of programs semantically equivalent to itself. A gang member is somewhere in between.

In particular, we will define a gang as set of programs G, which may or may not be in the same programming language, such that each program, when executed, will only accept members of its gang, and reject everything else (since they all do the same thing, this means that are semantically equivalent). A gang member is a program that is part of a gang, and the set of programs that it accepts is its gang.

So, a narcissist program is a gang of size 1, and a class of bigots is a maximally sized gang (every equivalent program gets to be part of the gang).

Your job is to create a gang of programs. It must be of size at least 2, and can have programs in different languages (you can even count the same program multiple times if it's a polyglot).

Your score is (average length of gang member)/(# of unique programming languages), which you are trying to minimize (so you are rewarded for using different languages). It is considered cheating to use built in language features that allow a program to access its own code.

Note: We'll define acceptance v.s. rejection via https://codegolf.meta.stackexchange.com/a/12685/16842 or https://codegolf.meta.stackexchange.com/a/12684/16842, your choice.


closed as unclear what you're asking by Mego, Timtech, ETHproductions, R. Kap, mbomb007 Jun 2 '17 at 2:43

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 5
    \$\begingroup\$ What does "accept" mean? Can acceptance and rejection be the output of two different values? \$\endgroup\$ – L3viathan Jun 1 '17 at 20:57
  • 1
    \$\begingroup\$ Full programs only, or are functions allowed? \$\endgroup\$ – Stephen Jun 1 '17 at 20:58
  • \$\begingroup\$ @L3viathan I think using this criteria would be best. \$\endgroup\$ – PyRulez Jun 1 '17 at 22:13
  • \$\begingroup\$ @StephenS functions are fine \$\endgroup\$ – PyRulez Jun 1 '17 at 22:13
  • \$\begingroup\$ IMHO, you should explicitly define exactly what "accept"/"reject" mean in the question; it's unclear as it currently stands. \$\endgroup\$ – ETHproductions Jun 1 '17 at 23:44

0 points (average length 0 bytes, 2 unique language)

I'm assuming we can define acceptance and rejection as the output of two different values.

The gang size is 2 (the languages are 05AB1E and 2sable), and the program is the empty program.

For some reason, both an empty 05AB1E program and an empty 2sable program appear to outputs 2 (plus a newline in the case of 2sable) when the input is not empty (i.e. a different program; rejection). They output nothing if there is no input (i.e. the same program; acceptance).

Since I "can even count the same program multiple times if its a polygot", these are two programs.

(I know neither 05AB1E nor 2sable at all and just tried golfing languages in TIO until I found some that seemed to work, so this answer might be wrong if they output something else for some specific inputs.)

  • \$\begingroup\$ I'm assuming OP will edit in a restriction of "no empty programs" - it is quine after all \$\endgroup\$ – Stephen Jun 1 '17 at 21:13
  • \$\begingroup\$ @totallyhuman It's not clear to me whether that refers to the gang size or the program size. \$\endgroup\$ – L3viathan Jun 1 '17 at 21:13
  • 1
    \$\begingroup\$ Clever abuse of the rules... \$\endgroup\$ – Neil A. Jun 1 '17 at 21:37
  • 1
    \$\begingroup\$ @StephenS I think its already implied due to codegolf.meta.stackexchange.com/a/5337/16842. \$\endgroup\$ – PyRulez Jun 1 '17 at 22:18
  • 1
    \$\begingroup\$ The empty Charcoal program outputs Parsing failed whether or not the input is empty—it does not get as far as reading the input. \$\endgroup\$ – Anders Kaseorg Jun 1 '17 at 22:20

140.75 points (average length 281.5 bytes, 2 unique languages)

These programs use cryptographic hashing to identify the gang members, and the first line of each program is identical and encodes the hash of the remainder of each program. Each program then compares the first line to the given list and the hash of the remainder, and returns true/True if it's accepted and false/False if it's rejected.

JavaScript (Node.js), 338 bytes


Python 2, 225 bytes

import hashlib,sys,json
print I.read(121)=='x='+json.dumps(x,separators=',:')and hashlib.sha224(I.read()).hexdigest()in x
  • \$\begingroup\$ What about hash collisions? \$\endgroup\$ – PyRulez Jun 2 '17 at 19:26

∞ points (Average length ∞, 1 unique language)

I might not win the challenge, but I sure have the biggest gang. (Watch out!)

main=interact$ \x->if length(lines x)==1&&take 279x==quine q++"--"then"Yarr!"else"It's one of them PyRulez guys!";quine s=s++show s;q="main=interact$ \\x->if length(lines x)==1&&take 279x==quine q++\"--\"then\"Yarr!\"else\"It's one of them PyRulez guys!\";quine s=s++show s;q="--

The language is Haskell. You can keep adding any letter to the end of the program except newlines. Outputs Yarr! for gang members and It's one of them PyRulez guys! for everything else.

141.9 points (Average length 141.9 bytes, 1 unique language, 255 gang members)

f x=elem '\n'x||take 141x/=k q++"--"||length x>142;k s=s++show s;q="f x=elem '\\n'x||take 141x/=k q++\"--\"||length x>142;k s=s++show s;q="--
  • \$\begingroup\$ +1 for having the worst possible entry. (I was wondering whether I needed to put in a rule about infinitely large gangs, but then I realized I didn't need to.) \$\endgroup\$ – PyRulez Jun 1 '17 at 22:31
  • \$\begingroup\$ Also, you can decrease your score substantially if you remove some of the longer gang members. \$\endgroup\$ – PyRulez Jun 1 '17 at 22:47

0 points (Average length 24 bytes, ∞ unique languages)

This is noncompeting since the MetaGolfScript family is banned, but I thought it would be fun to post it anyways.

The languages are MetaGolfScript-N, for every natural number N. There is one program in each language, which all have the following source code:

{s ":p`:s;p" + =}:p`:s;p
  • \$\begingroup\$ The real question is which infinitely large gang would win in a gang fight, mine or the @BlackCap gang. \$\endgroup\$ – PyRulez Jun 1 '17 at 23:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.