June
19th 2008
Prime numbers and Ruby

Posted under Programming & Ruby

I have recently started to learn how to program with Ruby. I am somewhat familiar with programming already, but by noe means an expert. I really do want to learn programming, so I started off with Ruby. One of my first programs is a program that checks if a number is a prime number. I have made the program in MATLAB earlier, so I just ported it, if one can say that.

Prime number program

Here you see the program in action. My computer have spent the last few hours trying to figure out if it is a prime or not. Yes, I know it is a prime, and therefore the program needs to do a lot more computing. After all, this is actually a quite big number. Even though it is a small program, with just 25 lines of code or so, it uses over 95 % of my CPU. Because of that, my computer is running a bit slow at the moment. Anyway, I will let the computer finish the calculations. I do wonder how much time it will need though.

I will keep you updated, and write a new post when the program gives me the answer. I will give you the code to, if anyone should be interested.

Update: The program have spent the last 22 hours trying to figure out if the number is a prime or not. I’m really beginning to wonder how much time is needed.

Update II: After about 25 hours, I logged in at my computer, and guess what? For some reason, the computer had decided to reboot. Not too happy about that. I actually suspect that the computer got overheated. Anyway, I will try again, but I might try on another computer. After all, the program uses a lot of resources, so I can’t really use the computer while running the program.

One Response to “Prime numbers and Ruby”

  1. » CPU speed and FLOPS - Lai Alexander on 27 Jun 2008 at 9:03 pm #

    […] might have read my post, Prime numbers and Ruby, and wondered why the program used a huge amount of time, and even after 25 hours of computing, the […]

Trackback URI | Comments RSS

Leave a Reply