Disk¶
A disk is a sized element on a Rod where: 1 <= size <= rod_height
-
class
towers.core.disk.
Disk
[source]¶ An immutable representation of a sized disk that sits on a Rod.
-
static
__new__
(cls, original_position, height=1)[source]¶ Parameters: - original_position (int) – The position on the Rod that this disks originally sat. Zero = The bottom of the Rod.
- height (int) – The maximum position of this
Disk
on aRod
.
Return type: Raises: - InvalidTowerHeight – The height of the tower is invalid.
- InvalidDiskPosition – The position of the disk is invalid.
-
classmethod
from_json
(d)[source]¶ Return a class instance from a json serializable representation.
Parameters: d (str|dict) – The json or decoded-json from which to create a new instance. Return type: Disk
Raises: See Disk.__new__
.
-
validate
()[source]¶ Perform self validation
Raises: - InvalidTowerHeight – The height of the tower is invalid.
- InvalidDiskPosition – The position of the disk is invalid.
-
width
¶ Obtain the width of the disk
Return type: int
-
static