The reversible reverser
APL, 5
⌽⍞⍝⍞⊖
This reverses (⌽
, along the last axis) the input (⍞
), and is followed by a comment (⍝
marks a line comment). Reversed, the program reverses (⊖
, along the first axis) the input, and is followed by a comment. Because the input is always going to be one dimensional, in this case ⌽
and ⊖
are functionally equivalent. It is perhaps even sneakier than the GolfScript solution, so here's a cleaner solution (no comments), which scores 9.
⍬,⌽,⍞,⊖,⍬
This first grabs an empty vector (⍬
), flattens it (monadic ,
), and reverses it (⊖
, along the first axis). This still leaves an empty vector. Then it concatenates (dyadic ,
) to the input (⍞
), leaving the input untouched. It then flattens (monadic ,
) the already-flat input and reverses it (⌽
, along the last axis). Then it concatenates (dyadic ,
) another empty vector (⍬
) to the reversed input. This does nothing, and leaves the reversed input behind. Reversed, this program does the same thing, based again on the fact that ⌽
and ⊖
are functionally equivalent with one-dimesional arguments.
You really couldn't say I'm adding useless characters to break the palindrome (the two different reverse functions are different with two-or-more-dimensional input; I'm just taking advantage of the fact they act the same with one-dimensional input)
Unix shell - 8 + 25% = 10
rev||ver
Previous answer of cat|tac
didn't actually work, tac
reverses the order of lines, not the order of characters in a line.
Haskell, 53
main=niam
niam=interact reverse
esrever tcaretni=main
Technically not a palindrome, but, since function declaration order doesn't matter, once reversed you have exactly the same program.