ProjectEuler.net - Problem 2

roland's picture

Problem:

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, ...

Find the sum of all the even-valued terms in the sequence which do not exceed four million.

 

Solution:

I think this problem can only be solved programmatically, so here it goes in Ruby of course:

limit = 4000000
fib1, fib2, sum = 1, 1, 0
while fib2 < limit do
  fib1 += fib2
  fib2 += fib1
  sum += (fib1 % 2 == 0 ? fib1 : 0)
  sum += (fib2 % 2 == 0 ? fib2 : 0)
end
p sum

Answer: 4613732

ProjectEuler.net - Problem 1

roland's picture

Problem:
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.

Solution:
This can be done analytically or programmatically.

Analytically:
The sum of numbers from 1..n is n*(n+1)/2
Between 1..1000 there are 1000/3 = 333 that are divisible by 3. So their sum is: 3*333*334/2 = 166,833
Between 1..1000 there are 1000/5 = 200 that are divisible by 5. So their sum is: 5*200*201/2 = 100,500
However we are double counting numbers divisible by 15 (3*5 = 15) so we need to subtract them.
Between 1..1000 there are 1000/15 = 66 that are divisible by 15. So their sum is: 15*66*67/2 = 33,165
Finally the sum numbers multiples of 3 and 5 is 234,168

Programmatically:
Using Ruby this is trivial: (1..1000).select{|d| d%3 == 0 or d%5 == 0}.inject(0){|m,e| m+= e}
which also yelds 234168.

Of course, the analytical case scales much better for large numbers.

Comcast Jacking up Prices in Indiana

roland's picture

When I moved to Indiana, Insight was the broadband provider. However, they entered some agreement to move out of Indiana with Comcast and I believe Kentucky is one of the states Insight serves.

The rate was $40/month and it was so for two years. When Comcast took over the price was the same. In October 2009, they increased the price to $43/month. Now Comcast has moved us on a promotional offer which means that in July 2010, they are jacking up prices to about $60/month. That's a 50% price increase, and it's very very unfair that we have to bear the cost of people with huge TVs that hog the bandwidth with their programming needs. Isn't there a consumer protection or something for price hikes of this magnitude? Anti-trust laws or something?

Is Blue Ray a very expensive technology?

roland's picture

I have been paying attention to prices of blue ray technology and surprisingly everything has been very expensive for a really long time. A player/burner costs around $250 disks cost $2.6, which is quite crazy. If you break it down by cost of storing a giga byte of data, blue ray costs $0.1/GB, where as hard drives $0.07. So you will say, 3 cents is not much of a difference, but the technologies are not even at par. You can read/write hard drives where as you can't say the same about disks.

What has happened for DVDs doesn't seem to be happening for Blue Ray disks. For DVDs the cost of storing 1GB is $0.03, which is three times less. Maybe the makers of Blue Ray are cashing in on the promises that one day we'll have 500GB disks, however, I doubt that's going to be anytime soon, since hologramic storage is not commercial yet.

Playing more than one audio source in Gentoo with Gnome

roland's picture

Perhaps, I didn't quite understand how ALSA and gnome played together, and what gstreamer actually did.
Well, Gentoo, unlike Ubuntu, has little customizations, such as the compiz doesn't come with any plugins enabled.

I was having an issue with playing more than one audio source. For example: playing a video on youtube and a video would result in only one source playing. Even if you emerged/installed alsa-utils and did everything http://www.gentoo.org/doc/en/alsa-guide.xml and still had this issue in Gnome.

I noticed that some applications such as VLC (VideoLan Player) will allow you to choose ALSA as the audio output, and mplayer will detect ALSA, but most apps rely on the default behavior. So, where does one customize the default behavior?

gstreamer-properties

In the options choose ALSA as the video input and output and suddenly everything will work one again.

Google video chat works too hard for you

roland's picture

I installed the video chat plugin in a VM without a microphone or audio, and the funny thing, the video chat plugin still works. Check this out:

While I don't have a camera, mic, or audio, I can still use it. I suppose it makes sense to see another's video, however, it's probably only useful for viewing another's webcam. I don't know, it just sounds funny.

Speculating about Time

roland's picture

When we consider moving left and right we can do so by pushing something and then gravity helps us move somewhat along the surface of the Earth. When you gave to movie up we must also push something behind, as we move up, for example helicopters or rockets. Moving along these dimensions requires us to push something behind as we are propelled away from our original position.

Gravity also binds movement in space, and one has to use thrusters to propel itself away from such attractive forces.

On the other hand, all are affected by Time. Without it gravity would have no meaning, nothing would ever happen. What does it take for one to break away from Time? What must one give up to break off Time. Could death be one such way people break away from Time? What about innert objects? How can one make such an object be appart from time, what must it give up or release in order to bend the effect of time?

EasyCamera support in Gentoo (and linux generally)

roland's picture

I have a webcam on my laptop but even though I tried enabling all modules in kernel 2.6.32, I wasn't able to get the system to recognize my webcam.

Finally, I found out about this project: http://linux-uvc.berlios.de/#devices and finally I got it to work.

You need mercurial source control for the source:

cd /usr/src
hg clone http://linuxtv.org/hg/~pinchartl/uvcvideo/
cd uvcvideo
make
make install

Edit either /etc/modprobe.conf (Ubuntu) or /etc/conf.d/modules (Gentoo) to add the kernel module.

Use something like "cheese" to test your webcam.

On the other hand, reading about privacy online, you may want to disable the automatic modprobe until you need it. :)

Syndicate content