VBA, 512 489 479 bytes
Sub f(A,B):Debug.?">>>>>->>>>->--<<<"&Replace(Replace(Replace(A,"<","<<<[+]-<<"),">",">>>>>>>[+]-<<"),".",">>-<<[-<+>>>>+[-<<<<<+]+[-->>>>>++]--<<+>>+[-<<<<<+]-<++[-->>>>>++]--<<]<[->+<]>>>>+[-<<<<<+]+[-->>>>>++]>>>>>-[-<<<<<+]-<++[-->>>>>++]-<<")&">>[>>>>>]<<<<<[+<<[-]<<<]>++[-->>>>>++]+[-<<<<<+]->>"&Replace(Replace(Replace(B,"<","<<<<<"),">",">>>>>"),",","[-]>>->[>>>>>]+[-<<<<<+]->>>[-<<<[<<<<<]>>>>+[->>>>>+]-<<+>>>[>>>>>]+[-<<<<<+]->>>]>>-[<<<<<]>>>>+[->>>>>+]<<"):End Sub
Explanation
The VBA code changes the brainfuck code in a way, that the output of snippet A will be stored in a list and the input of snippet B will be read from that list.
It first initializes some variables
>>>>>->>>>->--<<<
Then it reads snippet A and replaces every <
by <<<[+]-<<
, every >
by >>>>>>>[+]-<<
and every .
by the storing routine
>>>>>>>[+]-<<"),".",">>->+[-<<<<<+]+[-->>>>>++]>>>>>-[-<<<<<+]-<++[-->>>>>++]--<<[-<+>>>>+[-<<<<<+]+[-->>>>>++]--<<+>>+[-<<<<<+]-<++[-->>>>>++]--<<]<[->+<]>>>+<<
after that it deletes the memory of snippet A and makes changes to the stored list, so it can be read as input for snippet B:
>>[>>>>>]<<<<<[+<<[-]<<<]>++[-->>>>>++]+[-<<<<<+]->>>>>-<<<
Then snippet B will be read, every <
will be replaced by <<<<<
, every >
will be replaced by >>>>>
and every ,
will be replaced by the list reading routine:
[-]>>->[>>>>>]+[-<<<<<+]->>>[-<<<[<<<<<]>>>>+[->>>>>+]-<<+>>>[>>>>>]+[-<<<<<+]->>>]>>-[<<<<<]>>>>+[->>>>>+]<<
Brainfuck source code
This is my source for the brainfuck portions of the code. I will explain that in detail later.
[
Tape: tempMem data out/in dataAnchors outAnchors (all repeating)
dataAnchors of Snippet A: -1 = memory has been used, -2 = active memory cell for copying to out/in
dataAnchors of Snippet B: -1 = active memory cell for copying from out/in
outAnchors of Snippet A: -1 = start of list, -2 = next output position
outAnchors of Snippet B: -1 = character has been read (or start of input)
]
### Init
>> two blank data cells (for non wrapping pointer)
>>>- set start of input
>> >>- set first "used" flag
>-- set end of input
<<< return to first usable data cell
### A move right routine
>>>>> move to the next data cell
>>[+]- clear and set "used" flag
<< return to data cell
### A move left routine
<<<[+]- clear and set "used" flag of previous data cell
<< go to data cell
### A print routine
>>- set flag
<<[ while value greater 0
- decrement value
<+ increment tempMem
>>>>+[-<<<<<+] find start of input
+[-->>>>>++]-- find end of input
<<+ increment input
>>+[-<<<<<+]- find start of input
<++[-->>>>>++]--find flag
<< go to active data cell
]
<[->+<] move stored value back to data
>>>>+[-<<<<<+] find start of input
+[-->>>>>++] find end of input
>>>>>- set new end of input
[-<<<<<+]- return to start of input
<++[-->>>>>++]- return to and delete data flag
<< go to data cell
### After snippet A: Delete memory of A and configure out/in list
>>[>>>>>]<<<<< go to last used data
[+<<[-]<<<] delete each data
>++[-->>>>>++] find and delete end of input flag
+[-<<<<<+]- go to start of input
>> go to first data cell
### B move right routine
>>>>> go to next data cell
### B move left routine
<<<<< go to previous data cell
### B reading routine
[-] set cell = 0
>>- set flag
>[>>>>>]+[-<<<<<+]- find start of input
>>>[ if value greater 0
- decrement value
<<<[<<<<<]>>>> go to initial start of input (combined with next)
+[->>>>>+]- find mem cell flag
<<+ increment mem cell
>>>[>>>>>]+[-<<<<<+]->>> return to input cell
]
>>- set new start of input
[<<<<<]>>>> go to initial start of input (combined with next)
+[->>>>>+] find and delete mem cell flag
<< go to mem cell
Output for test case 1: f ",[..,]",",[...,]"
>>>>>->>>>->--<<<,[>>->+[-<<<<<+]+[-->>>>>++]>>>>>-[-<<<<<+]-<++[-->>>>>++]--<<[-<+>>>>+[-<<<<<+]+[-->>>>>++]--<<+>>+[-<<<<<+]-<++[-->>>>>++]--<<]<[->+<]>>>+<<>>->+[-<<<<<+]+[-->>>>>++]>>>>>-[-<<<<<+]-<++[-->>>>>++]--<<[-<+>>>>+[-<<<<<+]+[-->>>>>++]--<<+>>+[-<<<<<+]-<++[-->>>>>++]--<<]<[->+<]>>>+<<,]>>[>>>>>]<<<<<[+<<[-]<<<]>++[-->>>>>++]+[-<<<<<+]->>>>>-<<<[-]>>->[>>>>>]+[-<<<<<+]->>>[-<<<[<<<<<]>>>>+[->>>>>+]-<<+>>>[>>>>>]+[-<<<<<+]->>>]>>-[<<<<<]>>>>+[->>>>>+]<<[...[-]>>->[>>>>>]+[-<<<<<+]->>>[-<<<[<<<<<]>>>>+[->>>>>+]-<<+>>>[>>>>>]+[-<<<<<+]->>>]>>-[<<<<<]>>>>+[->>>>>+]<<]
Try it online!
Output for test case 2: f ">,[>,]<[.<]",",[...,]"
>>>>>->>>>->--<<<>>>>>>>[+]-<<,[>>>>>>>[+]-<<,]<<<[+]-<<[>>->+[-<<<<<+]+[-->>>>>++]>>>>>-[-<<<<<+]-<++[-->>>>>++]--<<[-<+>>>>+[-<<<<<+]+[-->>>>>++]--<<+>>+[-<<<<<+]-<++[-->>>>>++]--<<]<[->+<]>>>+<<<<<[+]-<<]>>[>>>>>]<<<<<[+<<[-]<<<]>++[-->>>>>++]+[-<<<<<+]->>>>>-<<<[-]>>->[>>>>>]+[-<<<<<+]->>>[-<<<[<<<<<]>>>>+[->>>>>+]-<<+>>>[>>>>>]+[-<<<<<+]->>>]>>-[<<<<<]>>>>+[->>>>>+]<<[...[-]>>->[>>>>>]+[-<<<<<+]->>>[-<<<[<<<<<]>>>>+[->>>>>+]-<<+>>>[>>>>>]+[-<<<<<+]->>>]>>-[<<<<<]>>>>+[->>>>>+]<<]
Try it online!
Output for test case 3: f ",.",",."
>>>>>->>>>->--<<<,>>->+[-<<<<<+]+[-->>>>>++]>>>>>-[-<<<<<+]-<++[-->>>>>++]--<<[-<+>>>>+[-<<<<<+]+[-->>>>>++]--<<+>>+[-<<<<<+]-<++[-->>>>>++]--<<]<[->+<]>>>+<<>>[>>>>>]<<<<<[+<<[-]<<<]>++[-->>>>>++]+[-<<<<<+]->>>>>-<<<[-]>>->[>>>>>]+[-<<<<<+]->>>[-<<<[<<<<<]>>>>+[->>>>>+]-<<+>>>[>>>>>]+[-<<<<<+]->>>]>>-[<<<<<]>>>>+[->>>>>+]<<.
Try it online!
Complex test case:
Snippet A: Build alphabet triangle >+++++[<+++++>-]<+[>>[>[.>]]>++++++++++.--[<++++++++>-]<[+.<]<-]>>,>[.>]++++++++++.[<[.<]>,>[.>]<]
Try it online!
Snippet B: Sort input in ascending order >>,[>>,]<<[[-<+<]>[>[>>]<[.[-]<[[>>+<<-]<]>>]>]<<]
Try it online!
Result:
>>>>>->>>>->--<<<>>>>>>>[+]-<<+++++[<<<[+]-<<+++++>>>>>>>[+]-<<-]<<<[+]-<<+[>>>>>>>[+]-<<>>>>>>>[+]-<<[>>>>>>>[+]-<<[>>-<<[-<+>>>>+[-<<<<<+]+[-->>>>>++]--<<+>>+[-<<<<<+]-<++[-->>>>>++]--<<]<[->+<]>>>>+[-<<<<<+]+[-->>>>>++]>>>>>-[-<<<<<+]-<++[-->>>>>++]-<<>>>>>>>[+]-<<]]>>>>>>>[+]-<<++++++++++>>-<<[-<+>>>>+[-<<<<<+]+[-->>>>>++]--<<+>>+[-<<<<<+]-<++[-->>>>>++]--<<]<[->+<]>>>>+[-<<<<<+]+[-->>>>>++]>>>>>-[-<<<<<+]-<++[-->>>>>++]-<<--[<<<[+]-<<++++++++>>>>>>>[+]-<<-]<<<[+]-<<[+>>-<<[-<+>>>>+[-<<<<<+]+[-->>>>>++]--<<+>>+[-<<<<<+]-<++[-->>>>>++]--<<]<[->+<]>>>>+[-<<<<<+]+[-->>>>>++]>>>>>-[-<<<<<+]-<++[-->>>>>++]-<<<<<[+]-<<]<<<[+]-<<-]>>>>>>>[+]-<<>>>>>>>[+]-<<,>>>>>>>[+]-<<[>>-<<[-<+>>>>+[-<<<<<+]+[-->>>>>++]--<<+>>+[-<<<<<+]-<++[-->>>>>++]--<<]<[->+<]>>>>+[-<<<<<+]+[-->>>>>++]>>>>>-[-<<<<<+]-<++[-->>>>>++]-<<>>>>>>>[+]-<<]++++++++++>>-<<[-<+>>>>+[-<<<<<+]+[-->>>>>++]--<<+>>+[-<<<<<+]-<++[-->>>>>++]--<<]<[->+<]>>>>+[-<<<<<+]+[-->>>>>++]>>>>>-[-<<<<<+]-<++[-->>>>>++]-<<[<<<[+]-<<[>>-<<[-<+>>>>+[-<<<<<+]+[-->>>>>++]--<<+>>+[-<<<<<+]-<++[-->>>>>++]--<<]<[->+<]>>>>+[-<<<<<+]+[-->>>>>++]>>>>>-[-<<<<<+]-<++[-->>>>>++]-<<<<<[+]-<<]>>>>>>>[+]-<<,>>>>>>>[+]-<<[>>-<<[-<+>>>>+[-<<<<<+]+[-->>>>>++]--<<+>>+[-<<<<<+]-<++[-->>>>>++]--<<]<[->+<]>>>>+[-<<<<<+]+[-->>>>>++]>>>>>-[-<<<<<+]-<++[-->>>>>++]-<<>>>>>>>[+]-<<]<<<[+]-<<]>>[>>>>>]<<<<<[+<<[-]<<<]>++[-->>>>>++]+[-<<<<<+]->>>>>>>>>>>>[-]>>->[>>>>>]+[-<<<<<+]->>>[-<<<[<<<<<]>>>>+[->>>>>+]-<<+>>>[>>>>>]+[-<<<<<+]->>>]>>-[<<<<<]>>>>+[->>>>>+]<<[>>>>>>>>>>[-]>>->[>>>>>]+[-<<<<<+]->>>[-<<<[<<<<<]>>>>+[->>>>>+]-<<+>>>[>>>>>]+[-<<<<<+]->>>]>>-[<<<<<]>>>>+[->>>>>+]<<]<<<<<<<<<<[[-<<<<<+<<<<<]>>>>>[>>>>>[>>>>>>>>>>]<<<<<[.[-]<<<<<[[>>>>>>>>>>+<<<<<<<<<<-]<<<<<]>>>>>>>>>>]>>>>>]<<<<<<<<<<]
Try it online!
7
Shortest code in each language win
andShortest Brainfuck solution will be accepted
are two different winning criteria. – Mego – 2018-07-17T03:58:52.4072@Mego I meant if you answer in brainfuck and you win, you're accepted – l4m2 – 2018-07-17T06:22:55.537
Can you explain what "Winner in Brainfuck will be accepted." is supposed to mean?
@Dorian Your submission is written in BF and you win. (option 3) – user202729 – 2018-07-18T06:13:32.960
Some of the tests doesn't make sense. How can #3
,.
with,.
become eqvivalent with,>,[,]<.
. The composition will only read once, but your result reads more. – Sylwester – 2018-07-19T20:34:18.177@dzaima What I mean is if you compose
,.
and,.
you get,.
not,>,[,]<.
since that reads more than once and ends up printing the second input. It isn't a second input since,.
does only read ONCE. You even see that in the #4 example which is the exact same two programs with correct outcome – Sylwester – 2018-07-21T21:33:16.253@dzaima
,>,[,]<.
with one byte input prints whatever EOF is. That is different than the composition of,.
and,.
which only prints the first initial input once and perhaps ignore all other input if any. – Sylwester – 2018-07-21T21:38:28.6901Also. can you elaborate on
4.Consistently allow or disallow cells to left
. The leading answer requires cells on left in the answer to work but disallow A, B, and C to not move passed the first byte. My answer diallows move to left in answer, A, B, and C. If the rules for my program and C can be different from A, and B then i surely can shorten my answer a lot. – Sylwester – 2018-07-21T21:42:57.377@Sylwester no it doesn't? The middle
– dzaima – 2018-07-21T21:42:59.470>,[,]<
is guaranteed to always finish as input is finite (assuming an interpreter where EOF == 0) and it doesn't move the pointer and doesn't output so it's a noop@dzaima Ah. I see it now. Thanks for your patience. Could you please answer about the 4th rule? – Sylwester – 2018-07-21T21:45:36.457
1The entire problem statement is about A, B, and C, and only the last two sentences make any reference to the language of the answer. Perhaps the author did intend for the answer to be in the same flavor as A, B, and C, but that would not be my fault. Solvers should not be punished for problem authors' lack of foresight. At any rate it is really trivial to add a few
>
s to the beginning of my answer to make it comply with a more restrictive flavor (but for golf, we should also consider alternatives). Also, it seems clear to me that A, B, and C must be in the same flavor as each other. – Mitch Schwartz – 2018-07-21T22:13:13.410Also @dzaima "invalid" in your comment seems slightly misleading to me -- we are not talking about validity in the usual sense (whereby invalid answers should be fixed or deleted), but merely of eligibility for acceptance (and I'm not a fan of accepting answers on this site, but if such a criterion for acceptance had been clearly specified then I would have answered accordingly, because why not). If my point on validity seems unclear, consider a correct answer in e.g. self-modifying brainfuck, which would be clearly valid but not eligible.
– Mitch Schwartz – 2018-07-21T22:43:21.430@dzaima If you really do mean "invalid" in the usual sense, that would be equivalent to the author specifying "You may answer in any language this site allows, except for flavors of brainfuck that differ from the flavor you chose for A, B, and C.", which seems rather elaborate to me... (And I feel slightly dirty even addressing this whole issue, since it is so trivial and has nothing to do with golf or problem solving.) – Mitch Schwartz – 2018-07-21T23:10:56.443
1Maybe I'm completely misunderstanding the challenge, but test cases #3 and #4 seem to clash. – James – 2018-07-27T16:53:07.707