E2GRuleWriter
Transcript of E2GRuleWriter
-
8/10/2019 E2GRuleWriter
1/4
//Joshua Major#include
#include
// Description of program
/*
This program takes a list of numbers thro! it in a number vector" used another vector to check if thesum of each set of $ numbers are prime
if the% are the% belong in a candidate vector" n the input the $ numbers are the boundar% values"
&ased on the ' functions havethe program !ill use backtracking check to see if there is a prime se(uence using ever% number
bet!een the first input value and the second" f there is print
it out if not sa% that )no prim se(uence eists)"*/
// Description of data stucture used/*
used lists/vectors to implement m% program" didn+t use arra%s/matrices because +m not that familiar!ith them" ,sing a graph
data structure !ould be too complicated because graph can have more than one nodes from anothernode" This program just involves
lists of numbers from one number to another"
*/// -valuation
/*
technicall% did this alone even though got help from the teacher" believe did a good jobconsidering get the right output"
*/
using namespace std.bool srime0int number1.bool backtrack0vector numbers vector candidatesint number1.
void print0vectornumbers1.
bool find0vectornumbersint value1.bool legal0vector numbers vector candidatesint nnde1.
int main012
-
8/10/2019 E2GRuleWriter
2/4
int number3number$.
vector numbers.
vectorcandidates.
bool found 4 true. cin>>number3>>number$.
!hile 0number3546 77 number$ 5461 2
for0int i 4 number3. i
-
8/10/2019 E2GRuleWriter
3/4
print0candidates1.
return true.
else 2
for0int j 4 6. j < numbers"si@e01. j881
2 if 0legal0numbers candidates j11
2
candidates"push9back0numbersAjB1. if05backtrack0numberscandidatesi8311
candidates"pop9back01.
else2
return true.
return false.
void print0vectornumbers12
/*
post=condition prints the numbers vector
*/ for0int i 4 6. i < numbers"si@e01. i881
cout
-
8/10/2019 E2GRuleWriter
4/4
candidates and if the number+s
alread% found
*/
if0candidates"empt%011 return true.
else if0find0candidatesnumbersAnndeB11
return false.else
return srime0candidates"back01 8 numbersAnndeB1.