winglian commited on
Commit
93d077c
1 Parent(s): fc85dba

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +24 -4
README.md CHANGED
@@ -59,14 +59,34 @@ Manticore was fine-tuned from the base model LlaMa 13B, please refer to its mode
59
  ## Examples
60
 
61
  ````
62
- ### Instruction: write Python code that returns the first n numbers of the Fibonacci sequence using memoization.
63
-
64
- ### Assistant:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  ````
66
 
67
  ```
68
  ### Instruction: Finish the joke, a mechanic and a car salesman walk into a bar...
69
 
70
- ### Assistant:
71
  ```
72
 
 
59
  ## Examples
60
 
61
  ````
62
+ USER: write Python code that returns the first n numbers of the Fibonacci sequence using memoization.
63
+
64
+ ASSISTANT:
65
+ Sure! Here’s an example implementation of the Fibonacci sequence using memoization in Python:
66
+ def fibonacci(n):
67
+ """Return the first n numbers of the Fibonacci sequence."""
68
+ cache = {} # Memoize the previous results for faster lookups
69
+ def memoized_fibonacci(*args, **kwargs):
70
+ if args[0] in cache:
71
+ return cache[args[0]]
72
+ else:
73
+ result = fibonacci(args[0])
74
+ cache[args[0]] = result
75
+ return result
76
+ def fibonacci_recursive(n):
77
+ """Recursive implementation of the Fibonacci sequence."""
78
+ if n <= 1:
79
+ return n
80
+ else:
81
+ return fibonacci_recursive(n-1) + fibonacci_recursive(n-2)
82
+ return memoized_fibonacci(*[n] * len(cache))
83
+
84
+ In this implementation, we define a function memoized_fibonacci that takes the same arguments as fibonacci, but also receives a cache dictionary. If an argument is found in the cache dictionary, it returns the corresponding value from the cache. Otherwise, it computes the value of fibonacci(n) and stores it
85
  ````
86
 
87
  ```
88
  ### Instruction: Finish the joke, a mechanic and a car salesman walk into a bar...
89
 
90
+ ### Assistant: The mechanic turns to the salesman and says, "I don't know what you drive but I bet it never breaks down." The salesman responds, "That's because my customers buy cars like yours!"
91
  ```
92