g | x | w | all
Bytes Lang Time Link
nanPython 2221226T220227ZFmbalbue
004Japt250117T162159ZShaggy
020Python230303T203844ZThe Thon
nanC gcc and Python 3230119T162153ZPeter
nan230110T193041ZThe Thon
001Jelly221228T011308ZLecdi
002Brachylog230107T084955ZUnrelate
3939Thue221231T025123ZFmbalbue
006x86_32 machine code221230T203257Zengineer
008TIBasic221230T195253ZYouserna
021Haskell221230T171334Zmatteo_c
nanR221230T163917ZDominic
005Pip221227T074446ZThe Thon
006Pyt221229T002500ZKip the
010GNU sed221229T011651ZSilvio M
241PUBERTY221228T234932Zengineer
008gbz80 machine code functions221228T184714ZSNBeast
003Motorola MC14500B Machine Code221228T172703Zengineer
010><>221228T153453Zmousetai
00405AB1E221227T072418ZThe Thon
6612Zsh221228T132558Zpxeger
024R221227T204754Zpajonk
040Python 3221227T220415ZJoao-3
nanJava 19 using exit codes221227T182120ZJeremy
035sed221227T235148Zengineer
088SussyLang221227T223254Zengineer
006APL Dyalog Unicode221226T215337ZAdá
036Python 3221227T204231Zl4m2
007brainfuck221227T210558Zengineer
008Jelly221227T185242ZThe Thon
2714JavaScript ES6221226T224818ZArnauld
004Vyxal221227T073632ZThe Thon
002Retina 0.8.2221226T233419ZNeil
034Desmos221226T233342ZAiden Ch
006Charcoal221226T233128ZNeil
004MATL both programs221226T223159ZLuis Men
8917POSIX Shell + Utilities221226T223557Zнабиячлэ
006Brainbool221226T220434ZJiří

Python 2, 16 + 15 = 49 46 44 40 31 bytes

Well, this is probably the most optimal python code.

-1 for Truthy, 0 for Falsy

Program A

0
print~-input()

Input A

Input B

Program B

1
print-input()

Input A

Input B

-2 bytes thanks to Jiři

-9 thanks to tsh by changing the version.

Japt, 4 bytes

Programme A

øa

Try it (with both inputs)

Programme B

øb

Try it (with both inputs)

Python, 20 bytes

Program A, 10 bytes

"$".__gt__

Program B, 10 bytes

'$'.__lt__

Attempt This Online! Link includes all four test cases.

Function which takes a string, returning True for friend and False for foe.

How?

Python string comparison works character by character.

When comparing $ to "$".__gt__, only $ and " are compared.
Similarly, when comparing $ to '$'.__lt__, only $ and ' are compared.

In ASCII values, " < $ < '.

C (gcc) and Python 3, 31 + 21 = 52 28 + 21 = 49 bytes

*-2 bytes by following @ceilingcat's suggestion, and -1 more by using <'p' rather than =='m' in C.

C:

main(){exit(getchar()<'p');}

Try It Online!

If there's a difference between the first character of input and 'm', the program returns 0; otherwise it returns 1.

Python 3:

print(input()[0]>'m')

Try It Online

