Project Euler Homework
|
00001 00010 #include <set> 00011 #include "032_perm032.h" 00012 #include "032_times_minus.h" 00013 00014 unsigned 00015 sum (set < int >&numbers) 00016 { 00017 unsigned sum = 0; 00018 for (set < int >::iterator p = numbers.begin (); p != numbers.end (); p++) 00019 sum += *p; 00020 return sum; 00021 } 00022 00023 int 00024 main () 00025 { 00026 perm032 trials (9); 00027 set < int >pandigital; 00028 do 00029 { 00030 times_minus expression (trials); 00031 do 00032 { 00033 if (expression.isZero ()) 00034 { 00035 pandigital.insert (expression.getProduct ()); 00036 00037 /* Debug 00038 cout << '*'; 00039 trials.print_perm (); 00040 cout << '\t'; 00041 expression.printExpr (); */ 00042 } 00043 } 00044 while (expression.next_opr_pos ()); 00045 } 00046 while (trials.next ()); 00047 00048 //cout << "Count: " << pandigital.size()<< endl; 00049 cout << sum (pandigital) << endl; 00050 00051 return 0; 00052 }