• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Jul 20th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
2.   attr_accessor :value, :next_node
3.
4.   def initialize(value, next_node=nil)
5.     @value = value
6.     @next_node = next_node
7.   end
8. end
9.
10. def print_values(list_node)
11.   print "#{list_node.value} --> "
12.
13.   if infinite_list?(list_node)
14.     mu, lam = repetition_params(list_node)
15.     (mu + lam).times do
16.       list_node = list_node.next_node
17.       print "#{list_node.value} --> "
18.     end
19.     print "(and then starts repeating)\n"
20.   else
21.     if list_node.next_node.nil?
22.       print "nil\n"
23.       return
24.     else
25.       print_values(list_node.next_node)
26.     end
27.   end
28. end
29.
30. def infinite_list?(list_node)
31.   tail = list_node.next_node
33.   count = 0
35.     count += 1
36.     tail = tail.next_node
38.   end
39.
40.   mu = 0
41.   tail = list_node
43.     tail = tail.next_node
45.     mu += 1
46.   end
47.
48.   lam = 1
52.     lam += 1
53.   end
54. # puts "mu: #{mu}, #{lam}"
55.   return mu, lam
56.   rescue NoMethodError
57.   false
58. end
59. alias :repetition_params :infinite_list?
60.
64. node1.next_node = node3 #creates an infinite loop
65.