If the ascii code for the first character of input is more than the one for 'm' (which p is but m isn't), the program prints True; otherwise it prints False.

Thunno, \$1\log_{256}(96)\approx\$ 0.82 bytes

Port of Lecdi's Jelly answer. Falsy = accepting; Truthy = rejecting.

Program A, \$1\log_{256}(96)\approx\$ 0.82 bytes

!

Program B, 0 bytes

Test cases

Explanation

! is the operator for logical not.

Jelly, 1 byte

Program A, 1 byte
Program B, 0 bytes
Outputs

Falsy = accepting; truthy = rejecting

Explanation

Brachylog, 2 bytes

0

Try it online!

1

Try it online!

With inspiration from Neil's Retina answer. Both full programs succeed on themselves and fail on each other. Each program unifies the input (and output) with the single numeric literal in the body, which matches the syntax for providing numbers as input.

Thue, 39 + 39 bytes

a::=b
b::=~1
c::=:::
A::=d
d::=~0
::=
c

True False

A::=B
B::=~1
C::=:::
a::=D
D::=~0
::=
C

True False

Has an additional newline (actually two) because of TIO implementation issue.

Truthy = 11 or 1\n1 depending on the implementation, in this case, 1\n1\n

Falsy = 0

x86_32 machine code, 6 bytes

Takes input in ESI (interpreted as a uint8_t *), and outputs to AL 0xAC for truthy and 0x46 for falsy.

Try it online!

Function A, 3 bytes

08049001 <a>:
 8049001:   ac                      lodsb
 8049002:   46                      inc esi
 8049003:   c3                      ret

Function B, 3 bytes

08049005 <b>:
 8049005:   46                      inc esi
 8049006:   ac                      lodsb
 8049007:   c3                      ret

Explanation

Function A copies the first byte of input to AL with lodsb. Function B copies the second byte of input to AL by first incrementing ESI before executing lodsb.

When Function A is run with itself or Function B is run with itself, the first/second byte (respectively) is copied to AL, which in both cases ends up being 0xAC.

When Function A is run with B or Function B is run with A, the opposite byte (0x46) is copied to AL.

TI-Basic, 8 bytes

Program A, 5 bytes

6-length(Ans

Program B, 3 bytes

length(Ans

Both programs take input from Ans as a string. Both output 2 for truthy and 4 for falsy.

Haskell, 21 bytes

function A, 11 bytes

even.length

function B, 10 bytes

odd.length

R, 11+12 = 23 bytes

prog a (11 bytes)

scan(,'')>F

prog a with itself as input = TRUE
prog a with prog b as input = FALSE

prog b (12 bytes)

!scan(,'')>F

prog a with prog a as input = FALSE
prog a with itself as input = TRUE

Pip, 6 5 bytes

Outputs 0 for truthy and 1 for falsy.

Program A, 2 bytes

+q

Program B, 3 bytes

1-q

Test cases

Explanation

+q forces the input into an integer. +q evaluates to 0, and 1-q evaluates to 1.

1-q subtracts the input from 1, once again forcing it into an integer. +q will therefore be 1, and 1-q will therefore be 0.

Pyt, 6 bytes

Program A

0
=

Try it online!

Program B

1
=

Try it online!

GNU sed, 10 bytes

Program A: 5 bytes

/a/q1

Program B: 5 bytes

/b/q1

Run with sed -nf <program_filename> <input_filename> Both programs output via their exit code, where 0 is accepting (or "friend") and 1 is rejecting (or "foe").

By default, sed outputs with exit code 0. However, the q command in GNU sed can terminate with a different exit code. Program A searches the input text for the letter a (which exists in Program A but not Program B). If it's present, then we terminate early with exit code 1. If not, we terminate at the end with the default exit code of 0. Program B does the exact same thing, except that it searches for letter b instead of a.

PUBERTY, 241 bytes

Outputs 0 for truthy and I for falsy.

Program A, 118 bytes

0
It is May 1, 1000, :: PM.q is in his bed, bored.His secret kink is t.Soon the following sounds become audible.oh yes

Program B, 123 bytes

I
0
It is May 1, 1000, :: PM.q is in his bed, bored.His secret kink is t.Soon the following sounds become audible.oh oh yes

Explanation

Both start with no-ops for simple processing. This answer works in the same way as my brainfuck answer. Program A prints out the first char of input (not including newlines, which are required for the input to be registered) and Program B prints out the second.

gbz80 machine code functions, 8 bytes

(Registers and flags will be referred to in lowercase letters, and the functions in uppercase letters.)

These functions require that the function to test is pointed to by hl. Their truthiness is output in the z flag: true is a match, false is a non-match.

Function A, 4 bytes:

3e 3e be c9

Disassembly:

ld a, $3e ; 3e is the opcode of "ld a, d8"
cp [hl]
ret

Function B, 4 bytes:

00 af be c9

Disassembly:

nop
xor a ; set a to 0
cp [hl]
ret

We're just checking the first byte of the function using two different ways to set a to a constant.

Motorola MC14500B Machine Code, 3 bytes

Outputs 0 for truthy and 1 for falsy.

Program A, 1.5 bytes

118

Disassembled:

1    ; Read input from the I/O pin into RR.
1    ; Read input from the I/O pin into RR.
8    ; Output RR to the I/O pin.

Program B, 1.5 bytes

428

Disassembled:

4    ; Read input from the I/O pin and store (RR AND (NOT INPUT)) into RR.
2    ; Read input from the I/O pin and store (NOT INPUT) into RR.
8    ; Output RR to the i/O pin.

Explanation

Program A outputs the second bit of input, which is 0 for Program A and 1 for Program B.

Program B outputs the complement of the second bit of input, which is 1 for Program A and 0 for Program B.

><>, 10 bytes

0"i=n;

And

1io;

Try it

Explanation

First we push a 0 or a 1. This is useless, but identifies the programs.

Then we push the string "0=n;0" (because strings wrap around). This means the 0 or 1 character code will be the last character on the stack.

We get the first character of the output program, and print if they are equal we print 1, otherwise 0.

The second program is similar except we can just print the first character of the first program so we can skip the = to save 1 byte.

05AB1E, 6 4 bytes

Program A, 3 2 bytes

Program B, 3 2 bytes

Test cases

Explanation

checks whether 0 is in the input, and checks whether 1 is in the input.

Zsh, 6 + 6 = 12 bytes

grep A

Attempt This Online!

grep B

Attempt This Online!

Output is via exit code.

R, 26 24 bytes

Program A, 12 bytes

\(x)x<"\\(y"

Attempt This Online!

Program B, 12 bytes

\(z)z>"\\(y"

Attempt This Online!

Two anonymous functions differing by the name of the variable. We then check whether the function text (essentially the variable name) is smaller or bigger (lexicographically) than the beginning of the function (\ escaped and () with y appended.

Python 3, 44 40 bytes

A, 20 bytes

print('['in input())

B, 20 bytes too

print(']'in input())

A, when input A

A, when input B

B, when input A

B, when input B

What I really like about this one, is that you can change 1 character and get the other program.

Java 19 using exit codes, 146 (73 + 73)

interface A{static void main(String[]a){System.exit(a[1].charAt(0)%65);}}
interface B{static void main(String[]a){System.exit(a[1].charAt(0)%66);}}

Run it with variations of:

cat A.java | xargs java B
echo $?                  

Java 19 using standard out, 158 (79 + 79) bytes

interface A{static void main(String[]a){System.out.print(a[1].charAt(0)==65);}}
interface B{static void main(String[]a){System.out.print(a[1].charAt(0)==66);}}

Run it with variations of:

cat A.java | xargs java A

sed, 35 bytes

Program A, 17 bytes

s/s.*/1/;s/;.*/0/

Program B, 18 bytes

;s/s.*/0/;s/;.*/1/

Test cases

Explanation

Program B starts with ; to distinguish it from Program A.

Program A replaces lines starting with s with 1, and replaces lines starting with ; with 0.

Program B replaces lines starting with s with 0, and replaces lines starting with ; with 1.

SussyLang, 88 bytes

Outputs 0 for truthy and 3 for falsy.

Program A, 44 bytes

pensus
sus 112
sussyballs
imposter
sussybaka

Program B, 44 bytes

sus 115
pensus
sussyballs
imposter
sussybaka

Test cases

Explanation

Program A takes the first character and subtracts 112 ('p'); Program B takes 115 ('s') and subtracts the first character.

APL (Dyalog Unicode), 10 7 6 bytes

Anonymous tacit prefix functions, returning for true and for false.

A: ⊣/⊢

 is an identity function, and returns the given source as-is

⊣/ returns the leftmost character (lit. left-identity reduction), i.e. when given A's source and when given B's source.

B: ⊢/⊣

 is an identity function, and returns the given source as-is

⊢/ returns the rightmost character (lit. right-identity reduction), i.e. when given A's source and when given B's source.

Try it online!

Python 3, 36 bytes

print(''<input())

Try it online!


print(''==input())

Try it online!

brainfuck, 7 bytes

Outputs , for truthy and F for falsy.

Program A, 3 bytes

,F.

Program B, 4 bytes

F,,.

Test cases

Explanation

Program A retrieves and prints the first byte of input, and Program B retrieves and prints the second byte of input. An F char (no-op) is inserted into each program in the opposite position of which the program prints out (so that Program A's F is the second char and Program B's F is the first char).

Jelly, 8 bytes

Program A, 4 bytes

0ŒṘe

Program B, 4 bytes

1ŒṘe

Test cases

Explanation

0ŒṘe checks whether 0 is in the input, and 1ŒṘe checks whether 1 is in the input.

JavaScript (ES6), 2x7 = 14 bytes

Both functions return a Boolean value.

A: s=>s>{}

B: S=>S<{}

Try it online!

Vyxal, 4 bytes

Program A, 2 bytes

0c

Program B, 2 bytes

1c

Test cases

Explanation

0c checks whether 0 is in the input, and 1c checks whether 1 is in the input.

Retina 0.8.2, 2 bytes

Program A:

A

Program B:

B

Explanation: Each program counts the number of As or Bs in the input respectively, which will be truthy for itself and falsy for the other program.

Desmos, 34 bytes

Program A, 17 bytes


A(l)=\{l[2]=65\}

Program B, 17 bytes


B(l)=\{l[2]=66\}

Input is a list of character codepoints, and output is 1 for truthy (accepting) and undefined for falsey (rejecting).

This is just the first strategy I thought of; there might be better ways out there.

Try It On Desmos!

Try It On Desmos! - Prettified

Charcoal, 6 bytes

Program A:

№SA

Program B:

№SB

Explanation: Each program counts the number of As or Bs in the input respectively, which will be truthy for itself and falsy for the other program.

MATL (both programs), score 4

Program A: oo

Program B: I\

Each program with itself as input outputs a truthy result, specifically a numeric array containing positive integers. Each program with the other as input outputs a falsy result, specifically a numeric arrray containing at least a zero entry. See truthy/falsy criteria in MATL, or use this truthy/falsy test.

How it works

Program A:

o  % Implicit input. Convert codepoints to numbers. Gives numeric vector
o  % Modulo 2 of each entry. Implicit display

Program B:

I  % Push 3
\  % Implicit input. Modulo (3, of code points). Gives numeric vector. Implicit display

POSIX Shell + Utilities, 8+9=17 bytes

$ cat ff?; echo; wc -c ff?
cmp $0 -
cmp $0 -
 9 ff1
 8 ff2
17 total
$ ./ff1 < ff1; echo $?
0
$ ./ff1 < ff2; echo $?
1
$ ./ff2 < ff1; echo $?
1
$ ./ff2 < ff2; echo $?
0

Some cmp implementations would allow dropping the -, for a score of 6+7=13 bytes.

Brainbool, 6 bytes

A: 1,.
B: ,+.

A with A input
A with B input
B with B input
B with A input

A explanation:

1 this is comment used for "1" input
, reads character
. and print it back

B explanation:

, reads character; also it is used as "0" input
+ negates the value
. print the value