Module TTally :: Class Possibilities
[hide private]
[frames] | no frames]

Class Possibilities

source code

A set of possible "answers" to a summation.

Instance Methods [hide private]
 
__init__(self, value, accept=False)
Create an Possibilities node with the given value.
source code
 
__getitem__(self, idx)
Return the Possibilities tree with idx as least-significant digit, or None if there is no such tree.
source code
 
__contains__(self, v)
Return True if the least-significant digit 'v' can lead to an accepting state.
source code
 
__str__(self)
Return a human-readable representation of the numbers accepted by this Possibilities object.
source code
 
__repr__(self) source code
 
__len__(self) source code
 
__hash__(self) source code
 
__eq__(self, other)
Return True iff the objects are reference-equal.
source code
 
add(self, num, mul=1)
Return a new Possibilities object which can accept the given number.
source code
 
_value(self)
Special accessor to handle special case value of root node.
source code
 
reset(self)
Count the number of accepting states and reset the 'na' field.
source code
Static Methods [hide private]
 
create(nums) source code
Instance Variables [hide private]
  value
The number associated with this node.
  leaves
Possibilities nodes corresponding to the 10 possible significant digits which could be accepted by this node.
  accept
Whether this node is an "accepting state".
  na
The number of accepting states in this node and child nodes.
Method Details [hide private]

__eq__(self, other)
(Equality operator)

source code 

Return True iff the objects are reference-equal. This is a very strict notion of equality! For example:

>>> a = Possibilities.create([1,2,3])
>>> b = Possibilities.create([1,2,3])
>>> a == a
True
>>> a == b
False

add(self, num, mul=1)

source code 

Return a new Possibilities object which can accept the given number. Returns 1 if the number was not previously accepted, else 0. For example:

>>> p = Possibilities.create([42])
>>> p.add(534)
1
>>> p.na
2
>>> p.add(534)
0
>>> p.na
2

Instance Variable Details [hide private]

value

The number associated with this node. This is the number which would be accepted by this node, if it were an accepting state, or -1 for the root node.

accept

Whether this node is an "accepting state". For example, the Possibilities object corresponding to the set [51,61] has an internal node with the value '1' which is not an accepting state, since the number 1 is not in the set.