Project Euler Solutions<p>This thread is dedicated for interesting project Euler solutions.  Some initial attempt on project Euler solutions are available on our Wiki: <a href="http://smallbasic.com/wiki/ProjectEuler.ashx">http://smallbasic.com/wiki/ProjectEuler.ashx</a>. <br/><br/>Problems are available at: <a href="http://projecteuler.net/index.php?section=problems">http://projecteuler.net/index.php?section=problems</a></p>© 2009 Microsoft Corporation. All rights reserved.Thu, 19 Nov 2009 17:22:28 Zc209f91a-278c-43b3-ad03-7ecb4c8b6de1http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#c209f91a-278c-43b3-ad03-7ecb4c8b6de1http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#c209f91a-278c-43b3-ad03-7ecb4c8b6de1Vijaye Rajihttp://social.msdn.microsoft.com/Profile/en-US/?user=Vijaye%20RajiProject Euler Solutions<p>This thread is dedicated for interesting project Euler solutions.  Some initial attempt on project Euler solutions are available on our Wiki: <a href="http://smallbasic.com/wiki/ProjectEuler.ashx">http://smallbasic.com/wiki/ProjectEuler.ashx</a>. <br/><br/>Problems are available at: <a href="http://projecteuler.net/index.php?section=problems">http://projecteuler.net/index.php?section=problems</a></p>Tue, 31 Mar 2009 23:11:51 Z2009-03-31T23:12:52Zhttp://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#0011ba6d-fdb2-40ba-a1b4-b008df7fdcc2http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#0011ba6d-fdb2-40ba-a1b4-b008df7fdcc2Vijaye Rajihttp://social.msdn.microsoft.com/Profile/en-US/?user=Vijaye%20RajiProject Euler SolutionsTo kick off, the First Problem is:<br/><br/> <p><em>&quot;If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.</em></p> <p><em>Find the sum of all the multiples of 3 or 5 below 1000.&quot;<br/></em><br/><strong>Solution<br/></strong>Id: <strong>JLK064<br/></strong>Listing: <a href="http://smallbasic.com/program/?JLK064">http://smallbasic.com/program/?JLK064</a></p>Tue, 31 Mar 2009 23:35:29 Z2009-03-31T23:35:29Zhttp://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#dc7c35a2-8f98-43c2-9d2a-89c2f91f57f6http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#dc7c35a2-8f98-43c2-9d2a-89c2f91f57f6Coding Cathttp://social.msdn.microsoft.com/Profile/en-US/?user=Coding%20CatProject Euler Solutions<p class=MsoNormal>I originally posted this as part of a response for the thread on arrays.</p> <p class=MsoNormal>Euler Projects 18 and 67 require the use of arrays or other similar data structures. You are given a triangle of numbers, and your job to find the maximum sum traveling from the tip to the base of the triangle. Project 18 has a height of 15, problem 67 has a height of 100.</p> <p class=MsoNormal><a title="http://projecteuler.net/index.php?section=problems&amp;id=18" href="http://projecteuler.net/index.php?section=problems&amp;id=18" title="http://projecteuler.net/index.php?section=problems&amp;id=18">http://projecteuler.net/index.php?section=problems&amp;id=18<br/> http://projecteuler.net/index.php?section=problems&amp;id=67</a></p> The small basic solution can be imported from the ID: XBN618Wed, 01 Apr 2009 16:43:43 Z2009-04-01T16:43:43Zhttp://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#e84173f4-db52-4370-8a81-a73adbd462a9http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#e84173f4-db52-4370-8a81-a73adbd462a9Coding Cathttp://social.msdn.microsoft.com/Profile/en-US/?user=Coding%20CatProject Euler SolutionsEuler Problem #28 <p class=MsoNormal><a title="http://projecteuler.net/index.php?section=problems&amp;id=28" href="http://projecteuler.net/index.php?section=problems&amp;id=28" title="http://projecteuler.net/index.php?section=problems&amp;id=28">http://projecteuler.net/index.php?section=problems&amp;id=28</a></p> The goal of this problem is to build a 1000x1000 grid, populate the grid with increasing numbers spiraling out from the center, and find the sum of the diagonals of the resulting grid.<br/> <p class=MsoNormal><br/> The first solution builds a 1000x1000 grid using the array object, with the needed spiraling values. Once built the code zips through the diagonals to find the sum.<br/> <br/> SmallBasic Publish ID: NMQ902<br/> <br/> Once I completed the above solution, it occurred to me that I could accomplish the same task by tracking the values of the diagonals as I was building the spiral. The array isn't needed. The second solution solves the problem without the array, and does so in half the time.<br/> <br/> Small Basic Publish ID: RBH700<br/></p>Tue, 21 Apr 2009 19:01:26 Z2009-04-21T19:02:25Zhttp://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#4359bd68-cf81-48dd-b5ee-8c66be233a84http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#4359bd68-cf81-48dd-b5ee-8c66be233a84Coding Cathttp://social.msdn.microsoft.com/Profile/en-US/?user=Coding%20CatProject Euler Solutions<strong>Euler Problem #30</strong> <br/> <br/> <a title="http://projecteuler.net/index.php?section=problems&amp;id=30" href="http://projecteuler.net/index.php?section=problems&amp;id=30" title="http://projecteuler.net/index.php?section=problems&amp;id=30">http://projecteuler.net/index.php?section=problems&amp;id=30</a> <br/> <br/> The goal of this problem is to find the sum of all numbers where:<br/> the sum of the fifth power of the numbers digits, equals that number<br/> Example: 4150 = 4^5 + 1^5 + 5^5 + 0^5<br/> <br/> <br/> This solution is a good example of why I have always been a fan of BASIC. Working with strings can be unpleasant in most languages. Basic makes it easy. I managed to cough up this solution in about five minutes, where it would have taken closer to an hour with Java simply because of the need to struggle with string manipulation (yes, I know you could also do some math to separate the digits).<br/> <br/> Small Basic Publish ID: RLB652Tue, 05 May 2009 19:54:45 Z2009-05-05T19:54:45Zhttp://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#7c5e11ec-525c-46d3-b506-4656a47fb4b3http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#7c5e11ec-525c-46d3-b506-4656a47fb4b3Vijaye Rajihttp://social.msdn.microsoft.com/Profile/en-US/?user=Vijaye%20RajiProject Euler SolutionsVery nice!  Love the elegance of RLB652.Tue, 05 May 2009 20:41:58 Z2009-05-05T20:41:58Zhttp://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#1bbff18c-e7b0-43a0-8eb8-c53d431ac8b3http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#1bbff18c-e7b0-43a0-8eb8-c53d431ac8b3gunnar.hhttp://social.msdn.microsoft.com/Profile/en-US/?user=gunnar.hProject Euler Solutions<p><strong>Another way to solve the Euler problem #28<br/><br/></strong>This program is much faster than the previously posted one. It solves the problem by viewing the diagonals as the result of four different equations, each starting in the middle. It then adds every value for each of the results in the equations to a variable and when it's done it shows the result.<br/><br/>This is the solution i came up with, the program is very simple and should be easy to understand.<br/><br/>ID: QXH159</p>Sun, 21 Jun 2009 21:26:48 Z2009-06-21T21:26:48Zhttp://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#81ad58d9-16a6-41f6-80cb-5575b7bc7ea6http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#81ad58d9-16a6-41f6-80cb-5575b7bc7ea6Coding Cathttp://social.msdn.microsoft.com/Profile/en-US/?user=Coding%20CatProject Euler SolutionsNice. You are right gunnar, your solution is fifteen times faster and it is a more elegant solution than mine.<br/>Mon, 22 Jun 2009 00:14:30 Z2009-06-22T00:14:30Zhttp://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#9d6c8679-4222-465c-ae2f-36c784604ab5http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#9d6c8679-4222-465c-ae2f-36c784604ab5Ma_Cherhttp://social.msdn.microsoft.com/Profile/en-US/?user=Ma_CherProject Euler SolutionsHi, <br/> on the followed link you can find my humble attempt of solution for problem no 69.<br/> <br/> The 'graphical' part makes sense only for small part of the triangle (up to 15-20 rows) but generally works for any (reasonable) size.<br/> <br/> As this is one of my first excercises, please forgive me some basic mistakes.<br/> <br/> <a href="http://smallbasic.com/program/?NXP803">http://smallbasic.com/program/?NXP803</a> <br/> <br/> ID: NXP803<br/>Wed, 24 Jun 2009 10:51:02 Z2009-06-24T10:51:02Zhttp://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#cc2359bc-b27b-427f-bfe9-851e2ef835afhttp://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#cc2359bc-b27b-427f-bfe9-851e2ef835afnrawlinsonhttp://social.msdn.microsoft.com/Profile/en-US/?user=nrawlinsonProject Euler SolutionsI've posted a solution with no looping... :)<br/><br/>Here's the way the young Gauss would have attacked the problem...<br/><br/>Use the Math.Floor function to find the number of multiples of 3 (n3) and 5 (n5) below the given number respectively.<br/><br/>Add up all the natural numbers from 1 to n3 (simple formula is n3x(n3 + 1) /2) and multiply by 3. (sum3)<br/>Do likewise for n5, only multiply by 5 of course! (sum5)<br/><br/>Then, because the multiples coincide at multiples of 15, use similar programming to find the sum of all the multiples of 15.<br/><br/>The answer is then simply sum3 + sum5, minus the sum of the multiples of 15.<br/><br/>Take a look...<br/><br/><a href="http://smallbasic.com/program/?LWS487">http://smallbasic.com/program/?LWS487</a>Thu, 20 Aug 2009 23:17:14 Z2009-08-20T23:17:14Zhttp://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#4589cade-65dd-469e-bff3-c14b17632337http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#4589cade-65dd-469e-bff3-c14b17632337litdevhttp://social.msdn.microsoft.com/Profile/en-US/?user=litdevProject Euler SolutionsI like your approach.  Modern computers make number crunching easier than thinking.<br/> <br/> However, doing it by brute force, noting the 'below input number' ...<br/> <br/> <em>total = 0<br/> For i = 1 To input-1<br/>   If (math.Remainder(i,3) = 0 or math.Remainder(i,5) = 0) Then<br/>     total = total+i<br/>   EndIf<br/> EndFor<br/> TextWindow.WriteLine(&quot;The long answer is :&quot; + total)</em> <br/> <br/> So for input = 15 we have:<br/> <br/> 3,6,9,12 &amp; 5,10, sum= 45, you have 30<br/> <br/> BTW we agree on the answer for 1000 - 233168<br/> <br/> Perhaps I am missing something in the original problem.<br/>Fri, 21 Aug 2009 20:32:41 Z2009-08-21T20:32:41Zhttp://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#f2a71ae3-9d5c-45ed-82bd-922529680aa9http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#f2a71ae3-9d5c-45ed-82bd-922529680aa9nrawlinsonhttp://social.msdn.microsoft.com/Profile/en-US/?user=nrawlinsonProject Euler SolutionsNo you didn't miss anything - I did! -  a coding error on my part that only showed up when the target was an exact multiple of 15 - just forgot to do &quot;Input - 1&quot; when calculating the multiples of 15 to be subtracted...<br/><br/>Embarrassing!<br/><br/>Thanks for pointing it out...<br/><br/>Revised code at <a href="http://smallbasic.com/program/?KNR835">http://smallbasic.com/program/?KNR835</a><br/><br/>I love the way smallbasic handles really big numbers - input 1000000000000 into the program above...<br/><br/>Anyone know just how big a number it can cope with?Sun, 23 Aug 2009 20:10:52 Z2009-08-23T20:13:23Zhttp://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#b9d42b97-41f5-4b12-bb96-4555e08801b5http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#b9d42b97-41f5-4b12-bb96-4555e08801b5litdevhttp://social.msdn.microsoft.com/Profile/en-US/?user=litdevProject Euler SolutionsThe following gives up at 2^95 on my PC.<br/> <br/> <em>i = 1<br/> </em> <em>x = 2<br/> While(&quot;True&quot;)<br/>   i = i+1<br/>   x =2*x<br/>   TextWindow.WriteLine(i+&quot; : &quot;+x)<br/> EndWhile<br/> </em> <br/>Sun, 23 Aug 2009 21:35:40 Z2009-08-23T21:35:40Zhttp://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#c6efdabe-7aa3-4568-89e2-5ad9f979132dhttp://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#c6efdabe-7aa3-4568-89e2-5ad9f979132dchengbang69http://social.msdn.microsoft.com/Profile/en-US/?user=chengbang69Project Euler SolutionsMy first post in small basic forum<br/> <br/> Problem #6<br/> Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.<br/> <br/> <a href="http://smallbasic.com/program/?NXP803-0">http://smallbasic.com/program/?NXP803-0</a>Tue, 15 Sep 2009 13:58:55 Z2009-09-15T13:58:55Zhttp://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#d5af07a3-263c-4dc1-a896-4c8f64a728d8http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#d5af07a3-263c-4dc1-a896-4c8f64a728d8Mathguy360http://social.msdn.microsoft.com/Profile/en-US/?user=Mathguy360Project Euler SolutionsThis is what it got to on mine (btw it was done before you could snap your fingers): <div> <div><br/></div> <div>95 : 39614081257132168796771975168</div> <div><br/></div> <div>Then it said this in an error window:</div> <div> </div> <div>   Value was either too large or too small for a Decimal.</div> <div><br/></div> <div>   at System.Decimal.FCallMultiply(Decimal&amp; result, Decimal d1, Decimal d2)</div> <div>   at Microsoft.SmallBasic.Library.Primitive.Multiply(Primitive multiplicand)</div> <div>   at Microsoft.SmallBasic.Library.Primitive.op_Multiply(Primitive primitive1, Primitive primitive2)</div> <div>   at _SmallBasicProgram._Main()</div> </div>Thu, 19 Nov 2009 17:21:16 Z2009-11-19T17:21:16Zhttp://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#36ba97e8-fc04-41d6-93a2-e8734e486fcehttp://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c209f91a-278c-43b3-ad03-7ecb4c8b6de1#36ba97e8-fc04-41d6-93a2-e8734e486fceMathguy360http://social.msdn.microsoft.com/Profile/en-US/?user=Mathguy360Project Euler Solutionswhich is the same thing it got to on your computer because it went over how many digits you could haveThu, 19 Nov 2009 17:22:28 Z2009-11-19T17:22:28Z