Given a list or string (you can decide to handle only one of these), return it unmodified. However, if your source code is palindromised by appending its reverse to it, then the this new code must palindromise the given list or string. For the purposes of this competition, you must count a trailing line break if it is necessary to make your code run when palindromised. ## Examples Let's say your solution takes a list and your source code is ``` AB DEF ``` and its input/argument is `[1,2,3]`. If I write ``` AB DEFFED BA ``` instead and run it, the output/result must be `[1,2,3,3,2,1]`. Let's say your solution takes a string and your source code is ``` ABC ``` and its input/argument is `"42\n"`. If I write ``` ABC CBA ``` instead and run it, the output/result must be `"42\n\n24"`.
Top Answer W
# [W](https://github.com/A-ee/w/) `t`, 4 bytes ``` +_:a ``` # Explanation ``` + % Join 2 (implicit) inputs _ % Reverse the joined input : % Copy the input a % All of this is discarded after the input push ``` # Explanation-noitanalpxE ``` +_:a % Stack is as above a % Push the input : % Copy the input _ % Reverse the copy + % Join to the original string % I.e. palindromizing the input ```
Answer #2 APL (Dyalog Unicode)
# [APL (Dyalog Unicode)], 3 bytes^SBCS^ ⌽⊢, [Try it online!][TIO-k89pozol] [APL (Dyalog Unicode)]: https://www.dyalog.com/ [TIO-k89pozol]: https://tio.run/##SyzI0U2pTMzJT////1HP3kddi3T@pz1qm/Cot@9R31RP/0ddzYfWGz9qmwjkBQc5A8kQD8/g/2kK6olJyepcQNrA0MjYxNTM3MJSHQA "APL (Dyalog Unicode) – Try It Online" ## Palindromized ⌽⊢,,⊢⌽ [Try it online!!enilno ti yrT][TIO-k89ppz0r] [APL (Dyalog Unicode)]: https://www.dyalog.com/ [TIO-k89ppz0r]: https://tio.run/##SyzI0U2pTMzJT////1HP3kddi3R0gASQ@T/tUduER719j/qmevo/6mo@tN74UdtEIC84yBlIhnh4Bv9PU1BPTEpW5wLSBoZGxiamZuYWluoA "APL (Dyalog Unicode) – Try It Online" ### How it works ⌽⊢, ⍝ Original function; Input = s ⌽ , ⍝ Compute reverse(s) and flatten(s) (flatten is a no-op) ⊢ ⍝ Select the right one, i.e. flatten(s) ⌽⊢,,⊢⌽ ⍝ Palindromized function; Input = s ,⊢⌽ ⍝ Similar to the original, but select reverse(s) ⊢, ⍝ Append the above to s, giving s+reverse(s) ⌽ ⍝ Reverse the entire string, which is no-op on a palindrome
Answer #3 05AB1E
## [05AB1E], 3 bytes «ÂI [Try it online!][TIO-k78bvage] [05AB1E]: https://github.com/Adriandmen/05AB1E [TIO-k78bvage]: https://tio.run/##yy9OTMpM/f//0OrDTZ7//0cb6hjpGMcCAA "05AB1E – Try It Online" ## Explanation ``` « Concatenate the (implicit) inputs Â Bifuricate: Push a, reversed(a) I Push the input Implicitly output the top of the stack ``` ## Explanation-noitanalpxE ``` «ÂI Same as above I Push the input Â Bifuricate: Push a, reversed(a) « Concatenate them Implicitly output the top of the stack ```