Rod

Note

A tower that contains Disks.

class towers.core.rod.Rod[source]

A single tower containing disks.

__bool__()[source]

A Rod is considered True if it contains any disks.

Return type:bool
__copy__()[source]

Return a shallow copy of this instance.

Return type:Rod
__deepcopy__(*d)[source]

Return a deep copy of this instance.

Parameters:d (dict) – Memoisation dict.
Return type:Rod
__eq__(other)[source]

Compare Rod instances for equivalence.

Parameters:other (Rod) –
Return type:bool
__iter__()[source]

Iterate over all the disks in this rod.

Return type:Disk
static __new__(name, disks=None, height=0)[source]
Parameters:
  • name (str) – The name of the rod.
  • disks (List[Disk]) – (optional) mutatable list of Disks.
  • height (int) – The height of the rod.
Return type:

Rod

Raises:

See Rod.validate.

__nonzero__()[source]

A Rod is considered non-zero if it contains any disks.

Return type:bool
append(disk, validate=True)[source]

Append the disk to this rod and optionally validate.

Parameters:
  • disk (Disk) – The disk to add to the top of our rod.
  • validate (bool) – True=perform self validation.
classmethod from_json(d)[source]

Return a class instance from a json serializable representation.

Parameters:d (Union[str,dict]) – The json or decoded-json from which to create a new instance.
Return type:Rod
Raises:See Rod.__new__.
pop()[source]

Pop the top most disk from this rod and return it

Return type:Disk
to_json()[source]

Return a json serializable representation of this instance.

Return type:object
validate()[source]

Perform self validation.

Raises: