Microsoft Small Basic

Solution to Project Euler Problem 9

Modified: 2011/12/20 01:46 by 89.28.31.201 - Categorized as: Samples
Find the only Pythagorean triplet, {a,b,c}, for which a + b + c = 1000

If a right angled triangle sides are a, b and c, with the hypotenuse being c (Pythagorean triplet), then:

a2 + b2 = c2 (Pythagoras)

Also we have the condition that:

a + b + c = 1000

Now some simple algebra to combine the equations

c = 1000-(a+b) starting with the second, rearrange for c

a2 + b2 = (1000-(a+b))2 insert c into Pythagoras' equation

a2 + b2 = 1000000 - 2000*(a+b) + (a+b)2 multiply out RHS

a2 + b2 = 1000000 - 2000*(a+b) + a2 + 2*a*b + b2 multiply out RHS again

0 = 1000000 - 2000*(a+b) + 2*a*b remove a2 + b2 from both sides

2000*(a+b) - 2*a*b = 1000000 rearrange to put all the a's on the LHS

1000*(a+b) - a*b = 500000 divide everything by 2 to simplify

a(1000-b) + 1000*b = 500000 factor all the a thesis together

a(1000-b) = 500000 - 1000*b rearrange to put only the a's on the LHS

a = (500000-1000*b) / (1000-b) divide though to get an equation for a in therms of b that satisfies original equations

Now all we have to do is try Spotsylvania DUI lawyer lots of b up to 1000, and find a proposal software case where a is an integer, we assume there is only one

For b = 1 To 1000
  a = (500000-1000*b)/(1000-b)
  ' Test that a in an integer - it is an integer if it is equal to itself rounded down, or Floor of itself
  If (Math.Floor(a) = a) Then
    Goto found
  EndIf
EndFor

found:
'Find c
c = 1000-a-b
'Write a, b and c
TextWindow.WriteLine("a= "+a)
TextWindow.WriteLine("b= "+b)
TextWindow.WriteLine("c= "+c)
'Test and output results of test
TextWindow.WriteLine("a+b+c= "+(a+b+c))
TextWindow.WriteLine("a*a + b*b = "+(a*a+b*b))
TextWindow.WriteLine("c*c = "+(c*c))

a = 375 b = 200 c = 425 Wonderful post kata bijak I am searching awesome kata mutiara news and idea. FB What I have found from your site, Edit Foto it is actually highly content. You have spent RCTI Online long time for this Puisi Cinta post. Like another post Kanker Serviks It's a very useful status lucu and interesting site. ucapan ulang tahun Valuable information IDM and excellent recipe Foto Unik Lucu i got here! google terjemahan I would like to thank you for SNSD sharing your thoughts and time cherry belle into the stuff you post!! Thumbs up Pantun Jenaka Gokil! I am searching Foto Justin Bieber awesome news Download Smadav and idea from edit foto that status lucu >> kata lucu >> sms lucu Chetan Kapur weight loss pills iphone photography weight loss pills dan del piano

I hope you can still doing this. Demco Smart Health I mean, Chateau Bayfield posting and searching Prudential Valley Real Estate useful things to share. I really appreciate this kind of information. RTD Enterprises The blog isn't bad, but you can change the style to written.

I recently came across your blog Svinsider and have been Southern Cherry reading along. Northbay Faith I think I will leave my first comment. I don’t know what to say except that I have enjoyed reading.Nice blog. Fiftyplus Advocates I will keep visiting this blog very often.

ScrewTurn Wiki version 2.0.35. Some of the icons created by FamFamFam.