--- title: PR-Quiz3 tags: Germany --- [https://hackmd.io/@wolfzxcv/ByGjDvdUp](https://hackmd.io/@wolfzxcv/ByGjDvdUp) ## 1. a. 1324421 b. 2751421 Becomes a. 1351421 b. 2724421 ## 2. ```javascript function cal(a, b, c, d, e, f, g, h) { return a + b - (c + d) + (e + f) - (g + h); } console.log(cal(6, 5, 4, 1, 3, 5, 3, 2)); // 9 console.log(cal(8, 7, 1, 2, 6, 6, 0, 1)); //23 console.log(cal(2, 3, 9, 2, 1, 2, 8, 5)); //-16 console.log(cal(4, 1, 8, 5, 2, 0, 9, 4)); //-19 ``` f(x) = (a + b) − (c + d) + (e + f) − (g + h) x1 = (6 5 4 1 3 5 3 2) f(x1) = 9 x2 = (8 7 1 2 6 6 0 1) f(x2) = 23 x3 = (2 3 9 2 1 2 8 5) f(x3) = -16 x4 = (4 1 8 5 2 0 9 4) f(x4) = -19 a) x2 > x1 > x3 > x4 b) Cross the fittest two individuals using one–point crossover at the middle point. i) * In order to get better value, we have to minus smaller number and add bigger number, which means **c, d, g, h to be smaller, a, b, e,f to be bigger** uniform crossover H=1 change, H=0 not change ==single point== x1 = (6 5 4 1 3 5 3 2) x2 = (8 7 1 2 6 6 0 1) H = 1 0 1 0 offspring: off1 = 6 5 1 1 6 5 3 2 0ff2 = 8 7 4 2 3 6 0 1 --- ==double points== x1 = (6 5 4 1 3 5 3 2) x2 = (8 7 1 2 6 6 0 1) H = 1 0 1 0 off3 = 8 5 4 1 3 5 0 2 off4 = 6 5 1 2 6 6 3 0 ii) ```javascript function cal(a, b, c, d, e, f, g, h) { return a + b - (c + d) + (e + f) - (g + h); } console.log(cal(6, 5, 1, 1, 6, 5, 3, 2)); //15 console.log(cal(8, 7, 4, 2, 3, 6, 0, 1)); //17 console.log(cal(8, 5, 4, 1, 3, 5, 0, 2)); //14 console.log(cal(6, 5, 1, 2, 6, 6, 3, 0)); //17 ```