-
Notifications
You must be signed in to change notification settings - Fork 0
/
out.rb
56 lines (47 loc) · 1.29 KB
/
out.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
RECORDER = []
def fibonacci(n)
record = {}
method(__method__).parameters.each{|arg| record[arg[1].to_s] = (eval arg[1].to_s)}
RECORDER.push(["fibonacci", record, "called"])
x = OWLJPRQHfibonacci(*(record.values))
RECORDER.push(["fibonacci", x, "returned"])
return x
end
def OWLJPRQHfibonacci(n)
f0 = 0
f1 = 1
i = 0
while i < n
f2 = f0 + f1
f0 = f1
f1 = f2
i += 1
end
return f0
end
def palindrome?(string)
record = {}
method(__method__).parameters.each{|arg| record[arg[1].to_s] = (eval arg[1].to_s)}
RECORDER.push(["palindrome?", record, "called"])
x = BAYSXNWDpalindrome?(*(record.values))
RECORDER.push(["palindrome?", x, "returned"])
return x
end
def BAYSXNWDpalindrome?(string)
string == string.reverse
end
def quicksort(arr)
record = {}
method(__method__).parameters.each{|arg| record[arg[1].to_s] = (eval arg[1].to_s)}
RECORDER.push(["quicksort", record, "called"])
x = HUWLFAMVquicksort(*(record.values))
RECORDER.push(["quicksort", x, "returned"])
return x
end
def HUWLFAMVquicksort(arr)
return arr if arr.length == 0
left = arr.select{|num| num < arr[0]}
mid = arr.select{|num| num == arr[0]}
right = arr.select{|num| num > arr[0]}
return quicksort(left)+mid+quicksort(right)
end