This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
192.168.0.13 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install TensorFlow | |
import tensorflow as tf | |
# Load and prepare the MNIST dataset. | |
# Convert the samples from integers to floating-point numbers: | |
mnist = tf.keras.datasets.mnist | |
(x_train, y_train), (x_test, y_test) = mnist.load_data() | |
x_train, x_test = x_train / 255.0, x_test / 255.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Dict, List, Tuple | |
from copy import deepcopy | |
Matrix = List[List[int]] | |
def move_empty_tile(matrix: Matrix, empty_tile: Tuple[int, int], new_empty_tile: Tuple[int, int]) -> Matrix: | |
row, col = empty_tile | |
new_row, new_col = new_empty_tile | |
new_matrix = deepcopy(matrix) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_adjacent_matrices(matrix: Matrix, empty_tile: Tuple[int, int] = None) -> List[Matrix]: | |
def find_empty_tile(matrix): | |
for i in range(len(matrix)): | |
for j in range(len(matrix[i])): | |
if matrix[i][j] == 0: | |
return (i, j) | |
if empty_tile is None: | |
empty_tile = find_empty_tile(matrix) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Callable, Tuple | |
from copy import deepcopy | |
from dataclasses import dataclass, field | |
from typing import Dict, List, Tuple | |
from copy import deepcopy | |
import heapq | |
@dataclass | |
class Node: | |
matrix: Matrix |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def a_star(initial_state: Matrix, end_state: Matrix, heuristic: Callable[[Matrix, Matrix], int] = uniform_cost) -> Node: | |
def convert_to_nodes(matrices: List[Matrix]): | |
neighbors = [] | |
for m in matrices: | |
key = str(m) | |
if key not in graph: | |
graph[key] = Node(m, cost=heuristic(m, end_state)) | |
neighbors.append(graph[key]) | |
return neighbors |