Commit
·
74ab58e
1
Parent(s):
c092dc8
Initial
Browse files
README.md
CHANGED
@@ -27,6 +27,7 @@ dataset to enhance its reasoning capabilities.
|
|
27 |
### TableofContents
|
28 |
|
29 |
- [Usage](#usage)
|
|
|
30 |
- [Dataset](#dataset)
|
31 |
- [Training](#training)
|
32 |
- [License](#licence)
|
@@ -64,7 +65,7 @@ model.eval()
|
|
64 |
|
65 |
messages = [
|
66 |
{"role": "system", "content": "You are a helpful coding assistant."},
|
67 |
-
{"role": "user", "content": "
|
68 |
]
|
69 |
|
70 |
prompt = tokenizer.apply_chat_template(
|
@@ -84,6 +85,159 @@ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
|
84 |
|
85 |
---
|
86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
### Dataset
|
88 |
|
89 |
- [nvidia/OpenCodeReasoning](https://huggingface.co/datasets/nvidia/OpenCodeReasoning)
|
|
|
27 |
### TableofContents
|
28 |
|
29 |
- [Usage](#usage)
|
30 |
+
- [Comparison](#comparison)
|
31 |
- [Dataset](#dataset)
|
32 |
- [Training](#training)
|
33 |
- [License](#licence)
|
|
|
65 |
|
66 |
messages = [
|
67 |
{"role": "system", "content": "You are a helpful coding assistant."},
|
68 |
+
{"role": "user", "content": "Please provide a Python script that checks whether a number is prime."}
|
69 |
]
|
70 |
|
71 |
prompt = tokenizer.apply_chat_template(
|
|
|
85 |
|
86 |
---
|
87 |
|
88 |
+
### Comparison
|
89 |
+
|
90 |
+
- Please pay attention to the `<think> </think>` special tokens in the [Reasoning Model](#reasoning-model). As you can
|
91 |
+
see, the `Reasoning Model` can now _“think”_.
|
92 |
+
|
93 |
+
#### Base Model
|
94 |
+
|
95 |
+
`System:` You are a helpful coding assistant.
|
96 |
+
|
97 |
+
`User:` Please provide a Python script that checks whether a number is prime.
|
98 |
+
|
99 |
+
`Assistant:`
|
100 |
+
|
101 |
+
```python
|
102 |
+
def check_prime(num):
|
103 |
+
# Check if the number is less than 2
|
104 |
+
if num < 2:
|
105 |
+
return False
|
106 |
+
# Check for factors from 2 to the square root of the number
|
107 |
+
for i in range(2, int(num**0.5) + 1):
|
108 |
+
if num % i == 0:
|
109 |
+
return False
|
110 |
+
# If no factors were found, the number is prime
|
111 |
+
return True
|
112 |
+
|
113 |
+
# Example usage
|
114 |
+
number = 7
|
115 |
+
if check_prime(number):
|
116 |
+
print(f"{number} is a prime number.")
|
117 |
+
else:
|
118 |
+
print(f"{number} is not a prime number.")
|
119 |
+
```
|
120 |
+
|
121 |
+
In this Python script, the function `check_prime` takes an integer as input and returns `True` if the number is prime,
|
122 |
+
otherwise it returns `False`. The function first checks if the number is less than 2, which means it cannot be prime.
|
123 |
+
Then, it iterates from 2 up to the square root of the number (inclusive). If any factor of the number is found within
|
124 |
+
this range, the function immediately returns `False`, indicating that the number is not prime. If no factors are found
|
125 |
+
after checking all possible divisors, the function concludes that the number is prime and returns `True`.
|
126 |
+
|
127 |
+
The example usage demonstrates how to call the `check_prime` function with the number 7. The output will indicate
|
128 |
+
whether 7 is a prime number or not.
|
129 |
+
|
130 |
+
#### Reasoning Model
|
131 |
+
|
132 |
+
`System:` You are a helpful coding assistant.
|
133 |
+
|
134 |
+
`User:` Please provide a Python script that checks whether a number is prime.
|
135 |
+
|
136 |
+
`Assistant:`
|
137 |
+
`<think>`
|
138 |
+
Okay, I need to write a Python program that checks if a given number is prime. Hmm, what's a prime number? Oh right, a
|
139 |
+
prime number has exactly two distinct positive divisors: 1 and itself. So for a number to be prime, it must not have any
|
140 |
+
divisors other than those two.
|
141 |
+
|
142 |
+
First, let's think about the steps involved. The first thing is to determine if there are any divisors other than 1 and
|
143 |
+
the number itself. How do I check that?
|
144 |
+
|
145 |
+
Well, for a number n, starting from 2 up to sqrt(n), check if any of them divide n. If any do, then it's not prime. But
|
146 |
+
wait, maybe even before checking up to the square root, some numbers might have factors beyond that. For example, take
|
147 |
+
|
148 |
+
9. The square root is 3. So checking 2,3,4 would catch 9's factors. Wait, but 3 divides 9, so the loop from 2 to sqrt(
|
149 |
+
n) (which is 3 in this case) will check 2 and 3. So yes, checking up to the square root is sufficient because any
|
150 |
+
composite number has at least one factor less than or equal to its square root.
|
151 |
+
|
152 |
+
So the plan is:
|
153 |
+
|
154 |
+
1. Read an integer from input.
|
155 |
+
2. Check if the number is less than 2. If so, it's not prime.
|
156 |
+
3. Otherwise, check from 2 up to the square root of the number. For each i, if the number mod i is zero, return False.
|
157 |
+
4. If none of the numbers in this range divide the number, return True.
|
158 |
+
|
159 |
+
Wait, but what about 0 and 1? Well, according to the problem statement, the input could be 0 or 1, which are not primes.
|
160 |
+
So we should handle those cases separately.
|
161 |
+
|
162 |
+
Let me outline the code structure.
|
163 |
+
|
164 |
+
Read the input number as an integer. Let's call it num.
|
165 |
+
|
166 |
+
Handle edge cases first:
|
167 |
+
|
168 |
+
- If num < 2: print "No" (since primes are >=2)
|
169 |
+
Else:
|
170 |
+
Compute sqrt_num = int(math.sqrt(num))
|
171 |
+
Then loop from 2 to sqrt_num inclusive. For each i, check if num % i ==0. If any such i exists, return False. Else,
|
172 |
+
after checking all, return True.
|
173 |
+
|
174 |
+
But how to compute the square root accurately in Python? Using math.isqrt for integers, which returns the floor of the
|
175 |
+
square root. That's better than using ** operator since it avoids floating point inaccuracies.
|
176 |
+
|
177 |
+
Wait, but what if the number is a perfect square? Like 9. Then math.isqrt(9) is 3. So in that case, the loop would check
|
178 |
+
up to 3. But when i reaches 3, 9%3 is 0, so it would return False, which is correct.
|
179 |
+
|
180 |
+
So the code would look something like this:
|
181 |
+
|
182 |
+
import math
|
183 |
+
|
184 |
+
n = int(input())
|
185 |
+
if n < 2:
|
186 |
+
print("No")
|
187 |
+
else:
|
188 |
+
sqrt_n = math.isqrt(n)
|
189 |
+
is_prime = True
|
190 |
+
for i in range(2, sqrt_n +1):
|
191 |
+
if n % i == 0:
|
192 |
+
is_prime = False
|
193 |
+
break
|
194 |
+
print("Yes" if is_prime else "No")
|
195 |
+
|
196 |
+
Wait, but wait, what about numbers like 25. The square root is 5. So the loop runs from 2 to 5. When i=5, 25%5 is 0, so
|
197 |
+
returns false. Correct.
|
198 |
+
|
199 |
+
This logic seems solid. Let me test some examples.
|
200 |
+
|
201 |
+
Test case 1: input 7. The loop runs up to 2. 2 to 2. Check 2. 7%2 is 1, so returns true. Output Yes.
|
202 |
+
|
203 |
+
Test case 2: input 6. sqrt(6) is ~2.449. So sqrt_n is 2. Loop from 2 to 2. Check 2. 6%2 is 0. So returns false. Output
|
204 |
+
No.
|
205 |
+
|
206 |
+
Another test case: 8. sqrt(8) is ~2.828. So sqrt_n is 2. Check 2. 8%2 is 0. So output No.
|
207 |
+
|
208 |
+
What about a prime number like 13. sqrt(13) is ~3.605. So loop up to 3. Check 2 and 3. 13%2 is 1, 13%3 is 1. So returns
|
209 |
+
true. Correct.
|
210 |
+
|
211 |
+
Edge case: 1. Output No.
|
212 |
+
|
213 |
+
Another edge case: 2. Output Yes.
|
214 |
+
|
215 |
+
What about a very large number, say 999983 (a prime). The code should check up to sqrt(999983) which is around 999.9. So
|
216 |
+
the loop runs 2 to 999. It will check all possible factors. Since it's a prime, none will divide it. So returns Yes.
|
217 |
+
|
218 |
+
So the code seems to handle all cases correctly.
|
219 |
+
|
220 |
+
I think that's the solution. Now, writing the code accordingly.
|
221 |
+
`</think>`
|
222 |
+
|
223 |
+
```python
|
224 |
+
import math
|
225 |
+
|
226 |
+
n = int(input())
|
227 |
+
if n < 2:
|
228 |
+
print("No")
|
229 |
+
else:
|
230 |
+
sqrt_n = math.isqrt(n)
|
231 |
+
is_prime = True
|
232 |
+
for i in range(2, sqrt_n + 1):
|
233 |
+
if n % i == 0:
|
234 |
+
is_prime = False
|
235 |
+
break
|
236 |
+
print("Yes" if is_prime else "No")
|
237 |
+
```
|
238 |
+
|
239 |
+
---
|
240 |
+
|
241 |
### Dataset
|
242 |
|
243 |
- [nvidia/OpenCodeReasoning](https://huggingface.co/datasets/nvidia/OpenCodeReasoning)
|