|
Post by matthew on Oct 24, 2017 17:06:32 GMT -5
Project Euler is a website which lists a series of mathematical problems which range in complexity from the relatively simple to the difficult. The first 100 problems are thought to be the easiest though. I'd originally begun using thinBasic several years ago but didn't get too far, I seem to remember someone here suggesting using Basic4GL to solve the problems but I don't think they ever got started. So I thought I'd create this thread where everyone can post their solutions to the tasks. I've solved the first problem... (which is probably the simplest) 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.
Find the sum of all the multiples of 3 or 5 below 1000. dim i, sum
for i = 1 to 999
if (i % 3 = 0) or (i % 5 = 0) then printr "Num:" ; i sum = sum + i endif
next
printr printr "Sum:" ; sum
|
|
|
Post by Nicky Peter Hollyoake on Oct 24, 2017 19:30:25 GMT -5
Looks interesting, being in uni doing engineering, problem solving is what we do a lot of. So definitely something I'd do for fun sometimes.
My laptop is downstairs and im being lazy so I'm going to do the 2nd problem without testing it. Let me know if it works.
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
dim firstTerm=1 dim secondTerm=2 dim currentTerm dim sum=2
do currentTerm=firstTerm+secondTerm firstTerm=secondTerm secondterm=currentTerm
if currentTerm % 2 = 0 then sum=sum+currentTerm endif loop until (firstTerm+secondTerm) > 4000000
print sum drawtext()
I'll edit the this post tomorrow if it needs changing.
Nicky
|
|
|
Post by matthew on Oct 24, 2017 20:08:47 GMT -5
Hi Nicky, my way of solving problem 2 was similar to yours. dim sum, evenSum
dim firstNum = 1 dim secondNum = 1
dim total = 4000000
while sum < total sum = firstNum + secondNum
if (sum < total) and (sum % 2 = 0) then evenSum = evenSum + sum endif
firstNum = secondNum secondNum = sum
wend
printr printr evenSum
If you create an account on the Project Euler website, you'll be able to download a PDF for each of the problems you've solved correctly. The PDF shows you other ways you could have got to the answer.
|
|