COG 366 Assignment 17 Part 1: Heuristics Document

Heuristic 1
1. Number/Name - H1/Zeros
2. English - If the goal is zero and zero is among the numbers, then multiply all of the
numbers together.
3. Pseudocode - If ( the goal is zero ) and ( zero is among the numbers ) then [ multiply the
numbers together ]
4. Examples
    1. Numbers = { 5, 4, 0, 8, 9 } Goal = 0
    Solution = ( 5 * ( 4 * ( 0 * ( 8 * 9 ) ) ) )
    2. Numbers = { 0, 5, 3, 5, 8 } Goal = 0
    Solution = ( 0 * ( 5 * ( 3 * ( 5 * 8 ) ) ) )
    3. Numbers = { 7, 6, 7, 1, 0 } Goal = 0
    Solution = ( 7 * ( 6 * ( 7 * ( 1 * 0 ) ) ) )

Heuristic 2
1. Number/Name - H2/Zero and Goal
2. English - If the goal is nonzero and zero and the goal are among the numbers, then add
the goal to the result of multiply all of the remaining numbers together.
3. Pseudocode - If ( the goal is not zero ) and ( zero is among the numbers ) and ( the goal is
among the numbers ) then [ add the goal to the product of the remaining numbers ]
4. Examples
    1. Numbers = { 7, 0, 9, 2, 6 } Goal = 9
    Solution = ( 9 + ( 7 * ( 0 * ( 2 * 6 ) ) ) )
    2. Numbers = { 5, 4, 3, 1, 0 } Goal = 4
    Solution = ( 4 + ( 5 * ( 3 * ( 1 * 0 ) ) ) )
    3. Numbers = { 0, 2, 3, 5, 3 } Goal = 3
    Solution = ( 3 + ( 0 * ( 2 * ( 3 * 5 ) ) ) )

Heuristic 3
1. Number/Name - H3/Zero Goal and Pair
2. English - If the goal is zero and a pair exists among the numbers, then multiply the
difference between the pair of numbers by all of the remaining numbers.
3. Pseudocode - If ( the goal is zero ) and ( a pair exists among the numbers ) then [ multiply
the difference between the pair of numbers by all of the remaining numbers ]
4. Examples
    1. Numbers = { 4, 5, 6, 4, 9 } Goal = 0
    Solution = ( ( 4 - 4 ) * ( 5 * ( 6 * 9 ) ) )
    2. Numbers = { 5, 0, 6, 0, 7 } Goal = 0
    Solution = ( ( 0 - 0 ) * ( 5 * ( 6 * 7 ) ) )
    3. Numbers = { 1, 0, 1, 2, 3 } Goal = 0
    Solution = ( ( 1 - 1 ) * ( 0 * ( 2 * 3 ) ) )

Heuristic 4
1. Number/Name - H4/Same Goal and Numbers
2. English - If all of the numbers in the set of numbers are the same as the goal number, then
add one of those numbers to the differences of both remaining pairs.
3. Pseudocode - If ( each number is equal to the next ) and ( the goal is also that same
number ) then [ add one number to the sum of the differences between the two remaining
pairs ]
4. Examples
    1. Numbers = { 3, 3, 3, 3, 3 } Goal = 3
    Solution = ( 3 + ( ( 3 - 3 ) + ( 3 - 3 ) ) )
    2. Numbers = { 5, 5, 5, 5, 5 } Goal = 5
    Solution = ( 5 + ( ( 5 - 5 ) + ( 5 - 5 ) ) )
    3. Numbers = { 7, 7, 7, 7, 7 } Goal = 7
    Solution = ( 7 + ( ( 7 - 7 ) + ( 7 - 7 ) ) )

Heuristic 5
1. Number/Name - H5/Pairs Plus Two
2. English - If there is a pair of ones, a pair of any number, and a number whose value is
two less than that of the goal, then add the sum of the pair of ones to the non-pair number
and add the difference of the remaining pair.
3. Pseudocode - If ( two of the numbers are one ) and ( two of the remaining numbers form
a pair ) and ( the remaining number is two less than the goal ) then [ add the sum of the
pair of ones and the non-pair number to the difference of the of the remaining pair ]
4. Examples
    1. Numbers = { 1, 3, 1, 3, 5 } Goal = 7
    Solution = ( ( ( 1 + 1 ) + 5 ) + ( 3 - 3 ) )
    2. Numbers = { 5, 1, 7, 1, 5 } Goal = 9
    Solution = ( ( ( 1 + 1 ) + 7 ) + ( 5 - 5 ) )
    3. Numbers = { 4, 4, 6, 1, 1 } Goal = 8
    Solution = ( ( ( 1 + 1 ) + 6 ) + ( 4 - 4 ) )

Heuristic 6
1. Number/Name - H6/Two Adjacents and Goal
2. English - If there are two pairs of adjacent numbers and the goal number is in the set of
numbers, then multiply the goal number by the product of the differences of both
adjacent pairs such that their differences equal one.
3. Pseudocode - If ( two numbers are adjacent ) and ( another two numbers are adjacent )
and ( the goal is among the numbers ) then [ multiply the goal number by the product of
the differences of the adjacent numbers ]
4. Examples
    1. Numbers = { 3, 4, 7, 6, 2 } Goal = 2
    Solution = ( ( ( 4 - 3 ) * ( 7 - 6 ) ) * 2 )
    2. Numbers = { 1, 2, 8, 3, 7 } Goal = 3
    Solution = ( ( ( 2 - 1 ) * ( 8 - 7 ) ) * 3 )
    3. Numbers = { 6, 3, 9, 4, 8 } Goal = 6
    Solution = ( ( ( 4 - 3 ) * ( 9 - 8 ) ) * 6 )

Heuristic 7
1. Number/Name - H7/Two Pairs and Goal of One
2. English - If there are two pairs among the numbers and a goal of one, then add the
quotient of one of the pairs to the product of the difference of the other pair and the
remaining number.
3. Pseudocode - If ( a pair is among the numbers ) and ( another pair is present among the
numbers ) and ( the goal is one ) then [ add the quotient of one of the pairs to the product
of the difference of the other pair and the remaining number ]
4. Examples
    1. Numbers = { 1, 6, 3, 1, 3 } Goal = 1
    Solution = ( ( ( 3 - 3 ) * 6 ) + ( 1 / 1 ) )
    2. Numbers = { 8, 7, 2, 7, 8 } Goal = 1
    Solution = ( ( ( 8 - 8 ) * 2 ) + ( 7 / 7 ) )
    3. Numbers = { 6, 6, 4, 4, 9 } Goal = 1
    Solution = ( ( ( 6 - 6 ) * 9 ) + ( 4 / 4 ) )

Heuristic 8
1. Number/Name - H8/Make Zero and Goal
2. English - If the goal number can be calculated from three of the numbers and zero can be
made with the remaining two, then add the expression that produces the goal to the
expression that produces zero.
3. Pseudocode - If ( the goal can be produced from three of the numbers ) and ( zero can be
made from the remaining two ) then [ add the expression that produces the goal to the
expression that produces zero ]
4. Examples
    1. Numbers = { 2, 3, 1, 0, 4 } Goal = 1
    Solution = ( ( 3 / ( 2 + 1 ) ) + ( 0 * 4 ) )
    2. Numbers = { 7, 3, 3, 4, 2 } Goal = 6
    Solution = ( ( ( 7 - 4 ) * 2 ) + ( 3 - 3 ) )
    3. Numbers = { 0, 5, 1, 9, 3 } Goal = 5
    Solution = ( ( 9 - ( 5 - 1 ) ) + ( 0 * 3 ) )