diff --git a/8_puzzle.py b/8_puzzle.py index 850f6b768d5..7c6fc858d36 100644 --- a/8_puzzle.py +++ b/8_puzzle.py @@ -26,15 +26,20 @@ def priority(self) -> int: return self.moves + self.manhattan() def manhattan(self) -> int: - """Calculate Manhattan distance from current to goal state.""" + """Calculate Manhattan distance using actual goal positions.""" distance = 0 + # Create a lookup table for goal tile positions + goal_pos = {self.goal[i][j]: (i, j) for i in range(3) for j in range(3)} + for i in range(3): for j in range(3): - if self.board[i][j] != 0: - x, y = divmod(self.board[i][j] - 1, 3) + value = self.board[i][j] + if value != 0: # skip the empty tile + x, y = goal_pos[value] distance += abs(x - i) + abs(y - j) return distance + def is_goal(self) -> bool: """Check if current state matches goal.""" return self.board == self.goal diff --git a/PongPong_Game/requirements.txt b/PongPong_Game/requirements.txt index ccf1333682a..dd0262c9c5a 100644 --- a/PongPong_Game/requirements.txt +++ b/PongPong_Game/requirements.txt @@ -1 +1 @@ -pyglet==2.1.9 +pyglet==2.1.11 diff --git a/remoteok_jobs_scraper/remoteok_jobs.py b/remoteok_jobs_scraper/remoteok_jobs.py new file mode 100644 index 00000000000..9c624748193 --- /dev/null +++ b/remoteok_jobs_scraper/remoteok_jobs.py @@ -0,0 +1,45 @@ +import requests +import xlwt +from xlwt import Workbook + +BASE_URL = 'https://remoteok.com/api' +USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36' +REQUEST_HEADER = { + 'User-Agent': USER_AGENT, + 'Accept-Language': 'en-US, en;q=0.5', +} + +def get_job_postings(): + """Fetch job postings from RemoteOK API.""" + try: + res = requests.get(BASE_URL, headers=REQUEST_HEADER) + res.raise_for_status() + data = res.json() + return data[1:] + except requests.RequestException as e: + print("Error fetching jobs:", e) + return [] + +def save_jobs_to_excel(jobs, filename='remoteok_jobs.xls'): + """Save job postings to an Excel file.""" + if not jobs: + print("No job data to save.") + return + + wb = Workbook() + sheet = wb.add_sheet('Jobs') + + headers = list(jobs[0].keys()) + for col, header in enumerate(headers): + sheet.write(0, col, header) + + for row, job in enumerate(jobs, start=1): + for col, key in enumerate(headers): + sheet.write(row, col, str(job.get(key, ''))) + + wb.save(filename) + print(f"Jobs saved to {filename}") + +if __name__ == '__main__': + jobs = get_job_postings() + save_jobs_to_excel(jobs) diff --git a/requirements_with_versions.txt b/requirements_with_versions.txt index 008f4475fd9..855f67995bf 100644 --- a/requirements_with_versions.txt +++ b/requirements_with_versions.txt @@ -55,7 +55,7 @@ pydantic==2.12.4 openpyxl==3.1.2 pytesseract==0.3.13 requests-mock==1.12.1 -pyglet==2.1.9 +pyglet==2.1.11 urllib3==2.5.0 thirdai==0.9.33 google-api-python-client==2.187.0