Reply to topic  [ 113 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7, 8  Next
Project Euler 
Author Message
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, was able to throw out half the starting values but it still takes 39 seconds to run.

Not very impressed with that.

:(

_________________
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: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
Well, there you go then...

Remove the recursive b*ll*cks and it runs in 200ms!

LOL!

OK, so I found out that the erroneous numbers were somehow caused by trying to store too many primitive variables rather than because the numbers exceeded the storage capacity.

I've rewritten it using brute force (checking for unnecessary values before running) and not storing anything. I can do it now using unsigned long longs instead of having to use bigIntegers and it runs in 250ms.

If I try to store any values to increase the speed for repeated values it actually increases the length of time it takes for the program to run!

Stupid computers.

_________________
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:54 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
Thought of a solution to 24 last night.

It worked :D

Need to write a program for it but it is fast.

_________________
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


Wed Aug 24, 2011 8:04 am
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
82 and 83 done with almost the same code :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


Wed Aug 24, 2011 2:16 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
85 done.

Solved it on the first run of the program with a run time of around 29ms!

:D

I was very pleased with that! :D

I didn't have to look up any formulae or algorithms either. Just worked out how to calculate the total rectangles on paper and then wrote an algorithm to find the solution over the possible range.

Altered it slightly (just changed the loops) and it now runs in 3 ms :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


Wed Aug 24, 2011 6:56 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
And now done 38.

Program took about 10ms to run and was right first time :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


Thu Aug 25, 2011 10:07 am
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
And 36 now :D

Done a total of 35 problems now! :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


Thu Aug 25, 2011 11:22 am
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
Written a program for problem 59 but it takes far too long and is far too "dumb". It's just a 100% brute force method.

Going to optimise it with a couple of safe (I think) assumptions which should reduce the run time by around 26 times (at least) 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


Thu Aug 25, 2011 5:20 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
Yay! I got my XOR function wrong which is why it was throwing me out.

In the end I brute forced all possible passwords against the encryption and filtered the results based on English language statistics and only one password came back :D

Takes about 3 mins to run though. Although that's on my slow PC with a high level language.

_________________
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


Fri Aug 26, 2011 12:31 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
Number 2 just done...

...with about 10 lines of code, which is pretty good for me.

8-)

_________________
Jim

Image


Fri Aug 26, 2011 5:32 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
rustybucket wrote:
Number 2 just done...

...with about 10 lines of code, which is pretty good for me.

8-)

Nice :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


Fri Aug 26, 2011 6:20 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
Fogmeister wrote:
rustybucket wrote:
Number 2 just done...

...with about 10 lines of code, which is pretty good for me.

8-)

Nice :D

**Spoiler**

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Sum_Of_Fib_Terms is

Sum_Total: Integer := 2; --Pre-load Total with first even value (That's Cheating! -Ed)

Fib_A : Integer := 1; --Pre-loading the three generator variables
Fib_B : Integer := 2;
Fib_C : Integer := 0;

begin

while Fib_C <= 4000000 loop
Fib_C := Fib_A + Fib_B; --Fibonacci Sequence Generator:
Fib_A := Fib_B + Fib_C; --Right-shifting operations saves the time of
Fib_B := Fib_C + Fib_A; --left-shifting the variables

Sum_Total := Sum_Total + Fib_B; --Increment total with even value

end loop;
Sum_Total := Sum_Total - Fib_B; --get rid of the last answer
Put (Item=> Sum_Total, Width => 15); --Screenprint the answer
end Sum_Of_Fib_Terms;

_________________
Jim

Image


Fri Aug 26, 2011 11:11 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
Dammit - this is getting addictive. Brute force is easy for number 3.

I've come up with a much more elegant algorithm but I've just discovered I'll need at least one goto.

Bugger :x

[edit] Just thought of how to do it with return

_________________
Jim

Image


Sun Aug 28, 2011 11:50 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
Image

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


Mon Aug 29, 2011 11:36 am
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
Right, I've been working on a Sudoku algorithm for problem 96.

I first wrote an algorithm to just fill in the obvious ones (i.e. if 8 different numbers appear in the same column, row or mini grid then the remaining number goes in the current slot).

That didn't do much but I kept it.

I then implemented a thing that looked at the numbers that could go into the current space. If any of the numbers can't go into another square in the mini grid then place it there.

This managed to solve about 10 or 11 out of the 50.

I've now implemented a system that checks an assumption of a number. i.e. this slot can take either 4 or 7. Check 4, does that work or does it break the grid? If it works then place 4 and repeat the first set of checks.

I've now got a program that solves 43 out of the 50 sudoku grids.

The remaining 7 all get broken by the assumption system because they get set so that they become unsolvable :(

It's good fun though :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 29, 2011 10:40 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 3 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.