Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def brent(numbers):
- power = loop_length = 1
- tortoise = 0
- hare = 0
- while numbers[tortoise] != numbers[hare]:
- if power == loop_length:
- tortoise = hare
- power *= 2
- loop_length = 0
- hare += 1
- loop_length += 1
- position = 0
- tortoise = hare = 0
- for i in range(loop_length):
- hare += 1
- while numbers[tortoise] != numbers[hare]:
- tortoise += 1
- hare += 1
- position += 1
- return position, loop_length
- numbers = [12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 11, 11, 11, 11]
- print brent(numbers)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement