Skip to content

Commit

Permalink
add_ci
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainGoussault committed Dec 9, 2023
1 parent b96e435 commit f86ad59
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test all files
run: |
find . -name '*.py' ! -name 'day_5/*.py' -exec python {} \;
python ci.py
35 changes: 35 additions & 0 deletions ci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import subprocess
import glob

def run_all_python_files(files):

for file in files:
print("Running", file)
exit_code = run_python_script(file)
if exit_code != 0:
print(f"Error in {file}. Exiting with status code {exit_code}.")
return exit_code
return 0


def run_python_script(file_path):
try:
subprocess.check_output(["python3", file_path], stderr=subprocess.STDOUT, universal_newlines=True)
return 0
except subprocess.CalledProcessError as e:
print(f"Exception in {file_path}: {e.output}")
return e.returncode


if __name__ == "__main__":

# Utilisez le motif '*.py' pour rechercher tous les fichiers se terminant par '.py'
python_files = glob.glob('day_*/*.py')

# Affichez la liste des fichiers trouvés
print("Fichiers Python trouvés :")
for file in python_files:
print(file)
exit_code = run_all_python_files(python_files)
print(f"Exiting with status code {exit_code}.")
exit(exit_code)
19 changes: 11 additions & 8 deletions day_5/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

filename = "input.txt"
filename = "day_5/input_test.csv"

try:
with open(filename, 'r') as file:
Expand All @@ -20,6 +20,7 @@

MAP_SIZE = int(max_integer*1.1)


def string_to_int_list(input_string):
# Split the string into a list of substrings
substrings = input_string.split()
Expand All @@ -29,21 +30,23 @@ def string_to_int_list(input_string):

return int_list


def get_seeds(lines):
seed_line = lines[0]
seeds_str = seed_line.split(":")[1]
seeds_list = string_to_int_list(seeds_str)

new_seeds_list = np.empty(0) # np.zeros(len(MAP_SIZE))
for i in range(0, len(seeds_list), 2):
print("progress seeds: " + str(int(i / len(seeds_list) /2 * 100)) + "%")
start = seeds_list[i]
range_seed = seeds_list[i + 1]
new_stuff = np.arange(start, start + range_seed)
new_seeds_list = np.concatenate((new_seeds_list, new_stuff))
print("progress seeds: " + str(int(i / len(seeds_list) /2 * 100)) + "%")
start = seeds_list[i]
range_seed = seeds_list[i + 1]
new_stuff = np.arange(start, start + range_seed)
new_seeds_list = np.concatenate((new_seeds_list, new_stuff))

return new_seeds_list.astype(int)


def build_map(name, map_size):

map = np.arange(map_size)
Expand All @@ -65,10 +68,11 @@ def build_map(name, map_size):

destination, source, range = string_to_int_list(line)
# print(destination, source, range)
map[source : source + range] = np.arange(destination, destination + range)
map[source: source + range] = np.arange(destination, destination + range)

return map


with open(filename, 'r') as file:
lines = file.readlines()
seeds = get_seeds(lines)
Expand Down Expand Up @@ -129,4 +133,3 @@ def build_map(name, map_size):


print(min(locations))

0 comments on commit f86ad59

Please sign in to comment.