入力:
2つの文字列(注:入力の順序は重要です)。
出力:
両方の単語/文は、それらの間に空の行が1つある行から始まります。彼らは互いに横に「歩いている」。しかし、彼らは同じ位置に同じ性格を持つとき、彼らはお互いに交差し、次に互いに隣り合って歩いていく。
あなたは混乱していますか?例を挙げてみましょう:
入力: Words crossing over
& Ducks
:
quacking
Word quack n
s i g
Duck cross n over
挑戦のルール:
- We always first go back walking a straight line after we’ve
‘crossed over’ before we can cross over again (see test case above
{1} – whereing
is equal, but after we’ve crossed on
i
, we first have to go back walking straight (thus
ignoringn
), before we can cross again on
g
). - The inputs can be of different length, in which case the longer
one continues walking in a straight line (see test cases 1, 2, 4 &
6). - Both inputs can be the same (see test case 3).
- The inputs won’t contain any tabs nor new-lines.
-
Spaces are ignored as characters that are the same (as
an edge case), in which case the next (non-space)
character after that – if any – is crossing over instead (see test
cases 3, 5 & 6). - The inputs can have no adjacent (non-space) characters on the
same position at all, in which case both just walk in a straight
line horizontally (see test cases 2). - Even if the first character is equal, we always start two lines
apart (see test cases 3 & 6). - Trailing spaces and a single trailing new-line are
optional. - You can assume the inputs will only contain printable ASCII
characters (new-lines and tabs excluded). - The inputs are case-sensitive, so
A
and
a
aren’t equal, and won’t cross over (see test case
7). - Both the inputs lengths will always be at least 2.
- Input & output can be in any reasonable format. Can be a single
String with new-lines; a String-array/list; printed to STDOUT; 2D
array of characters; etc.
一般的なルール:
- This is code-golf,
so shortest answer in bytes wins.
Don’t let code-golf languages discourage you from posting answers
with non-codegolfing languages. Try to come up with an as short as
possible answer for ‘any’ programming language. -
Standard rules apply for your answer, so you are allowed to use
STDIN/STDOUT, functions/method with the proper parameters and
return-type, full programs. Your call. -
Default Loopholes are forbidden. - If possible, please add a link with a test for your code.
- Also, please add an explanation if necessary.
テストケース:
1. 入力: "Words crossing over" & "Ducks quacking"
1. 出力:
Word quack n
s i g
Duck cross n over
2. 入力: "bananas" & "ananas"
2. 出力:
bananas
ananas
3. 入力: "I see my twin!" & "I see my twin!"
3. 出力:
I e y w n
s e m t i !
I e y w n
4. 入力: "Is the weather nice?" & "Not really, no.."
4. 出力:
Is th ally, no..
e
Not r weather nice?
5. 入力: "Codegolf & Programming Puzzles" & "The golfer might solve puzzles"
5. 出力:
Code o f & Programming P z l s
g l u z e
The o fer might solve p z l s
6. 入力: "Can you turn the lights off?" & "Can you try to solve this?"
6. 出力:
C n o urn the ve s off?
a y u t l t
C n o ry to so igh his?
7. 入力: "one Ampere" & "two apples"
7. 出力:
one Am les
p
two ap ere
8. 入力: "Words crossing" & "Words Quacking"
8. 出力:
W r s cross n
o d i g
W r s Quack n
ベストアンサー
APL
(Dyalog), 64 bytes
{C←⎕UCS⋄1↓e⊖' '⍪1 0 1⍀⍵⊖⍨≠e←C(2/⊃l)⎕R(l←C⌽⍳2)C([email protected]=⌿⍵)∧' '≠1⌷⍵}
オンラインで試してみてください!