The Third String
Haskell, 43 bytes
x!y=[s|s<-(<$max x y)<$>"abc",s/=x,s/=y]!!0
Takes the max (lexicographically later) string, which we know is nonempty; replaces all characters with one of "a", "b", and "c" using
<$; and returns the first that is neither of the inputs. I think this is similar to Neil's Charcoal answer and/or geokavel's CJam answer.
(I've lurked for a while but this is my first time answering on this site; hi!)
Brainfuck, 97 bytes
Run code online (note that "dynamic memory" must be selected in the bottom-right)
Awesome challenge! I thought it would be trivial but it ended up being really difficult. I keep coming back to it because I feel like there should be some elegant 20-or-so-byte BF solution. At this point, I'm pretty happy I (seemingly) got it to work at all in BF.
Input is taken as
str2, where strings are consecutive non-zero 1-byte characters.
(first str1 + first str2) or (first str1 + 1) or 2. This algorithm was thought up by the brilliant @ØrjanJohansen, (presumably) based on my (broken) original one.
# Let (Kn) be the nth character of K # Let (^) designate the pointer # Let F be the first string inputted # Let S be the second string inputted +>+[- # Twice do ,[>>,] # Input string (characters separated by 1) <<[<<]> # Go to left of beginning of string ]> # End on first character of second string # If second string is null we will end one too far to the left >[>]<<<[<]> # If first string is null we will end there too # We will use this to do flow control [ # Only run if both strings were non null # Tape: S0 ' F0 ' S1 ' F1 ' S2 ' F2 ' etc # ^ <+>> # Let F0* = F0 (plus) 1 (is 1 as of now; F0 will be added later) [-<+<+>>] # Let A = S0 (plus) F0 # A may or may not be zero # F0* may or may not be zero # Tape: F0* ' A ' 0 ' S1 ' F1 ' etc # ^ [>]<[->+<] # Let B = A or F0* # B may or may not be zero <[-]>> # Clear F0* # Tape: 0 ' B ' 0 ' S1 ' F1 ' etc (if A was zero) # ^ # OR 0 ' 0 ' B ' s1 ' F1 ' etc (if A was nonzero) # ^ # Let C = B or 2 # C will be guaranteed nonzero and unique from S0 and F0 >++<[<]> # Create C [.>>] # Print (using S or F; does not matter) >[>>] # End on a zero cells with zero cells all to the right # This is necessary for the coming functionality # also as to not loop ] # End non null block # Now we consider if one of the strings was null # Tape: 0 ' E0 ' 0 ' E1 ' etc (if one string was null) # ^ # Tape: 0 ' 0 ' 0 ' 0 ' etc (if neither string was null) # ^ # Where E is F or S (we don't care) >[ # Execute only if one string was null + # Let A = E0 (plus) 1 # A may or many not be zero # Tape: 0 ' A ' 0 ' E1 ' etc # ^ [>]+[<]> # Let B = A or 1 # B is guaranteed nonzero and != E0 # Tape: 0 ' B ' ? ' E1 ' 0 ' E2 ' etc # ^ [.>>] # Print # End on zero cell as not to loop ] # End null block
Jelly, 8 bytes
Try it online!
żḟ@€ØAZḢ - Link: list of characters, a; list of characters, b ż - zip a and b ØA - uppercase alphabet ḟ@€ - filter discard for €ach (swap @rguments) Z - transpose the result Ḣ - head