What's new

Project Euler

AceInfinity

Moderator, Programming, Contributor
Joined
Feb 21, 2012
Messages
1,729
Location
Canada
Project Euler

How many problems can you figure out? :thumbsup2: Let's have Sysnative compete as well for fun. (This thread will be the repository for any questions or answers provided by other members here.) I did this at my forum and we've figured out quite the number of them already. Through programmatically calculated results.

It's actually pretty fun!

Note: I challenge anyone to solve #406.

If you'd like an idea on some of the results we came up with, or you're wondering how to get results. Here's a link that will be a starter location for you, to get your brain thinking in terms of these problems if you're struggling: Project Euler Answers Thread

It was pretty popular on my own forum, so i'm going to share it here too. I want to see how active we can get this section of the forum. Even if you are not a programmer, I encourage you to try a few of the questions and solve them in whatever way you like. Otherwise... You can use Batch if you want lol, I don't care.

Good luck to all participants :)

~Ace
 

niemiro

Senior Administrator, Windows Update Expert, Developer
Staff member
Joined
Mar 2, 2012
Messages
8,386
Location
District 12
I'm pretty sure I completed problem 1, some time ago... :p

I probably should do some more, but it is just a case of finding the time, and I have so many other projects going on at the moment.

But maybe I can squeeze in the time for problem 2!
 

AceInfinity

Moderator, Programming, Contributor
Joined
Feb 21, 2012
Messages
1,729
Location
Canada
Well, I was kinda hoping that more people would at least try, because this is really lame lol. Too lame.

:bored2:
 

writhziden

Administrator, BSOD Kernel Dump Expert, C++ OOP
Joined
May 23, 2012
Messages
2,329
Location
Colorado
Sorry Ace. My time is really limited this week with a big deadline tomorrow for our program at my work. No time for fun stuff. ;-}
 

AceInfinity

Moderator, Programming, Contributor
Joined
Feb 21, 2012
Messages
1,729
Location
Canada
I'm up to Problem 36 with a couple odd ones solved from later on. I'll share one of my solutions...

Problem #28
Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows:



It can be verified that the sum of the numbers on the diagonals is 101.

What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed in the same way?
Answer #28
Pretty happy with this solution, I was actually going to create the grid then loop over it, but looking at the structure and orientation of the numbers in that grid for the diagonals, I found a nice formula on my own :)

Makes things much easier, and 100% faster lol.

Code:
//Answer #28: Project Euler
static void Main(string[] args)
{
	int size = 5;
	int sum = GetSpiralSum(size);
	Console.WriteLine("Sum Of Diagonals ({0}x{0} Grid):\n\t= {1}", size, sum);
	Console.ReadKey();
}

static int GetSpiralSum(int size)
{
	//formula for odd # grid size
	int len = size + size - 1;
	int sum = 0;
	int index = 1;

	sum = 1;
	for (int i = 3; i <= size; i += 2, ++index)
	{
		for (int j = 0; j < 4; j++)
		{
			sum += (i * i) - ((j * i) - j);
		}
	}
	return sum;
}
There's an even shorter way, but that is just a finer detail on the analysis that I did to come up with a result.
 
Last edited:

Will Watts

Senior Administrator, Security Analyst
Staff member
Joined
Mar 4, 2012
Messages
5,790
Location
%tmp%
I'm failing at question 1, so I'm not expecting to get too far... :lol:
 

AceInfinity

Moderator, Programming, Contributor
Joined
Feb 21, 2012
Messages
1,729
Location
Canada
Enumerate the numbers in that range, check for even divisibility by both 3 and 5, if both are multiples of that number, then keep track of that number. Maybe in an array or something. Then after you're done finding the numbers, add them together.

In C# here was my solution for the first one:
Code:
Console.WriteLine(Enumerable.Range(1, 999).Where(i => i % 3 == 0 || i % 5 == 0).Sum());
At least you are trying :thumbsup2: Everyone else just seems to read this thread and go silent lol :lol:
 

Will Watts

Senior Administrator, Security Analyst
Staff member
Joined
Mar 4, 2012
Messages
5,790
Location
%tmp%
I started in Python - haven't used it for a few months so I'm a bit rusty. I've since seen a much cleaner solution in Python - now that I've remembered bits of syntax. This was my first attempt though:

Code:
x = 0
y = 0
i = 0
q = 0
largest_x = 0
largest_y = 0

#multiples of 3
while largest_x <= 1000:
    largest_x = 3*i
    if largest_x < 1000:
        x += largest_x
    i += 1


