Advertisement
Guest User

Untitled

a guest
May 24th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.38 KB | None | 0 0
  1. # you can write to stdout for debugging purposes, e.g.
  2. # puts "this is a debug message"
  3. def solution(a)
  4.     # write your code in Ruby 2.2
  5.     length = slow = fast = 0
  6.     loop do
  7.         fast = a[a[fast]]
  8.         slow = a[slow]
  9.         if fast == slow
  10.           loop do
  11.             fast = a[a[fast]]
  12.             slow = a[slow]
  13.             length += 1
  14.             if fast == slow
  15.                 return length
  16.             end
  17.           end
  18.         end
  19.     end
  20. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement