Detect rotated strings

Ruby 49 41

a,b=$*;puts (a*2).sub(b,'')==a ?:yes: :no

Edit: replaced gets.split by $*


Python, 70 bytes

a,b=raw_input().split()
print ['No','Yes'][a in b*2and len(a)==len(b)]

Testing ...


APL (28)

Takes input on two lines.

'No' 'Yes'[1+(⊂⍞)∊⌽∘A¨⍳⍴A←⍞]

Explanation:

  • A←⍞: read a line of input and store it in A
  • ⌽∘A¨⍳⍴A: Rotate A by x, for each x in [1..length A]. Gives a list, i.e. estT stTe tTes Test
  • (⊂⍞)∊: read another line of input, and see if it is in this list.
  • 1+: add one to this, giving 1 if the strings were not rotated and 2 if they were
  • 'No' 'Yes'[...]: Select either the first or second element from the list 'No' 'Yes' depending on whether the strings were rotated or not.
  • This value is output automatically.