Project Euler...

Everything else that doesn't fall into one of the other PB categories.
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Well done, Derek...

...now you can optimize the next one :lol: (of course you can start also with an "unsolved" problem and create a fine purebasic code;)...

Michael
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

I will try to get round to some coding but at the moment I'm networking the house and it's more like not-working. :cry:
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Derek, hope your network will soon run fine (has networking something to do with plug'n play? :lol:)

I've solved 30 Euler problems for now, but it starts getting a little bit trickier already... :roll:
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Nope, bloody network won't work. Going to have to give up on it.

The internet sharing is working but the actual computers won't connect together, oh well, no great loss. I only really wanted the shared internet, the network was going to be a bonus.

Have reinstalled XP 3 times in the last two days and of course had to install SP2 and then the updates from microsoft (79 critical updates), if I never have to re-install an os again it will be too soon.

Back OT, will try to have a look at the problems on monday, hope you don't find them too hard.
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Hmm,
thought 'bout your network problems - different OS versions (e.g. Win2k and XP) can have a lot of difficulties seeing each other, but if you use the same OS on all boxes it "should" work...

Maybe the firewall settings?
Are your able to ping between the PCs?
Maybe you can do an easy check whats going on with an Analyzer (or the small freeware SmartSniff)?

Solved aready 40 Euler problems (#1 to #40), some of them not very smart...

Michael
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Have you done 22 because no matter what I do I cant get it to work, I can't even get 'COLIN' to be at array index 938!

Do you think it is the built in sort going wrong or can you see what I have done wrong?

How many have you done now BTW?

Code: Select all

OpenFile(1,"e:\names.txt")
a$=ReadString(1)
a$=Mid(a$,2,Len(a$)-1);remove first "
CloseFile(1)
Dim b$(5165)
c=0
t$=""
Repeat
  z$=Left(a$,1)
  a$=Mid(a$,2,Len(a$)-1)
  If z$<>","
    t$+z$; keep adding letters until find ,
  EndIf
  If z$=","
    c+1
    b$(c)=Left(t$,Len(t$)-1);remove " from end
    t$=""
    a$=Mid(a$,2,Len(a$)-1);remove first "
  EndIf
Until a$=""
ReDim b$(c)
SortArray(b$(),0);is this the problem?

rt=0
For n=1 To c
  t=0
  a$=b$(n)
  For m=1 To Len(a$)
    q=Asc(Mid(a$,m,1))-64;add up letters
    t+q
  Next
  rt=rt+t*n;running total + value*position
Next
Debug rt

For n=935 To 940
  Debug Str(n)+" "+b$(n)
Next
Debug "0="+b$(0)
Debug "1="+b$(1)
Debug "last="+b$(c)
Edit. It's just dawned on me that I'm looking for commas to seperate the names and of course the last name isn't followed by a comma and is probably getting dropped. Off to test my theory.

Edit. Yep, that sorted it! :D
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Solved 50 :P problems now - but #50 runs much longer than a minute :cry: . All other programs need usually less than a second, only a few need some seconds...

'bout the textfile (#22), the correct result look like this: 87?????82! There's also a second problem (#42) where I read the data with the following code...

Code: Select all

	zeile.s=""
	wort.s=""

	If ReadFile(0,"Euler-P42.txt")
		zeile=ReadString(0)+","
		CloseFile(0)
	EndIf

	s=0
	l=0
	Repeat

		k=FindString(zeile,",",l+1)
		If k
			wort=Mid(zeile,l+2,k-l-3)
			l=k
			;
			;
		EndIf
	Until k=0
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Have you seen some of the code, on the forums available when you solve a puzzle, written in 'J' and 'K'.

Whole programs only a dozen or so characters that need 30 or 40 lines of pb code, very interesting.
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Yep, crazy things, also programs like Mathematica seems to have fine script languages...
...but -- for the moment -- I didn't try to understand these snippets :?

I still try to solve ALL problems with Purebasic -- even it's not the best tool for all problems...
> especially when mixing long and quad variables, the results are unpredictable (for me;)...
> mixing float and integer variables is also dangerous: a.l=sqr(7) is different to a.l=int(sqr(7))
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Yeah, mixing quads with anything is dodgy at best. I'm finding it easier to use strings and simulate all the maths, a lot more accurate when you need a thousand digits or more!

Just did number 28. Doing all the easy ones. :wink: :)

Code: Select all

Dim a(1001,1001)
a(501,501)=1
x=502
y=501
c=2
st=2
Repeat
For n=1 To st;down
a(x,y)=c
c+1
y=y+1
Next
y=y-1
x=x-1

For n=1 To st;left
a(x,y)=c
c+1
x=x-1
Next
x=x+1
y=y-1

For n=1 To st;up
a(x,y)=c
c+1
y=y-1
Next
y=y+1
x=x+1

For n=1 To st;right
a(x,y)=c
c+1
x=x+1
Next

st=st+2
Until c=1002002

t=0
For n=1 To 1001
t=t+a(n,n)
t=t+a(n,1002-n)
Next
t=t-1
Debug t
Not very elegant.
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

You're right 'bout math functions using strings - but they are slow (and I made only functions for add, sub and mul - div was already too complicated)...

Here's my 28-code...

Code: Select all

x=1001
d1=0 : d2=0
For i=1 To x>>1
	ro=(i*2+1)*(i*2+1)
	lo=ro-i-i
	ru=(i+i)*(i+i)-i-i+1
	lu=ru+i+i
	d1+lu+ro
	d2+lo+ru
Next i

ShowResult(1+d1+d2);
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Very nice, I'm just trying to get them done now, not very pretty coding but it's working. :lol:
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Hi,

some problems are really hard to solve (for me) - and problem #60 can't be done under 1 minute (CPU time) for now (and I spent already about 1 hour brain time or so :wink:)

Michael
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Haven't had much time recently, (been playing a silly game called 'Tower Defence' too much).

Problem 60 does indeed look like it would take an eternity to work out!Good luck.

I've only been doing the easy ones and there aren't many of them. :wink:
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Problem 60 looks fun, I will take a shot at it when I get home.
Post Reply