Euler Problems
kinuthiA muchanE
muchanek at gmail.com
Sat Jul 12 18:15:26 BST 2008
Habari wote,
Now, this is getting lively, and I think Zacharia is the teacher all of
us have been longing for :-) Step by step, you elucidate all the
underling principles. I thought nobody ever reads this, I am mistaken.
Zacharia, why dont you subscribe to project Euler
(http://projecteuler.net ) and at least I will not be leading in the
list Kenyans who have solved the most problems, only 52, the last time I
looked.
And to Andrew (ha... you are at 17 ), you ask a question and then
disappear!! Hmmmm, and where is Miano??
Cheers!!
Kinuthia...
On Sat, 2008-07-12 at 07:16 -0700, Zacharia M. Rugongo wrote:
> This email is from a ubuntu-ke subscriber to other subscribers inluding you:)
> My solution to Euler #12 runs in less than 1 minute.
>
>
> Let us list the factors of the first eight triangle numbers:
> 1: 1
> 3: 1,3
> 6: 1,2,3,6
> 10: 1,2,5,10
> 15: 1,3,5,15
> 21: 1,3,7,21
> 28: 1,2,4,7,14,28
> 36: 1,2,3,4,6,8,9,12,18,36
> Note the numbers that are underlined in each sequence. This is the half way point.
> a) If you divide the triangle number by the first number that is underlined the result will be greater than the divisor.
> b)
> On the other hand if you divide the triangle number by the second
> number that is underlined the result will be less than the divisor.
> c)
> The triangle number 36 has only one number at the centre of the
> sequence, because that centre number is the square root of the triangle
> number 36.
>
> In
> cases a) and b) if you wanted to know the total number of divisors, you
> look for the position of the number underlined as described in b), then
> subtract 1 from it, then multiply it by 2. For example, for triangle
> number 28, value 7 is in position 4. So (4-1) * 2 = 6
>
> In
> cases c) if you wanted to know the total number of divisors, you look
> for the position of the center number underlined, then multiply it by
> 2. For example, for triangle number 36, value 6 is in position 5.
> So 5 * 2 = 10
>
> Here is the program.
>
>
> Dim triagNo As Integer ' Triangle number
> Dim counter As Integer ' for calculating the next triangle number
> Dim varValue As Integer ' Incremented in search for a Divisor
> Dim NoDivisors As Integer ' number of Divisors found
> Dim Divisor As Integer ' Value of found Divisor
>
> Do
> counter += 1
> triagNo = triagNo + counter
> varValue = 0
> Divisor = 0
> NoDivisors = 0
>
> Do
> varValue += 1
> If triagNo Mod varValue = 0 Then ' is varValue a Divisor
> Divisor = varValue
> NoDivisors += 1
> End If
> Loop Until (triagNo / Divisor) <= Divisor ' Find when you reach the second centre value
>
> If (triagNo / Divisor) = Divisor Then
> NoDivisors = (NoDivisors - 1) * 2 + 1 ' cases a) and b)
> Else
> NoDivisors = (NoDivisors - 1) * 2 ' case c)
> End If
>
> Loop Until (NoDivisors > 500)
>
> TextBox1.Text = triagNo
>
>
> Z. Mwangi
>
>
>
> ----- Original Message ----
> From: Andrew Mathenge <mathenge at gmail.com>
> To: ubuntu Kenya <ubuntu-ke at lists.ubuntu.com>
> Sent: Friday, July 11, 2008 3:24:23 AM
> Subject: Re: Euler Problems
>
> This email is from a ubuntu-ke subscriber to other subscribers inluding you:)
> I've been working on #12 and the performance is simply not acceptable.
> Has anyone been able to get this running as fast as some of the posts
> on the site claim?
>
> Andrew.
>
> On Tue, Jul 8, 2008 at 12:40 PM, kinuthiA muchanE <muchanek at gmail.com> wrote:
> > Andrew,
> > For #10, if you do not use a sieve to find the primes, it will run
> > forever!
> > There is one called the Sieve of Erastothenes. Check it out on
> > Wikipedia.
> >
> > Good luck :-)
> > Kinuthia...
> > On Tue, 2008-07-08 at 10:47 -0400, Andrew Mathenge wrote:
> >> I'm still trying them. I started at #1 after the one you proposed
> >> (#26) and I'm at #10 now. This one should be very simple but I don't
> >> know why it's taking so long to run.
> >>
> >> Andrew.
> >>
> >> On Tue, Jul 8, 2008 at 6:52 AM, kinuthiA muchanE <muchanek at gmail.com> wrote:
> >> > Habari,
> >> > Anybody still trying these problems, you are all so, so silent...
> >> >
> >> > Kinuthia...
> >> >
> >> >
> >
> >
>
> --
> Ubuntu-ke mailing list
> Ubuntu-ke at lists.ubuntu.com
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-ke
>
>
>
>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: https://lists.ubuntu.com/archives/ubuntu-ke/attachments/20080712/e8965b59/attachment.htm
More information about the Ubuntu-ke
mailing list