# Is it a brainfuck instruction?

A very simple challenge today. Output a truthy value whether the ASCII character (or it's code) supplied is a brainfuck instruction (one of +-,.<>[]), and a falsy value if it's a comment (everything else).

## Input

+
#
<
>
.
P
,


## Output

true
false
true
true
true
false
true

• As in, can the answer be formatted as either a program or function? (such as requiring main(){} and all of that in C answers) Apr 11, 2020 at 17:57
• @RedwolfPrograms doesn't matterdoesn't matter Apr 11, 2020 at 18:02
• Is the input character guaranteed to be printable ASCII? (32-126) Apr 11, 2020 at 18:47
• No, but I'd like to see (a part of an already valid answer) that assumes it's printable as an "addon". As I've stated (or rather deleted the comment afterwards), as it's quite a boring challenge, I'm looking for some creativity Apr 11, 2020 at 18:50
• @LuisMendo No, according to the esolang wiki, it's often lowercase Apr 12, 2020 at 15:56

# Factor, 17 bytes

[ "+-,.<>[]"in? ]


Try it online!

# Ly, 14 bytes

"+-,.()[]"i~u>


Try it online!

"+-,.()[]"      - Push legit characters onto the stack
i     - Read codepoint from STDIN
~    - Pop stack, search stack for that codepoint, push 1|0 result
u   - Print top of stack as a number (will be 1 or 0)
>  - Switch stacks to avoid printing the current contents


# Scratch, 22 bytes

if <symbol v] contains (input) then
set [output v] to [true]
else
set [output v] to [false]


Try it online!

# jq, 18 bytes

inside("+-,.<>[]")


Try it online!

• Fix+4 thanks to @JoKing
• Bounty started. By the way, this is 100 because SE has silly rules saying that if you've posted an answer, the minimum bounty is +100. Sep 2, 2021 at 8:56
• The output is always true for every input. Sep 3, 2021 at 0:07
• You should be using inside
– Jo King
Sep 4, 2021 at 7:54
• I'll award the bounty once this answer becomes valid. Sep 8, 2021 at 19:49
• @emanresuA fixed thx to jo king, if you have already lost 100 rep for prev. Bounty you are free to not award the bounty again Sep 9, 2021 at 7:41

# Lua, 31 bytes

print((...):match'[[%]+-.,><]')


Try it online!

Prints either the inputted character (strings are always truthy) or nil (which is falsy).

# C (gcc) XPG4.2/Single UNIX Specification, Version 3, POSIX:2001, 30 bytes

f(c){c=!!index("+-,.<>[]",c);}


Try it online!

• nitpick: index() isn't included by the C standard, so shouldn't it be stated? Apr 11, 2020 at 18:17
• @FryAmTheEggman Ah, well deciphered! Ok, posted the version of POSIX it's good to go on. Thanks! :-) Apr 11, 2020 at 18:40
• This is totally not necessary. C (gcc) works just fine. Apr 23, 2020 at 20:44

# C (gcc), 31 bytes

f(c){c=!!strchr("+-,.<>[]",c);}


Try it online!

# Ruby-nl, 16 bytes

Input is STDIN. Prints 0 (Ruby truthy) or nil (falsy).

Annoyingly, it seems like Ruby demands that both [ and ] be escaped in the character class regex.

p~/[+-,.<>]/


Try it online!

• That's apparently because Ruby allows nested character classes.
– Neil
Apr 12, 2020 at 9:31

# JS, 26 bytes

c=>'+-,.<>[]'.indexOf(c)+1


# x86_16 machine code, 40 bytes

Outputs '0' (false) or '1' (true) on the screen.

bb1f 7cb1 5080 3f00 7409 380f 7409 83c3
01eb f2b0 30eb 02b0 31b4 0ecd 10eb fe2b
2d2c 2e3c 3e5b 5d00


To boot, pad it to 510 bytes with zeros and add 55aa at the end!
This means "uncomment the last two assembly lines and rebuild".

Ungolfed (compilable, compile using nasm -fbin -o is-bf is-bf.asm):

[org 0x7c00]

mov bx, string
mov cl, 'P' ; the character
loop_:
cmp byte [bx], 0
je false
cmp byte [bx], cl
je true
jmp loop_
false:
mov al, '0'
jmp print
true:
mov al, '1'
print:
mov ah, 0eh
int 10h
jmp $; hang forever string: db "+-,.<>[]", 0 ; times 510 - ($-) db 0
; dw 0xaa55

• you don't have to make the assembly snippet bootable, you can aswell write a callable function Apr 12, 2020 at 11:25
• I like bootable snippets more because I can boot them in QEMU and see the results :) Apr 12, 2020 at 11:26
• this makes your code bigger, though. Apr 12, 2020 at 11:26

# APL+WIN 12 bytes

3 bytes saved thanks to @Avi F. S.

Prompts for character and returns 1 if true 0 if false:

⎕∊'+-,.<>[]'


Try it online! Courtesy of Dyalog Classic

• Keeping in form with your answer, you can shave off the first ×, here. Though if you just flip them around, you can do ⎕∊'+-,.<>[]', here! Apr 11, 2020 at 20:02

# LaTeX, 52 bytes

\usepackage{xstring}\def\f#1{\IfSubStr{[]+-.,}#1x{}}


Defined a macro \f that takes one argument and expands to x if the input is a brainfuck instruction and to nothing if not. Assumes there is only one character in the argument.

## Explanation

\usepackage{xstring}  % load the xstring package for the IfSubStr macro
\def\f#1{             % define a macro \f that takes 1 argument
\IfSubStr{[]+-.,}#1 % test if the second argument is a substring of the first
x                 % if it is a substring expand to x
{}                % else expand to nothing
}


# CJam, 14 12 bytes

-2 bytes by treating as a self-contained program instead of a block.

"+-<>[].,"q#


Try it online!

Returns -1 if not a brainfuck character, anything else if so.

# Perl 5-p, 15 bytes

\$_=y/+,.<>[]-//


Try it online!

# Java (JDK), 20 bytes

"<[+.,-]>"::contains


Try it online!

# ARBLE, 21 bytes

find(c,"[[%]+-.,><]")


Returns 1` for truthy, or nothing for falsey.

Try it online!