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|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": [
|
9 |
+
"import numpy as np\n",
|
10 |
+
"import pandas as pd"
|
11 |
+
]
|
12 |
+
},
|
13 |
+
{
|
14 |
+
"cell_type": "code",
|
15 |
+
"execution_count": 2,
|
16 |
+
"metadata": {},
|
17 |
+
"outputs": [],
|
18 |
+
"source": [
|
19 |
+
"new_data = pd.read_csv(\"sudoku-3m.csv\")"
|
20 |
+
]
|
21 |
+
},
|
22 |
+
{
|
23 |
+
"cell_type": "code",
|
24 |
+
"execution_count": 3,
|
25 |
+
"metadata": {},
|
26 |
+
"outputs": [
|
27 |
+
{
|
28 |
+
"data": {
|
29 |
+
"text/html": [
|
30 |
+
"<div>\n",
|
31 |
+
"<style scoped>\n",
|
32 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
33 |
+
" vertical-align: middle;\n",
|
34 |
+
" }\n",
|
35 |
+
"\n",
|
36 |
+
" .dataframe tbody tr th {\n",
|
37 |
+
" vertical-align: top;\n",
|
38 |
+
" }\n",
|
39 |
+
"\n",
|
40 |
+
" .dataframe thead th {\n",
|
41 |
+
" text-align: right;\n",
|
42 |
+
" }\n",
|
43 |
+
"</style>\n",
|
44 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
45 |
+
" <thead>\n",
|
46 |
+
" <tr style=\"text-align: right;\">\n",
|
47 |
+
" <th></th>\n",
|
48 |
+
" <th>id</th>\n",
|
49 |
+
" <th>puzzle</th>\n",
|
50 |
+
" <th>solution</th>\n",
|
51 |
+
" <th>clues</th>\n",
|
52 |
+
" <th>difficulty</th>\n",
|
53 |
+
" </tr>\n",
|
54 |
+
" </thead>\n",
|
55 |
+
" <tbody>\n",
|
56 |
+
" <tr>\n",
|
57 |
+
" <th>0</th>\n",
|
58 |
+
" <td>1</td>\n",
|
59 |
+
" <td>1..5.37..6.3..8.9......98...1.......8761.........</td>\n",
|
60 |
+
" <td>1985437266432785915276198439147352688761924352...</td>\n",
|
61 |
+
" <td>27</td>\n",
|
62 |
+
" <td>2.2</td>\n",
|
63 |
+
" </tr>\n",
|
64 |
+
" <tr>\n",
|
65 |
+
" <th>1</th>\n",
|
66 |
+
" <td>2</td>\n",
|
67 |
+
" <td>...81.....2........1.9..7...7..25.934.2..........</td>\n",
|
68 |
+
" <td>9348172567286534196159427381764258934523981673...</td>\n",
|
69 |
+
" <td>23</td>\n",
|
70 |
+
" <td>0.0</td>\n",
|
71 |
+
" </tr>\n",
|
72 |
+
" <tr>\n",
|
73 |
+
" <th>2</th>\n",
|
74 |
+
" <td>3</td>\n",
|
75 |
+
" <td>..5...74.3..6...19.....1..5...7...2.9....58..7...</td>\n",
|
76 |
+
" <td>2159837463876542194692713855387169249413258677...</td>\n",
|
77 |
+
" <td>25</td>\n",
|
78 |
+
" <td>2.6</td>\n",
|
79 |
+
" </tr>\n",
|
80 |
+
" <tr>\n",
|
81 |
+
" <th>3</th>\n",
|
82 |
+
" <td>4</td>\n",
|
83 |
+
" <td>........5.2...9....9..2...373..481.....36....5...</td>\n",
|
84 |
+
" <td>4738169256285397411954278637329481569413652785...</td>\n",
|
85 |
+
" <td>26</td>\n",
|
86 |
+
" <td>1.4</td>\n",
|
87 |
+
" </tr>\n",
|
88 |
+
" <tr>\n",
|
89 |
+
" <th>4</th>\n",
|
90 |
+
" <td>5</td>\n",
|
91 |
+
" <td>.4.1..............653.....1.8.9..74...24..91.....</td>\n",
|
92 |
+
" <td>9471536821286493576532874913819267455724389164...</td>\n",
|
93 |
+
" <td>25</td>\n",
|
94 |
+
" <td>1.1</td>\n",
|
95 |
+
" </tr>\n",
|
96 |
+
" </tbody>\n",
|
97 |
+
"</table>\n",
|
98 |
+
"</div>"
|
99 |
+
],
|
100 |
+
"text/plain": [
|
101 |
+
" id puzzle \\\n",
|
102 |
+
"0 1 1..5.37..6.3..8.9......98...1.......8761......... \n",
|
103 |
+
"1 2 ...81.....2........1.9..7...7..25.934.2.......... \n",
|
104 |
+
"2 3 ..5...74.3..6...19.....1..5...7...2.9....58..7... \n",
|
105 |
+
"3 4 ........5.2...9....9..2...373..481.....36....5... \n",
|
106 |
+
"4 5 .4.1..............653.....1.8.9..74...24..91..... \n",
|
107 |
+
"\n",
|
108 |
+
" solution clues difficulty \n",
|
109 |
+
"0 1985437266432785915276198439147352688761924352... 27 2.2 \n",
|
110 |
+
"1 9348172567286534196159427381764258934523981673... 23 0.0 \n",
|
111 |
+
"2 2159837463876542194692713855387169249413258677... 25 2.6 \n",
|
112 |
+
"3 4738169256285397411954278637329481569413652785... 26 1.4 \n",
|
113 |
+
"4 9471536821286493576532874913819267455724389164... 25 1.1 "
|
114 |
+
]
|
115 |
+
},
|
116 |
+
"execution_count": 3,
|
117 |
+
"metadata": {},
|
118 |
+
"output_type": "execute_result"
|
119 |
+
}
|
120 |
+
],
|
121 |
+
"source": [
|
122 |
+
"new_data.head()"
|
123 |
+
]
|
124 |
+
},
|
125 |
+
{
|
126 |
+
"cell_type": "code",
|
127 |
+
"execution_count": 4,
|
128 |
+
"metadata": {},
|
129 |
+
"outputs": [],
|
130 |
+
"source": [
|
131 |
+
"new_data['puzzle'] = new_data['puzzle'].apply(lambda x: x.replace('.','0'))"
|
132 |
+
]
|
133 |
+
},
|
134 |
+
{
|
135 |
+
"cell_type": "code",
|
136 |
+
"execution_count": 5,
|
137 |
+
"metadata": {},
|
138 |
+
"outputs": [],
|
139 |
+
"source": [
|
140 |
+
"quizzes = []\n",
|
141 |
+
"solutions = []\n",
|
142 |
+
"for idx, row in new_data.iterrows():\n",
|
143 |
+
" quizz = row[\"puzzle\"]\n",
|
144 |
+
" solution = row[\"solution\"]\n",
|
145 |
+
" quizzes.append(np.array([int(x) for x in quizz],).reshape(9,9).astype(np.uint8))\n",
|
146 |
+
" solutions.append(np.array([int(x) for x in solution]).reshape(9,9).astype(np.uint8))\n"
|
147 |
+
]
|
148 |
+
},
|
149 |
+
{
|
150 |
+
"cell_type": "code",
|
151 |
+
"execution_count": 6,
|
152 |
+
"metadata": {},
|
153 |
+
"outputs": [
|
154 |
+
{
|
155 |
+
"data": {
|
156 |
+
"text/plain": [
|
157 |
+
"((3000000, 9, 9), (3000000, 9, 9))"
|
158 |
+
]
|
159 |
+
},
|
160 |
+
"execution_count": 6,
|
161 |
+
"metadata": {},
|
162 |
+
"output_type": "execute_result"
|
163 |
+
}
|
164 |
+
],
|
165 |
+
"source": [
|
166 |
+
"quizzes = np.stack(quizzes)\n",
|
167 |
+
"solutions = np.stack(solutions)\n",
|
168 |
+
"quizzes.shape, solutions.shape"
|
169 |
+
]
|
170 |
+
},
|
171 |
+
{
|
172 |
+
"cell_type": "code",
|
173 |
+
"execution_count": 7,
|
174 |
+
"metadata": {},
|
175 |
+
"outputs": [],
|
176 |
+
"source": [
|
177 |
+
"sol = np.zeros((solutions.shape[0],2,9,9,9), dtype=np.uint8)\n",
|
178 |
+
"quizz = np.zeros((solutions.shape[0],2,9,9,9), dtype=np.uint8)\n",
|
179 |
+
"for i in range(9):\n",
|
180 |
+
" sol[:,1,:,:,i] = (solutions==i+1).astype(np.uint8)\n",
|
181 |
+
" sol[:,0,:,:,i] = ((solutions!=i+1) & (solutions!=0)).astype(np.uint8)\n",
|
182 |
+
" quizz[:,1,:,:,i] = (quizzes==i+1).astype(np.uint8)\n",
|
183 |
+
" quizz[:,0,:,:,i] = ((quizzes!=i+1) & (quizzes!=0)).astype(np.uint8)\n",
|
184 |
+
" \n",
|
185 |
+
"np.savez(\"sudoku_reshaped_3_million.npz\",quizzes=quizz[:1000000],solutions=sol[:1000000])"
|
186 |
+
]
|
187 |
+
},
|
188 |
+
{
|
189 |
+
"cell_type": "code",
|
190 |
+
"execution_count": null,
|
191 |
+
"metadata": {},
|
192 |
+
"outputs": [],
|
193 |
+
"source": []
|
194 |
+
}
|
195 |
+
],
|
196 |
+
"metadata": {
|
197 |
+
"kernelspec": {
|
198 |
+
"display_name": "Python 3 (ipykernel)",
|
199 |
+
"language": "python",
|
200 |
+
"name": "python3"
|
201 |
+
},
|
202 |
+
"language_info": {
|
203 |
+
"codemirror_mode": {
|
204 |
+
"name": "ipython",
|
205 |
+
"version": 3
|
206 |
+
},
|
207 |
+
"file_extension": ".py",
|
208 |
+
"mimetype": "text/x-python",
|
209 |
+
"name": "python",
|
210 |
+
"nbconvert_exporter": "python",
|
211 |
+
"pygments_lexer": "ipython3",
|
212 |
+
"version": "3.10.4"
|
213 |
+
},
|
214 |
+
"toc": {
|
215 |
+
"base_numbering": 1,
|
216 |
+
"nav_menu": {},
|
217 |
+
"number_sections": true,
|
218 |
+
"sideBar": true,
|
219 |
+
"skip_h1_title": false,
|
220 |
+
"title_cell": "Table of Contents",
|
221 |
+
"title_sidebar": "Contents",
|
222 |
+
"toc_cell": false,
|
223 |
+
"toc_position": {},
|
224 |
+
"toc_section_display": true,
|
225 |
+
"toc_window_display": false
|
226 |
+
}
|
227 |
+
},
|
228 |
+
"nbformat": 4,
|
229 |
+
"nbformat_minor": 4
|
230 |
+
}
|