-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
time-complexity.el
89 lines (78 loc) · 2.41 KB
/
time-complexity.el
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
;; https://beta.openai.com/examples/default-time-complexity
(let ((input "def foo(n, k):
accum = 0
for i in range(n):
for l in range(k):
accum += i
return accum
\"\"\"
The time complexity of this function is"))
(openai-api-sync
(list
`((model . "text-davinci-003")
(prompt . ,input)
(top_p . 1)
(max_tokens . 64)
(temperature . 0)
(stop . ["\n"])))))
'(" O(n*k). This is because the function has two nested for loops, each of which iterates n and k times respectively. Therefore, the total number of iterations is n*k, which is the time complexity of the function.")
;; putting ;; clojure-mode on top turns out to be a crucial hint (for the explanation)
(let ((input ";; clojure-mode
(for [x (range n)
y (range j)]
[x y])
;; The time complexity of this function is"))
(openai-api-sync
(list
`((model . "text-davinci-003")
(prompt . ,input)
(top_p . 1)
(max_tokens . 64)
(temperature . 0)
(stop . ["\n"])))))
'(" O(n*j). This is because the loop is iterating over two ranges, n and j, and the time complexity is the product of the two ranges.")
'
;; it doesn't do the explanation when I don't have comment syntax
(let ((input ";; clojure-mode
(for [x (range n)
y (range j)]
[x y])
The time complexity of this function is"))
(openai-api-sync
(list
`((model . "text-davinci-003")
(prompt . ,input)
(top_p . 1)
(max_tokens . 200)
(temperature . 0)
(stop . ["\n"])))))
'(" O(n*j).")
;; this actually turned out cool
(defun openai-improve-suggestions ()
(interactive)
(let ((input
(format ";; clojure-mode
%s
;; This code can be improved in the following ways: "
(buffer-substring-no-properties (region-beginning)
(region-end)))))
(with-current-buffer-window "output"
nil
nil
(cl-loop for res in
(openai-api-sync
(list
`((model . "text-davinci-003")
(prompt . ,input)
(max_tokens . 256)
(temperature . 0.8))))
do (insert res)))))
;; like this you get readme text lol
(let ((input "Implement union-find data structure in clojure"))
(openai-api-sync
(list
`((model . "code-davinci-002")
(prompt . ,input)
(max_tokens . 200)
(temperature . 0)
(top_p . 1)))))