9. ProjectEuler.net
"Project Euler exists to encourage, challenge, and develop the skills and enjoyment of anyone with
an interest in the fascinating world of mathematics."
• Project Euler is a series of challenging mathematical/computer
programming problems that requires more than just mathematical
insights to solve.
9
12年6月5日星期二
12. Expectations
Mathematics
So lution implementing
Hig h perfor mance co d ing
So lving problem
ind ivi dually
12
12年6月5日星期二
13. Example: Quick & Dirty
Once you solved a problem, you are entitled to join the forum for this problem.You can
share your solution with the other people who have also solved it. And the post usually
start with this sentence:
Good coding habit?
13
12年6月5日星期二
15. int i, j, k, n, sum;
int factorial[10000];
int* getfactorial(int n)
{
factorial[0] = 1;
k = 0;
for(i = 2; i <= n; i++)
{
• It’s too simple for for(j = 0; j <= k; j++)
factorial[j] *= i;
Java, Ruby or Python, for(j = 0; j <= k; j++)
for which they can {
if(factorial[j] >= 10)
handle big numbers by {
factorial[j+1] += (factorial[j] - (factorial[j] % 10)) / 10;
default. factorial[j] = factorial[j] % 10;
• So let’s look at C/C++. if(j == k)
k++;
• Real code copied from }
}
the forum. }
return factorial;
}
int getsum(int* array, int k)
{
sum = 0;
for(i = 0; i <= k; i++)
sum += array[i];
return sum;
}
int main()
{
int* factorial = getfactorial(n);
sum = getsum(factorial, k);
cout << "nThe sum of the digits of " << n << "! is " << sum << ".n";
return 0;
} 15
12年6月5日星期二
17. Big number again. Ha ha, I did that
before! Let me reuse it...
17
12年6月5日星期二
18. #include<iostream>
using namespace std;
int i, j, k, n, sum;
int factorial[10000];
Why the big number is named ‘factorial’
int* getfactorial(int n)
{ in my previous implementation?
factorial[0] = 1;
k = 0;
for(i = 2; i <= n; i++)
{
for(j = 0; j <= k; j++)
factorial[j] *= i;
for(j = 0; j <= k; j++)
Where’s the code for big number?
{
if(factorial[j] >= 10)
{
factorial[j+1] += (factorial[j] - (factorial[j] % 10)) / 10;
factorial[j] = factorial[j] % 10;
if(j == k)
k++;
}
}
}
return factorial;
}
18
12年6月5日星期二
19. #include <stdio.h>
#define NUMB 120 // 9 * 120 = 1080 total digits.
#define SIZE 1000000000 // 9 digit numbers
int main() {
int i = 0;
int j = 0;
int bigNum1[NUMB];
int bigNum2[NUMB];
int bigNum3[NUMB];
int counter = 0;
for (i = 0; i < NUMB; i++) {
bigNum1 = 0;
bigNum2 = 0;
bigNum3 = 0;
}
bigNum1[0] = 1;
OK, too hard to reuse. It’s not bigNum2[0] = 1;
counter = 2;
that hard to invent the wheel again. i = 0;
while (i == 0) {
counter++;
for (j = 0; j < NUMB; j++) {
bigNum3[j] = bigNum2[j] + bigNum1[j];
}
for (j = 0; j < NUMB-1; j++) {
while (bigNum3[j] >= SIZE) {
bigNum3[j] -= SIZE;
bigNum3[j+1]++;
Design? }
}
if (bigNum3[111] >= 1)
break;
for (j = 0; j < NUMB; j++) {
bigNum1[j] = bigNum2[j];
bigNum2[j] = bigNum3[j];
}
}
printf("n");
printf("P025 answer = %u", counter);
} 19
12年6月5日星期二
20. ing exercises
Problem so lv
tant skills
✓ Train ver y impor
w
as inter vie
✓Often use d
ques tions
i n skills in
✓ Probab ly also tra
n able co de,
maki ng maintai
a little.
•Don’t do it before bed time... 20
12年6月5日星期二
32. Poker Hands in ProjectEuler
• This is not a very hard problem to solve,
comparing to most of the problems listed in
ProjectEuler.net
• But it’s hard to solve it without bugs if you don’t
have unit tests.
• Problem 54 in projectEuler.net
32
12年6月5日星期二
36. Do both exercises.
Alone and with the others.
Always use good practices.
Have fun.
36
12年6月5日星期二
37. Discuss
Training
in workshop
Develop
in concurrence
Deliver
for acceptance
37
12年6月5日星期二
38. Odd-e
Certified Scrum Developer
• One week course simulating how it feels to be on a Scrum project
- Realistic exercise to work on as a team
- Topics covered: A-TDD, Build Automation, Sprint Planning, Pair
Programming, Continuous Integration, Test-Driven Development,
Working in teams, Collective Code Ownership, Mocking, Code
Smells & Refactoring, Good unit tests,Emergent Design, Working
with Legacy Code, Craftsmanship
- Maximum 10 people, in Odd-e office
- Java and C++ version
- Fulfills the ScurmAlliance CSD
More info at:
http://www.odd-e.com/courses.php?id=201205SingaporeCSD 38
12年6月5日星期二