-
Notifications
You must be signed in to change notification settings - Fork 0
/
sudoku_loader.py
31 lines (23 loc) · 987 Bytes
/
sudoku_loader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from puzzle import Puzzle
import csv
class SudokuLoader:
def __init__(self):
self.puzzle = []
self.__solution = []
self.__puzzle_strings = []
self.__solution_strings = []
with open('puzzles/sudoku.csv', newline='') as csvfile:
reader = csv.reader(csvfile, delimiter=",")
next(reader)
for row in reader:
self.__puzzle_strings.append(row[0])
self.__solution_strings.append(row[1])
self.puzzle_count = len(self.__puzzle_strings)
def load(self, puzzle_index, solve_set) -> (Puzzle, Puzzle):
puzzle = Puzzle(self.__puzzle_strings[puzzle_index], solve_set)
solution = Puzzle(self.__solution_strings[puzzle_index])
return puzzle, solution
def get_strings(self, limit: int = -1):
if limit == -1:
limit = len(self.__puzzle_strings)
return zip(self.__puzzle_strings[0:limit], self.__solution_strings[0:limit])