programming problems for you solve

Status
Not open for further replies.

office politics

It's all just 1s and 0s
Messages
6,555
Location
in the lab
Project Euler

What is Project Euler?
Project Euler is a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve. Although mathematics will help you arrive at elegant and efficient methods, the use of a computer and programming skills will be required to solve most problems.

The motivation for starting Project Euler, and its continuation, is to provide a platform for the inquiring mind to delve into unfamiliar areas and learn new concepts in a fun and recreational context.



Who are the problems aimed at?
The intended audience include students for whom the basic curriculum is not feeding their hunger to learn, adults whose background was not primarily mathematics but had an interest in things mathematical, and professionals who want to keep their problem solving and mathematics on the edge.



Can anyone solve the problems?
The problems range in difficulty and for many the experience is inductive chain learning. That is, by solving one problem it will expose you to a new concept that allows you to undertake a previously inaccessible problem. So the determined participant will slowly but surely work his/her way through every problem.
 
Have you managed to solve any yet?
I'm just getting into the language, just needing a couple more resources and I should in a couple of months, be able to attempt these.
 
Hmmm, how interesting! Let's see if we can get some compact code for problem 1.
Code:
void main (void)
{ 
  uns16 var,answer;
  while(var!=999)
          {
          var=var+3;
          answer=answer+var;
          }
  var=0;
  while(var!=1000)
         {
         var=var+5;
         answer=answer+var;
         }
}
 
Code:
int MAX = 10;
int calc(int q);

int main(void)
{
	int q1 = 3;
	int q2 = 5;
	
	printf("%d + %d = %d\n", calc(q1), calc(q2), calc(q1) + calc(q2));
	return EXIT_SUCCESS;
}

int calc(int q)
{
	int points = (MAX - 1) / q;	//points on the graph
	int yDiff = (points * q) - q;	//height of the slope
	int area = (yDiff * points) / 2;	//area under the graph
	
	return area + (points * q);	//return the area plus the graph offset
}

EDIT: just change MAX to 1000, I was testing it against 10 because that gave a known answer.
 
^so what answer do you get? I haven't tested my code yet, as I'm on a Mac and I don't have a compiler...
edit: and lol, that's a pretty complicated way of doing it don'tcha think?
 
Status
Not open for further replies.
Back
Top Bottom