func (p PotentialPositions) Collapse() map[*TicketField]int {
	collapsedPositions := map[*TicketField]int{}

	var current, next *TicketField
	for i := 0; i < len(p); i++ {
		if current == nil {
			for field, positions := range p {
				if len(positions) == 1 {
					// start collapse here
					current = field
				}
			}
		}

		collapsedPositions[current] = p[current][0]
		for field := range p {
			// collapse: remove current position from list of possibilities
			p[field] = filterOut(p[field], collapsedPositions[current])

			if len(p[field]) == 1 {
				next = field // found next field to collapse
			}
		}

		current = next
		next = nil
	}

	return collapsedPositions
}
// Collapse tries to collapse all potential positions in this list into a single
// possibility per field. For this algorithm to work, the following conditions must
// be met:
//
//   - Each field must map to a unique number of potential positions
//   - There must be exactly one field with only 1 possible position and one with
//     all possible positions (e.g. fieldN=0..N, field0=<single value>)
//   - A field with N positions must contain all the same possibilities as the one
//     with N-1 positions, plus one new possibility (e.g. field3=>0,3,5, field2=>0,5,
//     field1=>5)
Collapse tries to collapse all potential positions in this list into a single
possibility per field. For this algorithm to work, the following conditions must
be met.

- Each field must map to a unique number of potential positions
- There must be exactly one field with only 1 possible position and one with
all possible positions
- A field with N positions must contain all the same possibilities as the one
with N-1 positions, plus one new possibility
// Collapse tries to collapse all potential positions in this list into a single // possibility per field . For this algorithm to work the following conditions must // be met : // // - Each field must map to a unique number of potential positions // - There must be exactly one field with only 1 possible position and one with // all possible positions ( e . g . fieldN = 0 .. N field0 = <single value > ) // - A field with N positions must contain all the same possibilities as the one // with N - 1 positions plus one new possibility ( e . g . field3 = > 0 3 5 field2 = > 0 5 // field1 = > 5 )
func (p PotentialPositions) Collapse() map[*TicketField]int {
	collapsedPositions := map[*TicketField]int{}
	var current, next *TicketField
	for i := 0; i < len(p); i++ {
		if current == nil {
			for field, positions := range p {
				if len(positions) == 1 {
					current = field
				}
			}
		}
		collapsedPositions[current] = p[current][0]
		for field := range p {
			p[field] = filterOut(p[field], collapsedPositions[current])
			if len(p[field]) == 1 {
				next = field 
			}
		}
		current = next
		next = nil
	}
	return collapsedPositions
}
func ( p PotentialPositions ) Collapse ( ) map [ * TicketField ] int { collapsedPositions := map [ * TicketField ] int { } var current , next * TicketField for i := 0 ; i < len ( p ) ; i ++ { if current == nil { for field , positions := range p { if len ( positions ) == 1 { current = field } } } collapsedPositions [ current ] = p [ current ] [ 0 ] for field := range p { p [ field ] = filterOut ( p [ field ] , collapsedPositions [ current ] ) if len ( p [ field ] ) == 1 { next = field } } current = next next = nil } return collapsedPositions }
Collapse tries to collapse all potential positions in this list into a single
possibility per field.
Collapse tries to collapse all potential positions in this list into a single possibility per field .
// start collapse here // collapse: remove current position from list of possibilities // found next field to collapse