calculation / ap.py
OzoneAsai's picture
Upload 3 files
ef90e54
raw
history blame
No virus
1.24 kB
import csv
import time
from tqdm import tqdm
dataset = []
min_value = -10000
max_value = 10000
# Calculate the total number of combinations
total_combinations = (max_value - min_value + 1) ** 2
# Save the dataset to a CSV file
output_file = "output_dataset.csv"
with open(output_file, mode="w", newline="", encoding="utf-8") as file:
writer = csv.writer(file)
writer.writerow(["instruction", "output"]) # Write header
with tqdm(total=total_combinations, desc="Generating Dataset") as pbar:
start_time = time.time()
for a in range(min_value, max_value + 1):
for b in range(min_value, max_value + 1):
# Generate the instruction
if b < 0:
instruction = f"{a}-({abs(b)})"
else:
instruction = f"{a}+{b}"
# Calculate the output
output = a + b
# Write the row to the CSV file in real-time
writer.writerow([instruction, str(output)])
pbar.update(1)
end_time = time.time()
elapsed_time = end_time - start_time
print(f"Total time taken: {elapsed_time:.2f} seconds")
print(f"Dataset saved to {output_file}.")