Reply to topic  [ 113 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7, 8  Next
Project Euler 
Author Message
Spends far too much time on here
User avatar

Joined: Thu Apr 23, 2009 6:44 pm
Posts: 4141
Location: Exeter
Reply with quote
Ok, currently working on problem 5, using the code below, keep on getting an error regarding an 'unresolved external symbol' and I cannot for the love of Geoff work out why it is giving me this. Have renamed every variable going just incase I was using something that was already named and tried commenting out pretty much everything after the int main() but cannot see what's giving the problem.

Code:
//1.5 Project Euler Problem 5 - What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20

#include <iostream>

int main()
{
   int x; // entry being tested
   int y; // entry in 'array'
   bool z; // Problem resolved?

   using std::cout;

   z = false;
   x = 2520;
   y = 2;

   while (z == false)
   {
      
      while (y < 21)
      {
         if (x % y == 0)
         {
            y++;
         }
         else
         {
            y = 41;
         }
      }

      if (y == 21)
      {
         z = true;
      }
      else
      {
         x = x + 2;
         y = 2;
      }

   }

   //cout << x << "\n";

   return 0;
}

_________________
"The woman is a riddle inside a mystery wrapped in an enigma I've had sex with."


Sun Aug 21, 2011 6:17 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 7:35 pm
Posts: 6580
Location: Getting there
Reply with quote
Try removing the "using std..." bit and put "using namespace std;" as the line after the include line at the beginning.

Seems ok apart from that though.


---
I am here: http://maps.google.com/maps?ll=53.851236,-1.530917

_________________
Oliver Foggin - iPhone Dev

JJW009 wrote:
The count will go up until they stop counting. That's the way counting works.


Doodle Sub!
Game Of Life

Image Image


Sun Aug 21, 2011 6:42 pm
Profile WWW
Spends far too much time on here
User avatar

Joined: Thu Apr 23, 2009 6:44 pm
Posts: 4141
Location: Exeter
Reply with quote
Found the cause, I'd selected the wrong project types when creating the project in VS, set that correctly and everything works.

The function itself isn't working properly mind, but that's a different matter entirely ;)

EdIt: It does if you don't comment out your final print screen of the answer! :oops:

_________________
"The woman is a riddle inside a mystery wrapped in an enigma I've had sex with."


Sun Aug 21, 2011 6:44 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 7:35 pm
Posts: 6580
Location: Getting there
Reply with quote
Woop!

Done number 81 now!

Runs in about 0.001 seconds :D

LOL!

_________________
Oliver Foggin - iPhone Dev

JJW009 wrote:
The count will go up until they stop counting. That's the way counting works.


Doodle Sub!
Game Of Life

Image Image


Sun Aug 21, 2011 9:26 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 7:35 pm
Posts: 6580
Location: Getting there
Reply with quote
13 and 25 done!

Wrote my own set of functions to add numbers together in string form and then used these to work out both of the problems.

Somehow I don't think 1000 digit numbers are covered by 32 bit ints. :D

Will be working on 82 and 83 tonight. Can solve them both with the same program (ish) but need to write the setup first.

_________________
Oliver Foggin - iPhone Dev

JJW009 wrote:
The count will go up until they stop counting. That's the way counting works.


Doodle Sub!
Game Of Life

Image Image


Mon Aug 22, 2011 11:59 am
Profile WWW
Spends far too much time on here
User avatar

Joined: Thu Apr 23, 2009 9:40 pm
Posts: 4876
Location: Newcastle
Reply with quote
got the start & end digit on 79, just 6 digits to go.... so just 720 (minimum) combinations left :lol:

_________________
Twitter
Charlie Brooker:
Macs are glorified Fisher-Price activity centres for adults; computers for scaredy cats too nervous to learn how proper computers work; computers for people who earnestly believe in feng shui.


Mon Aug 22, 2011 1:06 pm
Profile
Spends far too much time on here
User avatar

Joined: Thu Apr 23, 2009 6:44 pm
Posts: 4141
Location: Exeter
Reply with quote
Problem 79 done by 'observation', was reasonably straight forward. Would be quite a lot harder to program I suspect.

_________________
"The woman is a riddle inside a mystery wrapped in an enigma I've had sex with."


Mon Aug 22, 2011 1:48 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 7:35 pm
Posts: 6580
Location: Getting there
Reply with quote
OK, I've got a program that will solve problem 14 but becuase it's done at work it doesn't have the capacity to store enough entries for the recursive program.

Will have to re-do it in C++ at home tonight.

_________________
Oliver Foggin - iPhone Dev

JJW009 wrote:
The count will go up until they stop counting. That's the way counting works.