#multiples of 5
while largest_y <= 1000:
    largest_y = 5*q
    if largest_y < 1000:
        y += largest_y
    q += 1

print (y+x)
I couldn't remember much syntax, hence the overly complicated attempt. However, I'm still not sure why it doesn't work. If I change it to work out the example, under 10, it works fine. But I'm doing dodgy calculations and it goes wrong with higher numbers; maths isn't my strong point. :grin1:
 

AceInfinity

Moderator, Programming, Contributor
Joined
Feb 21, 2012
Messages
1,729
Location
Canada
Nice work guys :)

No problem Will, you may struggle with a few, but otherwise some of these are fairly straightforward, and just require optimization for performance and speed of the calculations. I struggled with a couple so far, there's 2 that I can't solve at this point, some coin problem in 31, and 406. Not sure about the rest yet. I'm done 1-42, and I skipped 31. But other than that, 52, and 67 are completed on my account as well.

It's good to see SOME activity here, even just the slightest bit... I'm happy :)

My friend key on Project Euler:
Code:
75060110415387_a2341721eae9286d23fd272b7720e0a6

~Ace
 

niemiro

Senior Administrator, Windows Update Expert, Developer
Staff member
Joined
Mar 2, 2012
Messages
8,386
Location
District 12
I have just had a look at 31. The problem for me is that although I can see a logical method for calculation, it would be a nightmare to debug even a tiny mistake.
 

AceInfinity

Moderator, Programming, Contributor
Joined
Feb 21, 2012
Messages
1,729
Location
Canada
I have just had a look at 31. The problem for me is that although I can see a logical method for calculation, it would be a nightmare to debug even a tiny mistake.
^ Behold, lol. That's my issue. I think I have figured out a way to do it though, although with modified permutations... The other admin on my forum wrote a recursive function in C++ to help achieve the result, although I'm not sure if he actually solved it yet. He just had a similar task for homework in his data class.
 

Will Watts

Senior Administrator, Security Analyst
Staff member
Joined
Mar 4, 2012
Messages
5,790
Location
%tmp%
I'll soon move on to number 2. :lolg:

At least it's good for my maths.
 

AceInfinity

Moderator, Programming, Contributor
Joined
Feb 21, 2012
Messages
1,729
Location
Canada
I'll soon move on to number 2. :lolg:

At least it's good for my maths.
There's some crazy ones in here that I can't solve because of my math as well. Specifically a couple physics ones that involve calculating the blast radius' volume in m^3 for a firecracker that explodes 100m above ground. :) I can calculate the range it would go (farthest), but the volume i'm clueless on.
 

AceInfinity

Moderator, Programming, Contributor
Joined
Feb 21, 2012
Messages
1,729
Location
Canada
I'll post what I shared to others. This is all I did for that challenge, but I never proceeded to advance any farther than this on 317.



Calculating the largest arc, comes with background knowledge that the pieces being thrown away from the center point at a 45 degree angle will go the farthest (assuming no other external forces in this problem, as mentioned).

This means that the pieces from the firecracker, when it explodes 100m above ground, that are going in a 45 degree angle from that horizontal plane 100m above ground, will go the farthest horizontally. So we would be able to calculate the distance it goes horizontally by taking the horizontal component of the initial velocity, and plugging it into a formula to calculate the range of this projectile motion. (Note: At the point where it falls to the same plane; 100m above ground away from the original point... It moves even farther because of momentum and inertia while it's falling to the ground the rest of that 100m).

Aside from that, I am not too sure on how you would calculate the volume (all directions, not just left and right on a 2D representation,) for this explosion zone formed when it goes off. It would be more like a dome, so i'm sure there's some formula out there as well for this, which involves gravity, the displacement from the center, and the height).

But, there's also the area above that 45 degree blast arc, along with the point directly above the firecracker, and perpendicular to the ground.
I took Physics, but that knowledge is forgotten now. I can only remember bits and pieces.
 

tom982

Senior Administrator, Windows Update Expert
Joined
May 31, 2012
Messages
4,357
Location
New York
If I've worked it out correctly, then the X directly to the right of the point of explosion on your diagram is 40.77471948m away, and the X where the fragments would touch the floor is 87.41807227m away from your centre line. I don't know if it helps though, as the path of the projectile is curved so the volume can't be calculated with any simple calculations, it's going to be some hideously complicated differential equation followed by a lovely bit of integration, and the bottom party is the easy bit :p

I'll ask my differential equations lecturer about this when I go back to uni, there's got to be an equation to use for this :)
 
Top