I decide to change the statement a little, so people who don't know the language can easily understand the challenge. (apparently there are many)
Background:
- I'm thinking about scraping some BF programs on this site for the fastest-code (or approximation) version of the other challenge, and I figure out that I need to have this, and I post it here as a code-golf challenge since it's somewhat interesting (and also pretty easy).
- It's possible to force programs to check if there are any extra characters too; however it might make the problem harder (only allow printable ASCII? Some scraped data might have non-ASCII characters, so it isn't really practical. Any Unicode characters as input? Most esoteric languages can't handle that.)
Does this BF program have a simple memory layout?
Given a string consisting of only the characters +-[]<>., check if:
- All pairs of
[]are matching (balanced), and - There's an equal number of
<and>between every matching pair of[].
Background: the inputs that this program output true are exactly the valid inputs for the related challenge BF memory layout optimizer.
Reference implementation in Python 3.
Example input/output
Output true:
,>>, ,<++[->>+<<] +<><>+ ,[.,] >.< Output false:
,[>,] +[>>>->-[>->----<<<]>>]>.---.>+..+++.>>.<.>>---.<<<.+++.------.<-.>>+. ].[ Undefined behavior: (your program can do anything when given those as input)
((((()()()()()){}){}){}()) $\="=".hex.$/ \!$/'?))='%<\..>