| Bytes | Lang | Time | Link |
|---|---|---|---|
| nan | Python 2 | 221226T220227Z | Fmbalbue |
| 004 | Japt | 250117T162159Z | Shaggy |
| 020 | Python | 230303T203844Z | The Thon |
| nan | C gcc and Python 3 | 230119T162153Z | Peter |
| nan | 230110T193041Z | The Thon | |
| 001 | Jelly | 221228T011308Z | Lecdi |
| 002 | Brachylog | 230107T084955Z | Unrelate |
| 3939 | Thue | 221231T025123Z | Fmbalbue |
| 006 | x86_32 machine code | 221230T203257Z | engineer |
| 008 | TIBasic | 221230T195253Z | Youserna |
| 021 | Haskell | 221230T171334Z | matteo_c |
| nan | R | 221230T163917Z | Dominic |
| 005 | Pip | 221227T074446Z | The Thon |
| 006 | Pyt | 221229T002500Z | Kip the |
| 010 | GNU sed | 221229T011651Z | Silvio M |
| 241 | PUBERTY | 221228T234932Z | engineer |
| 008 | gbz80 machine code functions | 221228T184714Z | SNBeast |
| 003 | Motorola MC14500B Machine Code | 221228T172703Z | engineer |
| 010 | ><> | 221228T153453Z | mousetai |
| 004 | 05AB1E | 221227T072418Z | The Thon |
| 6612 | Zsh | 221228T132558Z | pxeger |
| 024 | R | 221227T204754Z | pajonk |
| 040 | Python 3 | 221227T220415Z | Joao-3 |
| nan | Java 19 using exit codes | 221227T182120Z | Jeremy |
| 035 | sed | 221227T235148Z | engineer |
| 088 | SussyLang | 221227T223254Z | engineer |
| 006 | APL Dyalog Unicode | 221226T215337Z | Adá |
| 036 | Python 3 | 221227T204231Z | l4m2 |
| 007 | brainfuck | 221227T210558Z | engineer |
| 008 | Jelly | 221227T185242Z | The Thon |
| 2714 | JavaScript ES6 | 221226T224818Z | Arnauld |
| 004 | Vyxal | 221227T073632Z | The Thon |
| 002 | Retina 0.8.2 | 221226T233419Z | Neil |
| 034 | Desmos | 221226T233342Z | Aiden Ch |
| 006 | Charcoal | 221226T233128Z | Neil |
| 004 | MATL both programs | 221226T223159Z | Luis Men |
| 8917 | POSIX Shell + Utilities | 221226T223557Z | набиячлэ |
| 006 | Brainbool | 221226T220434Z | Jiří |
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()
Program B
1
print-input()
-2 bytes thanks to Jiři
-9 thanks to tsh by changing the version.
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');}
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')
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
- A inputted into A:
0(falsy) - B inputted into A:
1(truthy) - A inputted into B:
Ṇ(truthy as it is a non-empty string) - B inputted into B:
(falsy as it is an empty string)
Explanation
- The string
Ṇ(program A) is truthy as it is a non-empty string - The string
(program B) is falsy as it is an empty string - In Jelly, an empty program just outputs exactly what was input. So program B produces a truthy output when program A is inputted, and a falsy output when it is given itself as input
- In Jelly,
Ṇis the logical NOT operator. It outputs a falsy output (0) when a truthy input is given, but a truthy output (1) when a falsy input is given. Therefore, it produces a falsy output when given itself as input, and a truthy output when program B is inputted
Brachylog, 2 bytes
0
1
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
A::=B
B::=~1
C::=:::
a::=D
D::=~0
::=
C
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.
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
- -1 thanks to DLosc
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.
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;
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
- -2 thanks to Kevin Cruijssen
Program A, 3 2 bytes
0å
Program B, 3 2 bytes
1å
Test cases
Explanation
0å checks whether 0 is in the input, and 1å checks whether 1 is in the input.
R, 26 24 bytes
Program A, 12 bytes
\(x)x<"\\(y"
Program B, 12 bytes
\(z)z>"\\(y"
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())
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.
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<{}
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
- Try it online! Program A with Program A as input.
- Try it online! Program A with Program B as input.
- Try it online! Program B with Program A as input.
- Try it online! Program B with Program B as input.
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.
Charcoal, 6 bytes
Program A:
№SA
Program B:
№SB
- Try it online! Program A with Program A as input.
- Try it online! Program A with Program B as input.
- Try it online! Program B with Program A as input.
- Try it online! Program B with Program B as input.
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