| Bytes | Lang | Time | Link |
|---|---|---|---|
| 086 | TSQL | 250514T165009Z | BradC |
| 018 | Juby | 240312T170426Z | Jordan |
| 168 | SAKO | 250326T165913Z | Acrimori |
| 049 | AWK | 250325T203302Z | xrs |
| 013 | APLNARS | 250323T213621Z | Rosario |
| 079 | Tcl | 181208T235046Z | sergiol |
| 040 | Bash | 240710T141759Z | Themooni |
| 020 | Raku | 181209T225602Z | Jo King |
| 034 | sed 4.2.2 r | 240715T173520Z | guest430 |
| 030 | min | 240713T213440Z | chunes |
| 320 | C++ | 240711T181539Z | jreneew2 |
| 035 | Zsh | 240711T173555Z | roblogic |
| 062 | Forth gforth | 240710T130721Z | reffu |
| 054 | Octave | 240710T081803Z | Glory2Uk |
| 051 | PowerShell | 240322T161345Z | James Fl |
| 057 | Swift 5.9 | 230715T000944Z | macOSist |
| 040 | TIBasic | 240312T232435Z | Youserna |
| 008 | Brachylog | 240312T194651Z | DLosc |
| 007 | Uiua SBCS | 240312T171946Z | chunes |
| 023 | ForWhile | 230712T193427Z | bsoelch |
| 179 | Racket | 230706T182446Z | Ed The & |
| 003 | Nekomata | 230706T015818Z | alephalp |
| 032 | JavaScript Node.js | 230703T071036Z | l4m2 |
| 077 | Rockstar | 230624T092907Z | Shaggy |
| 052 | Lua | 230630T025722Z | bluswimm |
| 041 | JavaScript Node.js | 230628T131008Z | Fhuvi |
| 030 | Arturo | 230624T024710Z | chunes |
| 003 | Thunno 2 | 230623T172350Z | The Thon |
| 031 | Julia 1.0 | 221031T174014Z | Ashlin H |
| 003 | Vyxal | 221101T005608Z | aketon |
| 026 | Ruby nl | 221031T175218Z | Jordan |
| 003 | Stax | 221029T001554Z | recursiv |
| nan | 221028T140559Z | bigyihsu | |
| 013 | APL Dyalog Unicode | 221025T225220Z | Seggan |
| nan | Fig | 221020T000311Z | naffetS |
| 003 | Vyxal | 221019T235717Z | naffetS |
| 025 | Factor | 221019T220341Z | chunes |
| 005 | MATL | 181209T214937Z | Suever |
| 052 | Pepe | 181210T114448Z | u-ndefin |
| 003 | Japt | 181208T223836Z | Shaggy |
| 018 | perl 5 | 190108T133916Z | Nahuel F |
| 038 | brainfuck | 190514T122924Z | Dorian |
| 011 | cQuents | 190513T152149Z | Stephen |
| 079 | C# .NET Core | 190114T194034Z | Destroig |
| 066 | MBASIC | 190111T151403Z | wooshiny |
| 063 | PHP | 190110T025800Z | 640KB |
| 038 | Reticular | 190108T235127Z | Wisław |
| 059 | Runic Enchantments | 190108T222254Z | Draco18s |
| 088 | Common Lisp | 190108T171753Z | Renzo |
| 036 | JavaScript | 181210T005829Z | guest271 |
| 050 | C 32bit | 181209T184757Z | user7740 |
| 039 | Ruby | 181211T045741Z | acornell |
| 026 | Wolfram Language Mathematica | 181209T000400Z | Misha La |
| 054 | C clang | 181210T034649Z | user3604 |
| 061 | Lua | 181212T031103Z | cyclamin |
| 036 | JavaScript | 181209T195415Z | Oliver |
| 033 | Ruby | 181211T210227Z | G B |
| 007 | Pyth | 181211T203428Z | Sok |
| 032 | JavaScript ES6 | 181208T232816Z | Arnauld |
| 005 | MathGolf | 181211T151634Z | maxb |
| 082 | SNOBOL4 CSNOBOL4 | 181210T220149Z | Giuseppe |
| 064 | Clojure | 181210T205125Z | Carcigen |
| 085 | Java JDK | 181210T161658Z | Olivier |
| 044 | Powershell | 181210T090828Z | mazzy |
| 008 | V | 181208T222102Z | DJMcMayh |
| 034 | C# Visual C# Interactive Compiler | 181209T232606Z | dana |
| 059 | brainfuck | 181209T232333Z | Jo King |
| 004 | Pushy | 181209T215749Z | FlipTack |
| 032 | Perl 6 | 181209T193519Z | Sean |
| 078 | Tcl | 181209T183859Z | david |
| 011 | Pyth | 181209T133601Z | ElPedro |
| 058 | R | 181209T174313Z | digEmAll |
| 048 | Python 2 | 181209T090331Z | ElPedro |
| 043 | Red | 181209T084221Z | Galen Iv |
| 007 | J | 181209T075234Z | Galen Iv |
| 013 | Attache | 181209T004002Z | Conor O& |
| 038 | Python 2 | 181209T000054Z | xnor |
| 010 | Charcoal | 181208T235438Z | Neil |
| 002 | Jelly | 181208T225329Z | Jonathan |
| 003 | 05AB1E | 181208T222827Z | Okx |
| 027 | Haskell | 181208T224108Z | nimi |
| 006 | APL Dyalog Unicode | 181208T222229Z | Adá |
T-SQL, 86 bytes
SELECT SUBSTRING(s+s,number+2,len(s))FROM t,spt_values WHERE TYPE='P'AND number<len(s)
Input is taken from pre-existing table t with string column s per our IO rules.
This must be run in the master database, which (on MS SQL servers) includes a system table named spt_values containing the digits 0 through 2047.
J-uby, 18 bytes
:*%[:& &:|,:+@|:+]
Explanation
:* % [:& & :|, :+@ | :+]
:+@ | :+ # Range 1..(input length)
:* % [ , ] # Map with...
:& & :| # Rotate input chars
SAKO, 168 bytes
PODPROGRAM:F(*W)
CALKOWITE:*W,I,J,K
STRUKTURA(9):W
I=0
1)I=I+1
GDYW(I)=58:2,INACZEJ1
**2)C=W(K)
W(K)=W(K-1)
W(K-1)=C
POWTORZ:K=1(1)I
DRUKUJWIERSZ:W
POWTORZ:J=1(1)I
WROC
Repeatedly moves character to the end. The string is expected to end in LF as is usually in SAKO.
Full programme version, 177 bytes
CALKOWITE:*W,I,J,K
BLOK(9):W
W(=I)=0
CZYTAJWIERSZ:W
I=0
1)I=I+1
GDYW(I)=58:2,INACZEJ1
**2)C=W(K)
W(K)=W(K-1)
W(K-1)=C
POWTORZ:K=1(1)I
DRUKUJWIERSZ:W
POWTORZ:J=1(1)I
STOP1
KONIEC
AWK, 49 bytes
{for(;i++<NF;)print$0=substr($0,2)substr($0,1,1)}
{for(;i++<NF;) # iterate based on num of chars
print$0 # print string
=substr($0,2) # sub string from 2 position till end
substr($0,1,1)} # sub string first char concatted.
APL(NARS), 13 chars
{{⍵⌽k}¨⍳≢k←⍵}
test:
{{⍵⌽k}¨⍳≢k←⍵}'john'
┌4──────────────────────────────┐
│┌4────┐ ┌4────┐ ┌4────┐ ┌4────┐│
││ ohnj│ │ hnjo│ │ njoh│ │ john││
│└─────┘ └─────┘ └─────┘ └─────┘2
└∊──────────────────────────────┘
Tcl, 79 bytes 80 | 91
proc P s {time {puts [set s [regsub ^. $s ""][string in $s 0]]} [string le $s]}
Bash, 44 40 bytes
-4 bytes by roblogic
for((;i++<${#1};)){ echo ${1:i}${1::i}
}
Use as body of a bash function or as a bash script. takes the string as first arg and outputs to stdout.
explanation:
for ((;i<${#1};i++)){ # ${#1} is the length of $1, so this is a for loop counting character positions
echo ${1:$i}${1::$i} # ${1:x:y} is the substring of $1 starting at position x ending at position y.
}
Raku, 20 bytes
{.rotate(all 1..$_)}
Anonymous code block that has input/output as a list of characters. The output is a Junction object that contains all the rotated arrays. I'm not sure how legal this is, since extracting values from a Junction is not normal.
Explanation:
{ } # Anonymous codeblock
.rotate( ) # Rotate the input list
all 1..$_ # By all of the range 1 to length of the input array
# all creates a junction of values
# And it runs the function on each value
The all can be replaced by any of any, one, [&], [|], [^].
If the Junction isn't allowed, here's an alternate solution:
Raku, 20 bytes
{{.rotate(++$)xx$_}}
There's probably a better way to reset the anonymous variable There is! And it's the same size as the Junction solution somehow.++$ than by wrapping the code in another code block...
sed 4.2.2 -r, 34 bytes
h;:
x;s/(.)(.*)/\2\1/p
x;s/.//;//b
honestly surprised there's not a sed answer here yet, this is something sed does well. it holds the string, and then puts the first char at the end and deletes a char from the held string until there's no more held string
min, 30 bytes
(dup(swap rest append dup)map)
Takes a list of characters and outputs a list of lists of characters.
C++, 320 bytes
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
int main(int argc, char* argv[]){std::string i=std::string(argv[1]);std::vector<std::string>r;std::cout<<i<<" -> ";for(int a=0;a<i.size();a++){std::rotate(i.begin(),i.begin()+1,i.end());r.push_back(i);}for(const auto& b:r){std::cout<<b<<" ";}}
Forth (gforth), 62 bytes
: f >r i for j 0 do dup i j + k mod + 1 type loop cr next r> ;
Explanation
Input is the form of a standard forth string (addr & length) on the stack. Output is printed, one permutation per line, in "reverse" (moving characters from the end). Saved several bytes by abusing the return stack, to cut out a bunch of normal stack manipulation.
Code Explanation
: f \ start a new word definition
>r \ place string length on the return stack
i for \ start a reverse counted loop from len to 0
j 0 do \ start a counted loop from 0 to len
dup \ duplicate the string starting address
i j + \ add current index and offset
k mod \ Get the total modulo the string length to get current char index
+ \ add the current char index to the string starting address
1 type \ output the current char
loop \ end the inner counted loop
cr \ output a newline
next \ end the outer reverse counted loo
r> \ remove the string length from the return stack
; \ end word definition
Octave, 54 bytes
@(x)arrayfun(@(j)circshift(x,[0,j]),1:sum(x|1),'un',0)
I see basically two options here: subsetting + concatenation and using a built-in circshift to rotate a string. The built-in approach turned to be the shorter one.
Swift 5.9, 65 59 57 bytes
var s="",r={s=$0
s.map{$0
s+=[s.removeFirst()]
print(s)}}
r(_:) is the closure to call.
TI-Basic, 40 bytes
For(I,1,length(Ans)-1
sub(Ans,2,length(Ans)-1)+sub(Ans,1,1
Disp Ans
End
Ans
Takes input in Ans. Rotates to the left.
Brachylog, 8 bytes
l≥ℕ₁;?↺₍
Generator solution: takes a string as input, outputs one rotation at a time when called repeatedly. Try it online!
Explanation
l≥ℕ₁;?↺₍
l Length of input string
≥ Get a number less than or equal to that
ℕ₁ which is also an integer greater than or equal to 1
;? Put it in a list with the input string
↺₍ Rotate the latter the former number of times
Uiua SBCS, 7 bytes
⇌≡↻⇡⊃⧻¤
If it is allowed to start with the input rather than end with it, then remove the reverse for -1 byte.
⇌≡↻⇡⊃⧻¤
⊃⧻¤ # fix the input and get its length
⇡ # range
≡↻ # rotate input by each number in the range
⇌ # reverse
ForWhile 23 bytes
{:0$(.0@,0@(.0@,#:)9#)}
Input: a char array followed by its length (stored on stack)
Output: prints rotations of input separated by tab (newline would need an additional character)
Explanation
{ \ define anonymous procedure
:0$ \ store copy of string length at address 0
(. \ start for-loop, ignore loop-counter
0@, \ rotate top (string length) stack elements
0@(.0@,#:) \ print string but keep it on the stack
9# \ print tab
) \ end outer for-loop
} \ end procedure
Calling the procedure:
{:0$(.0@,0@(.0@,#:)9#)} \ procedure
1$ \ store procedure at address 1
"ForWhile" \ procedure argument
1@? \ call procedure
prints:
orWhileF rWhileFo WhileFor hileForW ileForWh leForWhi eForWhil ForWhile
Racket - 179 bytes
#!racket
(let([s(read-line)][a string-append])(let g([r s][i(string-length s)])(display(a r(if(= i 0)""" -> ")))(if(= i 0)(void)(g(a(substring r 1)(~a(string-ref r 0)))(- i 1)))))
Explanation
On line one we have the required language expression. Yesterday, I learnt that #![language] is short for #lang [language], but it is discouraged in normal programs.
On line two, we define an immediately invoked function using let. The parent let receives a line of input from the user and passes it to it's child let called g. The child let acts as a recursive loop that uses the length of the parent string as an iterator. The first if check is in charge of pretty printing the rotated string. (While it would save some bytes to remove it, I like the way it looks.) The second check is used to determine whether the string should be rotated again or if the program should end.
To rotate the string, we split the string at index 1 and append the first character to the end of the string.
#lang racket
(let ([str (read-line)] [str-app string-append])
(let loop ([rotated str] [idx (string-length str)])
(display (str-app rotated (if (= idx 0) "" " -> ")))
(if (= idx 0)
(void)
(loop (str-app (substring rotated 1)
(~a (string-ref rotated 0)))
(- idx 1)))))
Output (Input: Heya!)
Heya! -> eya!H -> ya!He -> a!Hey -> !Heya -> Heya!
Nekomata, 3 bytes
x→Ř
x Enumerate; push [0, 1, ..., len(input) - 1]
→ Increment
Ř Rotate right by that amount (automatically vectorized)
Unfortunately x is 0-indexed, so we have to increment it before rotating.
JavaScript (Node.js), 32 bytes
s=>[...s].map(_=>s=s.slice(1)+_)
JavaScript (Node.js), 32 bytes
s=>s.map(_=>s=[...s.slice(1),_])
Rockstar, 79 77 bytes
Listen to S
X's 0
While S at X
Cut S
Rock roll S in S
Join S
Say S
Let X be+1
Try it (Code will need to be pasted in)
JavaScript (Node.js), 41 bytes
Another JS answer, which doesn't beat any of the previous JS ones.
Input is an array of characters (as seen in other answers), and output is an array of strings.
Rotates the string the inverted way, as allowed by OP.
s=>[...s].map(_=>[...s]=s.pop()+s.join``)
Different approach that swaps each character with their corresponding one, obtained via calculation of its index (correct rotation direction, 58 bytes) :
s=>s.map((_,i)=>s.map((_,j)=>s[(i+j+1)%s.length]).join``)
Thunno 2, 3 bytes
ż€Ỵ
Explanation
ż€Ỵ # Implicit input
ż # Push the length range
€ # For each number in this range:
Ỵ # Rotate the input left that many times
Vyxal, 3 bytes
(Ǔ…
Explanation:
( # For each char in the input
Ǔ # Rotate left
… # Print without popping
Go, 105 bytes
func f(s[]rune)(o[][]rune){for i:=0;i<len(s);i++{o=append([][]rune{append(s[i:],s[:i]...)},o...)}
return}
Without the requirement of the original being at the end, this saves 13 bytes:
92 bytes
func f(s[]rune)(o[][]rune){for i:=0;i<len(s);i++{o=append(o,append(s[i:],s[:i]...))}
return}
APL (Dyalog Unicode), 13 bytes
{(↓,↑)∘⍵¨⍳≢⍵}
Over twice as long as the other APL answer, but uses a different more literal tactic. Test harness stolen from that answer.
{(↓,↑)∘⍵¨⍳≢⍵}
{ } ⍝ Define function
⍳≢ ⍝ Indexes of
⍵ ⍝ The input
¨ ⍝ For each item in ^
( ) ⍝ Apply the following function:
↓ ⍝ Drop n elements
↑ ⍝ Take n elements
, ⍝ Concatenate the 2 above results
∘⍵ ⍝ Bind the right input of the above function to the input
Factor, 25 bytes
[ all-rotations reverse ]
! "john"
all-rotations ! { "john" "ohnj" "hnjo" "njoh" }
reverse ! { "njoh" "hnjo" "ohnj" "john" }
MATL, 6 5 bytes
tf&+)
1 byte saved thanks to @luis!
Try it at MATL Online!
Explanation:
# Implicitly grab input string
t # Duplicate the input
f # Create an array [1, ..., N] where N is the number of characters in the input
&+ # Add the transpose of this array to itself to create a 2D array of indices
#
# + 1 2 3 4
# ----------
# 1 | 2 3 4 5
# 2 | 3 4 5 6
# 3 | 4 5 6 7
# 4 | 5 6 7 8
#
) # Use this 2D array to index into the original string using periodic indexing
# Implicitly display the resulting character array
Pepe, 64 52 bytes
rEEEEeREEeRREeeeREEReREEEeeReReeeReeERREeeerEEEEERee
Try it online! Uses newlines for separation.
Japt, 5 3 bytes
Takes input as a character array, outputs an array of character arrays
£=é
£=é :Implicit input of character array U
£ :Map
é : Rotate U one element to the right
= : Reassign to U for next iteration
perl 5, 18 (-n) bytes
Thanks to Xcali
s/./say$',$`,$&/ge
Original answer (23 bytes)
/^.+?(?{say$'.$&})(?!)/
brainfuck, 38 bytes
,[>>,]<<<+>[[.>>]<<[<<]>-[+>.>-].<<+>]
Based on the idea of JoKing to use null-characters as space symbols. This code marks the current letters to print and loops until it reaches the left end.
,[>>,]<< input string with empty cells in between
<+> set first marker
[ main loop
[.>>] print remaining characters
<<[<<] return to start
>-[+>.>-] print until marker (remove marker)
. print null
<<+ set new marker
> restart loop with next character to the left
] stop if there's no character to the left
cQuents, 11 bytes
=A#|LA)&_lZ
Explanation
=A#|LA)&_lZ
=A first term in sequence is the input
#|LA) add second input n: length of input
& output first n terms in sequence
each term equals:
_l unary rotate left of
Z previous term
Replace _l with _r to rotate right instead of left.
C# (.NET Core), 103, 79 bytes
Without LINQ.
EDIT: ASCII-only golfing -24 bytes with a better use of a for loop and substring return!
p=>{var s="";for(int j=0;j++<p.Length;s+=p+" ")p=p.Substring(1)+p[0];return s;}
MBASIC, 69 66 bytes
-3 bytes, thanks to Ørjan Johansen
1 INPUT S$:L=LEN(S$):FOR I=1 TO L:S$=MID$(S$+S$,2,L):PRINT S$:NEXT
PHP, 63 bytes
for($s=$argv[1];$x++<strlen($s);)echo$s=substr($s,1).$s[0]," ";
Output
$php strrot.php john
ohnj hnjo njoh john
$php strrot.php heehee
eeheeh eheehe heehee eeheeh eheehe heehee
Reticular, 56 38 bytes
iSL:%=@qB[:%`@d]:%`*[[o]:%`1-*p$]:%`*;
Explanation with input "Hee"
iS # Read input string and put its chars into an array
L:%= # Get length of string and save it as `%`
@qB # Reverse array and push its items to the stack
Stack: [H, e, e]
[:%`@d]:%`* # Duplicates the top length(str) items in the stack
a total of length(str) number of times
Stack before: [H, e, e]
Stack after: [H, e, e, H, e, e, H, e, e, H, e, e]
[[o]:%`1-*p$]:%`* # Output the top length(str) items from the stack
with a trailing newline, and then
pop the next item in the stack.
Iterate this `%` number of times
Stack before: [H, e, e, H, e, e, H, e, e, H, e, e]
Stack after 1st iteration: [e, e, H, e, e, H, e, e]
Output: Hee
Stack after 2nd iteration: [e, H, e, e]
Output: Hee
eeH
Stack after 3rd iteration: []
Output: Hee
eeH
eHe
; # Exit
Runic Enchantments, 59 bytes
>iu0l:1-}[{ R{:0=1\
/:$ak$0l1-[{U$:/?-/
\}?*2=0:-1{]{~ /;$~
Can handle inputs up to 8 characters (spaces need to be escaped, however).
Essentially just a bunch of stack manipulation, with integer 0 denoting the end of the stack and the original length used as a counter held at the end.
Without using the stack-of-stacks commands [ and ] the solution is slightly larger (63 bytes) but can handle strings up to 16 characters:
>iu0l1-}l1-sRl1-s:0 \
/s:$ak$0l1-sU$:/?-1=/
\-1l}?*5=0:-1{~/;${
Common Lisp, 88 bytes
(lambda(x)(loop for s from 1 to(length x)do(format t"~a~a "(subseq x s)(subseq x 0 s))))
JavaScript, 48 43 36 bytes
-5 bytes courtesy of @Bubbler *-7 bytes courtesy of @Shaggy
Input is a character array and output is an array of character arrays.
s=>s.map(_=>([a,...b]=s,s=[...b,a]))
C (32-bit), 58 51 50 bytes
-1 byte for a nice round number thanks to ceilingcat
i;f(s){for(i=0;i++<printf("%s%.*s\n",s+i,i,s)-2;);}
Degolf
i; // "Global" i.
f(s){ // s is pointer to string, which conveniently fits in a 32 bit integer.
for(i=0; // Initialize i.
// Increment i and take its complement, and add it to the
// return value of printf(); which just happens to be strlen(s)+1.
// ~i + strlen(s) + 1 == strlen(s) + 1 - i - 1, so the last printed
// string is the original string.
~++i + printf("%s%.*s\n",s+i,i,s);
// The printf prints two strings: first until the terminating \0,
// the second until a \0 or until i chars have been printed. It also
// prints a linefeed.
}
Wolfram Language (Mathematica), 35 26 bytes
Partition[#,Tr[1^#],1,-1]&
Takes a list of characters as input.
Partition (but not its variant StringPartitionused below) has an optional fourth argument for treating its input as cyclic (and for specifying how exactly to do so), which makes this solution simpler than the string one - in addition to not having any 15-character built-in functions.
Wolfram Language (Mathematica), 44 bytes
Rest@StringPartition[#<>#,StringLength@#,1]&
The same, but takes a string as input.
Turns "john" into "johnjohn", then takes all the length-StringLength["john"] substrings of this string with offset 1, producing {"john","ohnj","hnjo","njoh","john"}, then drops the first of these with Rest.
C (clang), 57 54 bytes
i;f(int*a){for(i=0;a[i++];printf("%S%.*S ",a+i,i,a));}
Takes input as a wide string.
Lua, 61 bytes
function(s)for i=1,#s do print(s:sub(i+1)..s:sub(1,i))end end
Split string at successive indices from one to the length of the string (one-based indexing), concatenate the pieces in the reverse order, print.
JavaScript, 36 bytes
Saved 3 bytes thanks to @Shaggy by using shift() instead of splice().
a=>a.map(x=>a.push(a.shift())&&a+"")
Pyth, 7 bytes
_.e.>Qk
Accepts input as a string or as a list of characters, output is a list of the same. Try it online here.
JavaScript (ES6), 37 32 bytes
Returns an array of strings.
s=>[...s].map(c=>s=s.slice(1)+c)
MathGolf, 5 bytes
hÅ╫o;
Explanation
h length of array/string without popping
Å start block of length 2
╫ left-rotate bits in int, list/str
o print TOS without popping
; discard TOS
SNOBOL4 (CSNOBOL4), 82 bytes
S =INPUT
T X =X + 1
S LEN(1) . L REM . R
OUTPUT =S =R L LE(X,SIZE(S)) :S(T)
END
Clojure, 64 bytes
(fn[w](take(count w)(rest(iterate #(str(subs % 1)(first %))w))))
See the pre-golfed code below for an explanation. Returns a (lazy) list of strings.
(defn cycle-word [word]
(->> ; Take the word
word
; Create an infinite list of iterations of strings where
; the first character is moved to the end of the subs(tring)
(iterate #(str (subs % 1) (first %)))
; Drop the first result since we don't want it to start with the original word
(rest)
; Then take as many iterations from the infinite list as the word has characters
(take (count word))))
(cycle-word "john")
=> ("ohnj" "hnjo" "njoh" "john")
Java (JDK), 85 bytes
s->{for(int i=s.length();i-->0;)System.out.println(s.substring(i)+s.substring(0,i));}
Powershell, 44 bytes
($s=$args|% t*y)|%{$h,$t=$s;-join($s=$t+$h)}
Test script:
$f = {
($s=$args|% t*y)|%{$h,$t=$s;-join($s=$t+$h)}
}
@(
,('john', 'ohnj', 'hnjo', 'njoh', 'john')
,('heehee', 'eeheeh', 'eheehe', 'heehee', 'eeheeh', 'eheehe', 'heehee')
) | % {
$s,$expected = $_
$result = &$f $s
"$result"-eq"$expected"
$result
}
output:
True
ohnj
hnjo
njoh
john
True
eeheeh
eheehe
heehee
eeheeh
eheehe
heehee
brainfuck, 59 bytes
,[>,]<[>>[>]+[<]<[<]>-[[>]>[>]<+[<]<[<]>-]>[.>]>[.>]<[<].<]
Outputs each string separated by null bytes.
Explanation:
,[>,] # Get input
<[ # Start loop over input
>>[>] # Go to end of the string
+ # Set it to one to mark it
[<]<[<]> # Move to the beginning of input
-[[>]>[>]<+[<]<[<]>-] # Transfer the first character to the end
>[.>]>[.>] # Print the rotated string
<[<]. # Print a nul byte
<] # Repeat loop while input
Perl 6, 32 bytes
{m:ex/^(.*)(.+)$/».&{[R~] @$_}}
m:ex/^(.*)(.+)$/ exhaustively matches the given regex, splitting the input string at every possible place, except that the second substring must have at least one character--that prevents the input string from showing up twice in the output. Then each of the resulting Match objects' capture groups are reduced ([]) to a single string with R~, the reversed string concatenation operator.
Tcl, 78 bytes
proc R t {time {puts [set t [regsub -all (.?)(.*) $t {\2\1}]]} [string le $t]}
Pyth, 11 bytes
VSlQ+>QN<QN
Pretty much just a port of my Python answer
Explanation
==================================================
assign('Q',eval_input())
for N in num_to_range(Psorted(Plen(Q))):
imp_print(plus(gt(Q,N),lt(Q,N)))
==================================================
V # for N in
S # 1-indexed range
lQ # length of evaluated input
+ # concatanate
>QN # all characters after index N in Q (Q[N:])
<QN # and all characters before index N in Q (Q[:N])
Python 2, 54 48 bytes
lambda i:[i[x:]+i[:x]for x in range(1,len(i)+1)]
Well beaten by xnor but posted as an alternative approach anyway.
J, 7 bytes
#\|."{]
Explanation:
|."{ - rotate ( "{ is short for "0 1 - rank 0 1 )
] - the input
#\ - lenght of the successive prefixes of the input
Attache, 13 bytes
Rotate#{1:#_}
Explanation
Rotate#{1:#_}
# fork(f, g) = ${ f[x, g[x]] }; this forks:
Rotate rotate's the input by
{1:#_} each number from 1 to the length of the input
Alternatives
15 bytes: {_&Rotate!1:#_}
16 bytes: {Rotate[_,1:#_]}
16 bytes: Rotate@Rotations
16 bytes: Rotate#(1&`:@`#)
17 bytes: Rotate#{1+Iota@_}
18 bytes: Rotate#(1&`+@Iota)
19 bytes: Rotate#(Succ=>Iota)
Charcoal, 10 bytes
⮌Eθ⭆θ§θ⁻μκ
Try it online! Link is to verbose version of code. Explanation:
θ Input string
E Map over characters
θ Input string
⭆ Map over characters and join
θ Input string
§ Circularly indexed by
⁻ Difference between
μ Inner index
κ Outer index
⮌ Reversed
Implicitly print each string on its own line
To rotate in the opposite direction, replace Minus with Plus.
Jelly, 2 bytes
ṙJ
A monadic Link accepting a list of characters which yields a list of lists of characters
Try it online! (footer pretty prints by calling the link and joining with newline characters)
APL (Dyalog Unicode), 6 bytesSBCS
⍳∘≢⌽¨⊂
⍳ the indices
∘ of
≢ the tally
⌽¨ each rotate (to the left)
⊂ the entire string
