"""
Utility functions and classes for the RushHour project.
"""


class SlottedDefaults(object):
    """Provides default implementation for some methods based on slots."""
    __slots__ = ()

    def __eq__(self, other):
        if self.__class__ != other.__class__:
            return False

        for slot in self.__slots__:
            if getattr(self, slot) != getattr(other, slot):
                return False
        return True

    def __repr__(self):
        return "{}({})".format(self.__class__.__name__, ', '.join(
            repr(getattr(self, slot)) for slot in self.__slots__
        ))

    def __hash__(self):
        return hash(tuple(getattr(self, slot) for slot in self.__slots__))


class TransposedView(object):
    """Represents a transposed view of a list of lists."""

    class _Column(object):
        def __init__(self, grid, idx):
            self._grid = grid
            self._idx = idx

        def __getitem__(self, idx):
            if isinstance(idx, slice):
                return [row[self._idx] for row in self._grid[idx]]
            return self._grid[idx][self._idx]

        def __setitem__(self, idx, val):
            self._grid[idx][self._idx] = val

    def __init__(self, grid):
        self._grid = grid

    def __getitem__(self, idx):
        return self._Column(self._grid, idx)

4bf9895f5128e5cfaa86042909a1df181859c1a3
<mask token>


class TransposedView(object):
    """Represents a transposed view of a list of lists."""


    class _Column(object):

        def __init__(self, grid, idx):
            self._grid = grid
            self._idx = idx

        def __getitem__(self, idx):
            if isinstance(idx, slice):
                return [row[self._idx] for row in self._grid[idx]]
            return self._grid[idx][self._idx]

        def __setitem__(self, idx, val):
            self._grid[idx][self._idx] = val

    def __init__(self, grid):
        self._grid = grid

    def __getitem__(self, idx):
        return self._Column(self._grid, idx)

<mask token>


class SlottedDefaults(object):
    <mask token>
    <mask token>

    def __eq__(self, other):
        if self.__class__ != other.__class__:
            return False
        for slot in self.__slots__:
            if getattr(self, slot) != getattr(other, slot):
                return False
        return True
    <mask token>
    <mask token>


class TransposedView(object):
    """Represents a transposed view of a list of lists."""


    class _Column(object):

        def __init__(self, grid, idx):
            self._grid = grid
            self._idx = idx

        def __getitem__(self, idx):
            if isinstance(idx, slice):
                return [row[self._idx] for row in self._grid[idx]]
            return self._grid[idx][self._idx]

        def __setitem__(self, idx, val):
            self._grid[idx][self._idx] = val

    def __init__(self, grid):
        self._grid = grid

    def __getitem__(self, idx):
        return self._Column(self._grid, idx)

<mask token>


class SlottedDefaults(object):
    <mask token>
    __slots__ = ()

    def __eq__(self, other):
        if self.__class__ != other.__class__:
            return False
        for slot in self.__slots__:
            if getattr(self, slot) != getattr(other, slot):
                return False
        return True

    def __repr__(self):
        return '{}({})'.format(self.__class__.__name__, ', '.join(repr(
            getattr(self, slot)) for slot in self.__slots__))

    def __hash__(self):
        return hash(tuple(getattr(self, slot) for slot in self.__slots__))


class TransposedView(object):
    """Represents a transposed view of a list of lists."""


    class _Column(object):

        def __init__(self, grid, idx):
            self._grid = grid
            self._idx = idx

        def __getitem__(self, idx):
            if isinstance(idx, slice):
                return [row[self._idx] for row in self._grid[idx]]
            return self._grid[idx][self._idx]

        def __setitem__(self, idx, val):
            self._grid[idx][self._idx] = val

    def __init__(self, grid):
        self._grid = grid

    def __getitem__(self, idx):
        return self._Column(self._grid, idx)

<mask token>


class SlottedDefaults(object):
    """Provides default implementation for some methods based on slots."""
    __slots__ = ()

    def __eq__(self, other):
        if self.__class__ != other.__class__:
            return False
        for slot in self.__slots__:
            if getattr(self, slot) != getattr(other, slot):
                return False
        return True

    def __repr__(self):
        return '{}({})'.format(self.__class__.__name__, ', '.join(repr(
            getattr(self, slot)) for slot in self.__slots__))

    def __hash__(self):
        return hash(tuple(getattr(self, slot) for slot in self.__slots__))


class TransposedView(object):
    """Represents a transposed view of a list of lists."""


    class _Column(object):

        def __init__(self, grid, idx):
            self._grid = grid
            self._idx = idx

        def __getitem__(self, idx):
            if isinstance(idx, slice):
                return [row[self._idx] for row in self._grid[idx]]
            return self._grid[idx][self._idx]

        def __setitem__(self, idx, val):
            self._grid[idx][self._idx] = val

    def __init__(self, grid):
        self._grid = grid

    def __getitem__(self, idx):
        return self._Column(self._grid, idx)

"""
Utility functions and classes for the RushHour project.
"""


class SlottedDefaults(object):
    """Provides default implementation for some methods based on slots."""
    __slots__ = ()

    def __eq__(self, other):
        if self.__class__ != other.__class__:
            return False

        for slot in self.__slots__:
            if getattr(self, slot) != getattr(other, slot):
                return False
        return True

    def __repr__(self):
        return "{}({})".format(self.__class__.__name__, ', '.join(
            repr(getattr(self, slot)) for slot in self.__slots__
        ))

    def __hash__(self):
        return hash(tuple(getattr(self, slot) for slot in self.__slots__))


class TransposedView(object):
    """Represents a transposed view of a list of lists."""

    class _Column(object):
        def __init__(self, grid, idx):
            self._grid = grid
            self._idx = idx

        def __getitem__(self, idx):
            if isinstance(idx, slice):
                return [row[self._idx] for row in self._grid[idx]]
            return self._grid[idx][self._idx]

        def __setitem__(self, idx, val):
            self._grid[idx][self._idx] = val

    def __init__(self, grid):
        self._grid = grid

    def __getitem__(self, idx):
        return self._Column(self._grid, idx)
