Open main menu

CDOT Wiki β

Changes

Moscow 5

1,742 bytes added, 09:49, 6 December 2012
Assignment 1
== Assignment 1 ==
This is a KenKen puzzle solver Pi calculator that calculates pi up to n digits using a brute force algorithm implementing recursive backtracking to solve a KenKen puzzle. The program creates a possible map of solutions and sequencially substitutes possible valid inputs into the solution map accordingly. When a solution is found to be a failure arctan formula pi=16arctan(1/5)-4arctan(1/239) as the program exits the recursive loop back to main formula along with another variation of the last stable solution and continues with formula based on the solution mapsame method.
<br/>
Source: [[https://github.com/thlmille/KenKenSolver KenKen Solver]]
<br/>
<br/>
The update_possible arctan method:
<big><pre>
// Iterate through solution we have so far, and
// remove possibilities from possible mapvoid arctan(int multiplier, int denom, int sign){ INDEXER x; LONG remain, temp, divisor, denom2; SHORT NotZero = 1; INDEXER adv;
void puzzle::update_possible for (x = 0; x < size; x++) { powers[x] = 0;
for divisor = 1; denom2 = (int i LONG)denom;denom2 *= 1denom2; i < adv = this->size0; ++i) {
remain = (LONG)multiplier * denom; while (NotZero) { for (int j x = 1adv; j x <= this->size; x++j) { temp = (LONG)powers[x] + remain; powers[x] = (SHORT)(temp / denom2); remain = (temp - (denom2 * (LONG)powers[x])) * BASE; }
if remain = 0; for (this->solutionx = adv; x < size; x++) { temp = (LONG)powers[x] + remain; term[ix]= (SHORT)(temp / divisor); remain = (temp - (divisor * (LONG)term[jx] !)) * BASE; } remain = 0) {;
this- if (sign >possible[make_pair(i0) { LONG carry, j)].clear()sum;
int taken carry = this0; for (x = size -1; x >solution=0; x--) { sum = (LONG)pi[x] + (LONG)term[ix]+ carry; carry = 0; if (sum >= BASE) { carry = 1; sum -= BASE; } pi[jx]= (SHORT)sum; } } else { LONG borrow, sum;
update_possible_row borrow = 0; for (x = size - 1; x >= 0; x--) { sum = (LONG)pi[x] - (LONG)term[x] - borrow; borrow = 0; if (sum < 0) { borrow = 1; sum += BASE; } pi[x] = (taken, iSHORT)sum; } }
update_possible_column sign = -sign; divisor += 2; NotZero = 0; for (x = adv; x < size; x++) { if (taken, jpowers[x]) { NotZero = 1; break; } }
if (NotZero)
{
while (powers[adv] == 0)
adv++;
}
/* We can skip ones that are already 0 */
}
 
}
 
}
 
}