Shift characters in a string
Pyth, 4 bytes
.>zQ
This is almost similar to my CJam 5 byte version, except that Pyth as a auto-eval input operator Q
.
.> # Cyclic right shift of
z # Input first line as string
Q # Rest of the input as evaluated integer
Try it online here
Javascript (ES5), 55 52 bytes
p=prompt;with(p())p(slice(b=-p()%length)+slice(0,b))
Commented:
p = prompt; // store a copy of prompt function for reuse
with(p()) // extend scope chain with first input
p( // print result
slice(b = -p() % length) // take second input negated and modulo length
+ // and slice string by result
slice(0, b) // concatenate with opposite slice
)
CJam, 5 bytes
llim>
This is pretty straight forward.
l e# Read the first line
li e# Read the second line and convert to integer
m> e# Shift rotate the first string by second integer places
Try it online here