Let's get the gang back together!

6

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.

PyRulez

Posted 2017-06-01T20:44:53.100

Reputation: 6 547

Question was closed 2017-06-02T02:43:38.503

5What does "accept" mean? Can acceptance and rejection be the output of two different values? – L3viathan – 2017-06-01T20:57:04.663

1Full programs only, or are functions allowed? – Stephen – 2017-06-01T20:58:20.783

@L3viathan I think using this criteria would be best.

– PyRulez – 2017-06-01T22:13:41.720

@StephenS functions are fine – PyRulez – 2017-06-01T22:13:47.947

IMHO, you should explicitly define exactly what "accept"/"reject" mean in the question; it's unclear as it currently stands. – ETHproductions – 2017-06-01T23:44:22.430

Questions should be self-contained in case the linked ones are deleted or something in the future. Please copy your definitions of accept/reject into your question description. – mbomb007 – 2017-06-02T02:43:34.737

Answers

4

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.)

L3viathan

Posted 2017-06-01T20:44:53.100

Reputation: 3 151

I'm assuming OP will edit in a restriction of "no empty programs" - it is [tag:quine] after all – Stephen – 2017-06-01T21:13:25.057

@totallyhuman It's not clear to me whether that refers to the gang size or the program size. – L3viathan – 2017-06-01T21:13:59.733

I added another language, so the minimum size requirement is met (assuming it refers to gang size). – L3viathan – 2017-06-01T21:20:07.483

@L3viathan "Your job is to create a gang of programs. It must be of size at least 2" – Stephen – 2017-06-01T21:20:24.710

@StephenS The gang is of size 2 now. – L3viathan – 2017-06-01T21:20:55.013

1Clever abuse of the rules... – Neil A. – 2017-06-01T21:37:50.697

1

@StephenS I think its already implied due to https://codegolf.meta.stackexchange.com/a/5337/16842.

– PyRulez – 2017-06-01T22:18:12.470

@StephenS "if you can answer a question with an empty program and that question is scored by length ... and is tagged as quine ... just notify the OP." – PyRulez – 2017-06-01T22:20:18.260

1The empty Charcoal program outputs Parsing failed whether or not the input is empty—it does not get as far as reading the input. – Anders Kaseorg – 2017-06-01T22:20:53.343

@AndersKaseorg on TIO it didn't seem that way – L3viathan – 2017-06-02T05:53:03.870

@L3viathan When I go to https://tio.run/#charcoal with empty code and empty input and click Execute, I get Parsing failed. (You do have to remember to click Execute.)

– Anders Kaseorg – 2017-06-02T06:00:04.463

@AndersKaseorg Could have sworn it worked yesterday. I replaced Charcoal with 2sable. – L3viathan – 2017-06-02T06:27:02.470

2

∞ 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="--

BlackCap

Posted 2017-06-01T20:44:53.100

Reputation: 3 576

+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.) – PyRulez – 2017-06-01T22:31:20.047

Also, you can decrease your score substantially if you remove some of the longer gang members. – PyRulez – 2017-06-01T22:47:10.743

2

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

x=["69fa7652b24a3aa2a56122db2f3ce27395a3be0a6e6eed00b01592b9","604e0bb526a9af96f90a964c3849be96862bb3d31b9fcfbc83d6c7aa"]
c=[]
process.stdin.on('data',d=>c.push(d)).on('end',_=>console.log((d=Buffer.concat(c)).slice(0,121)=='x='+JSON.stringify(x)&&x.some(y=>y==require('crypto').createHash('sha224').update(d.slice(121)).digest('hex'))));

Python 2, 225 bytes

x=["69fa7652b24a3aa2a56122db2f3ce27395a3be0a6e6eed00b01592b9","604e0bb526a9af96f90a964c3849be96862bb3d31b9fcfbc83d6c7aa"]
import hashlib,sys,json
I=sys.stdin
print I.read(121)=='x='+json.dumps(x,separators=',:')and hashlib.sha224(I.read()).hexdigest()in x

Frxstrem

Posted 2017-06-01T20:44:53.100

Reputation: 676

What about hash collisions? – PyRulez – 2017-06-02T19:26:04.217

1

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

PyRulez

Posted 2017-06-01T20:44:53.100

Reputation: 6 547

The real question is which infinitely large gang would win in a gang fight, mine or the @BlackCap gang. – PyRulez – 2017-06-01T23:47:08.253