Doodle Sub!
Game Of Life

Image Image


Mon Aug 22, 2011 2:20 pm
Profile WWW
Spends far too much time on here
User avatar

Joined: Thu Apr 23, 2009 9:40 pm
Posts: 4876
Location: Newcastle
Reply with quote
jonlumb wrote:
Problem 79 done by 'observation', was reasonably straight forward. Would be quite a lot harder to program I suspect.


See I see that as cheating for a problem like this, the whole idea is to program every problem, doing by observation without thinking the process through completely is a different matter to doing it in code

Fogmeister wrote:
OK, I've got a program that will solve problem 14 but becuase it's done at work it doesn't have the capacity to store enough entries for the recursive program.

BigInteger in .net is enough :)

_________________
Twitter
Charlie Brooker:
Macs are glorified Fisher-Price activity centres for adults; computers for scaredy cats too nervous to learn how proper computers work; computers for people who earnestly believe in feng shui.


Mon Aug 22, 2011 2:37 pm
Profile
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 6:36 pm
Posts: 5151
Location: /dev/tty0
Reply with quote
I wish I were better at maths. I've done a few in Perl, but when it started to talk about prime factors, I get somewhat scared off...


Mon Aug 22, 2011 2:45 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 7:35 pm
Posts: 6580
Location: Getting there
Reply with quote
finlay666 wrote:
jonlumb wrote:
Problem 79 done by 'observation', was reasonably straight forward. Would be quite a lot harder to program I suspect.


See I see that as cheating for a problem like this, the whole idea is to program every problem, doing by observation without thinking the process through completely is a different matter to doing it in code

Fogmeister wrote:
OK, I've got a program that will solve problem 14 but becuase it's done at work it doesn't have the capacity to store enough entries for the recursive program.

BigInteger in .net is enough :)

I've got the BigInteger library for C++ at home but wanted to try doing it without using a pre-written library.

I was trying to use it using the string library I've written at work.

It takes strings of any length and can add them together and also divide them by 2. :D

I'm quite pleased with it :D

_________________
Oliver Foggin - iPhone Dev

JJW009 wrote:
The count will go up until they stop counting. That's the way counting works.


Doodle Sub!
Game Of Life

Image Image


Mon Aug 22, 2011 2:57 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Thu Jun 18, 2009 5:10 pm
Posts: 5836
Reply with quote
I think I may have to try some these...


... but I think I'll try them in Ada :lol:

_________________
Jim

Image


Mon Aug 22, 2011 3:40 pm
Profile
Spends far too much time on here
User avatar

Joined: Thu Apr 23, 2009 9:40 pm
Posts: 4876
Location: Newcastle
Reply with quote
Fogmeister wrote:
I've got the BigInteger library for C++ at home but wanted to try doing it without using a pre-written library.


First one I did I ended up writing my own library before finding out it was covered in System.Numerics

_________________
Twitter
Charlie Brooker:
Macs are glorified Fisher-Price activity centres for adults; computers for scaredy cats too nervous to learn how proper computers work; computers for people who earnestly believe in feng shui.


Mon Aug 22, 2011 9:59 pm
Profile
I haven't seen my friends in so long
User avatar

Joined: Thu Jun 18, 2009 5:10 pm
Posts: 5836
Reply with quote
No. 1 done in Ada - after learning how to do it again

8-)

_________________
Jim

Image


Tue Aug 23, 2011 4:39 pm
Profile
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 7:35 pm
Posts: 6580
Location: Getting there
Reply with quote
Finn, when you said you did 14 and it worked pretty quickly, how quickly did it run?

Also what number type did you use to store the lengths and values?

I'm using a recursive function to store all values in an array but I have to use BigIntegers for the lengths and the values otherwise I get stupid nonsense answers.

Also, even though I'm storing all previously encountered lengths it still takes 74 seconds to run. The function works so that if I was to start at 3 (for example) when it finishes running it would have stored the lengths for 3, 10, 5, 16, 8, 4, 2 and 1 (if I just did 3 that is without doing 2 and 1 before it).

It runs the function 3 million times which on a C2D 2.4GHz should take that amount of time (but I do have iTunes playing music and Safari open at the same time).

The only thing I can think is that taking the time up is BigInteger and when looking through the solution forum they have been able to use longs and unsigned longs but these just don't work for me.

Are there differences that would cause one person's long to be different from another person's?

_________________
Oliver Foggin - iPhone Dev

JJW009 wrote:
The count will go up until they stop counting. That's the way counting works.


Doodle Sub!
Game Of Life

Image Image


Tue Aug 23, 2011 9:35 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 113 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7, 8  Next

Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.