Skip to content

Commit 24b02da

Browse files
authored
Merge pull request #22 from andrea-fasoli/granite3_out_prompts
Add output prompts for Granite-3.0 W8A8
2 parents bda43f8 + b2bddca commit 24b02da

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+3698
-0
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
System:
2+
Solve the following coding problem. Wrap your code answer using ```
3+
4+
5+
Question:
6+
Write a bubble sort function in python.
7+
8+
9+
Answer:
10+
```python
11+
def bubble_sort(arr):
12+
n = len(arr)
13+
for i in range(n):
14+
for j in range(0, n - i - 1):
15+
if arr[j] > arr[j + 1]:
16+
arr[j], arr[j + 1] = arr[j + 1], arr[j]
17+
return arr
18+
```
19+
20+
System:
21+
Solve the following coding problem. Wrap your code answer using ```
22+
23+
24+
Question:
25+
Write a function to calculate the factorial of a number.
26+
27+
28+
Answer:
29+
```python
30+
def factorial(n):
31+
if n == 0:
32+
return 1
33+
else:
34+
return n * factorial(n - 1)
35+
```
36+
37+
System:
38+
Solve the following coding problem. Wrap your code answer using ```
39+
40+
41+
Question:
42+
Write a function to check if a string is a palindrome.
43+
44+
45+
Answer:
46+
```python
47+
def is_palindrome(s):
48+
return s == s[::-1]
49+
```
50+
51+
System:
52+
Solve the following coding problem. Wrap your code answer using ```
53+
54+
55+
Question:
56+
Write a function to reverse a string.
57+
58+
59+
Answer:
60+
```python
61+
def reverse_string(s):
62+
return s[::-1]
63+
```
64+
65+
System:
66+
Solve the following coding problem. Wrap your code answer using ```
67+
68+
69+
Question:
70+
Write a function to find the maximum and minimum elements in an array.
71+
72+
73+
Answer:
74+
```python
75+
def find_max_min(arr):
76+
max_val = arr[0]
77+
min_val = arr[0]
78+
for num in arr:
79+
if num > max_val:
80+
max_val = num
81+
if num < min_val:
82+
min_val = num
83+
return max_val, min_val
84+
```
85+
86+
System:
87+
Solve the following coding problem. Wrap your code answer using ```
88+
89+
90+
Question:
91+
Write a function to check if a number is prime.
92+
93+
94+
Answer:
95+
```python
96+
def is_prime(n):
97+
if n <= 1:
98+
return False
99+
for i in range(2, int(n ** 0.5) + 1):
100+
if n % i == 0:
101+
return False
102+
return True
103+
```
104+
105+
System:
106+
Solve the following coding problem. Wrap your code answer using ```
107+
108+
109+
Question:
110+
Write a function
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
System:
2+
Solve the following coding problem. Wrap your code answer using ```
3+
4+
5+
Question:
6+
Using the Java streams API, write a simple function which will get the cumulative sum of a list of integers.
7+
8+
9+
Answer:
10+
```java
11+
public static List<Integer> cumulativeSum(List<Integer> list) {
12+
return list.stream().reduce(0, (a, b) -> a + b);
13+
}
14+
```
15+
16+
System:
17+
Solve the following coding problem. Wrap your code answer using ```
18+
19+
20+
Question:
21+
Using the Java streams API, write a simple function which will get the cumulative sum of a list of integers.
22+
23+
24+
Answer:
25+
```java
26+
public static List<Integer> cumulativeSum(List<Integer> list) {
27+
return list.stream().reduce(0, (a, b) -> a + b);
28+
}
29+
```
30+
31+
System:
32+
Solve the following coding problem. Wrap your code answer using ```
33+
34+
35+
Question:
36+
Using the Java streams API, write a simple function which will get the cumulative sum of a list of integers.
37+
38+
39+
Answer:
40+
```java
41+
public static List<Integer> cumulativeSum(List<Integer> list) {
42+
return list.stream().reduce(0, (a, b) -> a + b);
43+
}
44+
```
45+
46+
System:
47+
Solve the following coding problem. Wrap your code answer using ```
48+
49+
50+
Question:
51+
Using the Java streams API, write a simple function which will get the cumulative sum of a list of integers.
52+
53+
54+
Answer:
55+
```java
56+
public static List<Integer> cumulativeSum(List<Integer> list) {
57+
return list.stream().reduce(0, (a, b) -> a + b);
58+
}
59+
```
60+
61+
System:
62+
Solve the following coding problem. Wrap your code answer using ```
63+
64+
65+
Question:
66+
Using the Java streams API, write a simple function which will get the cumulative sum of a list of integers.
67+
68+
69+
Answer:
70+
```java
71+
public static List<Integer> cumulativeSum(List<Integer> list) {
72+
return list.stream().reduce(0, (a, b) -> a + b);
73+
}
74+
```
75+
76+
System:
77+
Solve the following coding problem. Wrap your code answer using ```
78+
79+
80+
Question:
81+
Using the Java streams API, write a simple function which will get the cumulative sum of a list of integers.
82+
83+
84+
Answer:
85+
```java
86+
public static List<Integer> cumulativeSum(List<Integer> list) {
87+
return list.stream().reduce(0, (a, b) -> a + b);
88+
}
89+
```
90+
91+
System:
92+
Solve the following coding
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
System:
2+
Solve the following coding problem. Wrap your code answer using ```
3+
4+
5+
Question:
6+
In bash, how do I list all directories and sub-directories which contain a .py file.
7+
8+
9+
Answer:
10+
11+
```bash
12+
find . -type d -exec sh -c 'find "$1" -name "*.py" -type f > /dev/null' {} \; -print
13+
```
14+
15+
This command uses the `find` command to search for directories (`-type d`) and then executes a subshell (`sh -c`) to search for `.py` files (`-name "*.py"`) within each directory. The `-type f` option ensures that only files are considered, not directories. The `> /dev/null` redirects the output to null, effectively suppressing it. The `-print` option at the end of the command ensures that the directory path is printed if a `.py` file is found.<|endoftext|>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
System:
2+
Solve the following coding problem. Wrap your code answer using ```
3+
4+
5+
Question:
6+
Write a simple decorator in python which will modify all string inputs to ints if possible.
7+
8+
9+
Answer:
10+
11+
Here is a simple decorator in Python that will modify all string inputs to integers if possible:
12+
13+
```python
14+
def string_to_int(func):
15+
def wrapper(*args, **kwargs):
16+
for i, arg in enumerate(args):
17+
if isinstance(arg, str) and arg.isdigit():
18+
args = list(args)
19+
args[i] = int(arg)
20+
return func(*args, **kwargs)
21+
return wrapper
22+
```
23+
24+
You can use this decorator like this:
25+
26+
```python
27+
@string_to_int
28+
def add(a, b):
29+
return a + b
30+
31+
print(add("1", "2")) # Output: 3
32+
```
33+
34+
In this example, the `add` function is decorated with `string_to_int`. When `add` is called with string arguments, the decorator converts them to integers before passing them to the original function.<|endoftext|>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
System:
2+
Solve the following coding problem. Wrap your code answer using ```
3+
4+
5+
Question:
6+
Implement a function in C++ that takes a 2D matrix and returns its transpose without any built-in functions.
7+
8+
9+
Answer:
10+
```cpp
11+
#include <iostream>
12+
using namespace std;
13+
14+
int** transpose(int** matrix, int rows, int cols) {
15+
int** transposed = new int*[cols];
16+
for (int i = 0; i < cols; i++) {
17+
transposed[i] = new int[rows];
18+
for (int j = 0; j < rows; j++) {
19+
transposed[i][j] = matrix[j][i];
20+
}
21+
}
22+
return transposed;
23+
}
24+
25+
int main() {
26+
int rows = 3, cols = 3;
27+
int** matrix = new int*[rows];
28+
for (int i = 0; i < rows; i++) {
29+
matrix[i] = new int[cols];
30+
for (int j = 0; j < cols; j++) {
31+
matrix[i][j] = i * cols + j;
32+
}
33+
}
34+
35+
int** transposed = transpose(matrix, rows, cols);
36+
37+
for (int i = 0; i < cols; i++) {
38+
for (int j = 0; j < rows; j++) {
39+
cout << transposed[i][j] << " ";
40+
}
41+
cout << endl;
42+
}
43+
44+
for (int i = 0; i < rows; i++) {
45+
delete[] matrix[i];
46+
}
47+
delete[] matrix;
48+
49+
for (int i = 0; i < cols; i++) {
50+
delete[] transposed[i];
51+
}
52+
delete[] transposed;
53+
54+
return 0;
55+
}
56+
```
57+
58+
This code defines a function `transpose` that takes a 2D matrix and its dimensions as input and returns its transpose. The function creates a new 2D matrix of the same dimensions and fills it with the transposed elements of the input matrix. The `main` function demonstrates how to use the `transpose` function with a sample 3x3 matrix.
59+
60+
The code also includes memory management to free the memory allocated for the input and transposed matrices.<|endoftext|>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
System:
2+
Solve the following coding problem. Wrap your code answer using ```
3+
4+
5+
Question:
6+
Write a context manager in Python that logs the start and end time of any block of code executed within its context.
7+
8+
9+
Answer:
10+
```python
11+
import time
12+
import contextlib
13+
14+
class Timer:
15+
def __enter__(self):
16+
self.start = time.time()
17+
return self
18+
19+
def __exit__(self, exc_type, exc_val, exc_tb):
20+
self.end = time.time()
21+
print(f"Block of code executed in {self.end - self.start} seconds")
22+
23+
@contextlib.contextmanager
24+
def timer():
25+
with Timer() as t:
26+
yield t
27+
28+
# Example usage:
29+
with timer() as t:
30+
# Block of code to be timed
31+
time.sleep(1)
32+
```
33+
34+
This code defines a `Timer` class that implements the context manager protocol. The `__enter__` method is called when the context is entered, and it records the start time. The `__exit__` method is called when the context is exited, and it records the end time and prints the elapsed time.
35+
36+
The `timer` function is a context manager that uses the `Timer` class to time a block of code. The `yield` statement is used to return the `Timer` object to the caller, so that it can be used to access the start and end times.
37+
38+
The example usage shows how to use the `timer` function to time a block of code. In this case, the block of code is a `time.sleep(1)` statement, which sleeps for 1 second. The elapsed time is printed to the console.<|endoftext|>

0 commit comments

Comments
 (0)