APL (Dyalog), 34 Charachters
Still trying to golf it a bit more, new to APL. Tips appreciated.
Here is an attempt to explain it, I also simplified it a bit (no charachter improvement, though)
⋄ is a statement separator, think of it as a new line.
That leaves us with 2 statements.
APL works from right to left in statements, but follows parentesis still, so
(⍴x←⍞) is executed first.
⍞ takes charachter input.
← assigns that to
⍴ gives the length of
x. Then the
-2 is executed, which subtracts 2 from the length of
x. Finally, the length-2 is assigned to
y and we move on to the next statement.
x[⍴x] takes the last character of
x, think of it as
x[x.length] (using the length as the index of the last character).
, is catenate.
So we concatenate the last character of
x[1+⍳y][y?y] which takes the middle indices of
2+⍳y and applies a randomization using
1 2 3 ... y and
1+ turns this into
2 3 4 ... y+1 which are the middle indices of x, for example, this returns
[y?y] "deals" y values from 1 to y.
x[1+⍳y][y?y] grabs the middle of the word and randomizes it.
Finally, we concatenate the first charachter of
x, to the rest of the string, and that is the output of the program.
Hopefully that was understandable...
idis the identity function. I would still like to see Haskell solution to this problem in less than 100 characters. \$\endgroup\$