Advertisement
brewersfan1976

cylic_string.rb

Oct 15th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.58 KB | None | 0 0
  1. def cyclicString(s)
  2.     answer = 1
  3.    
  4.     while (answer < s.length)
  5.           correct = true
  6.           position = 0
  7.        
  8.           while (position + answer < s.length)
  9.                 if s[position] != s[position + answer] then
  10.                    correct = false
  11.                    break
  12.                 end
  13.                    
  14.                 position = position + 1
  15.           end
  16.            
  17.           if correct == true then
  18.              return answer
  19.           end
  20.              
  21.           answer = answer + 1
  22.     end
  23.              
  24.     return s.length
  25. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement