28 Aug 2007 acs   » (Journeyer)

The Practice of Perl

Well.. a sugestive title for an post, but I decide for this title because of Perl is one of my prefer programming languages, my “swiss army knife”… and dont first time that I using perl for solving my problem… ehehehhehehehhee…

But why I talking about perl here??? Because of one problem, for more exactly, the problem 5 of Project Euler (http://projecteuler.net/), a site with mathematical problems that resolve with the use of algorithms. The problem 5 it follows below:

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.

What is the smallest number that is evenly divisible by all of the numbers from 1 to 20?

I trying resolve this using C, but I dont have an simple compiler in my work machine,because in my opinion, Visual C is much complex for this task… (some of my friends dont think it…)

But I think… I have perl interpretor in my machine and write this program in perl dont much harder and I starting the port of C for Perl and write this piece of code for solving my problem:

for ( my $n = 20; 1; $n++ ) {
for ( 1..20 ) {
if ( $n % $_ ) {
last;
}
if ( $_ == 20 ) {
die $n;
}
}
}
Well… is an idiot program, extremaly simple but I have the answer of problem with this… dont consider the execution time, “only” 20 min of the pure brute force for answering the problem… ehehhehehehehehhehe…

And perl with your practical syntax save my world one more time!!!! :D

In Play: Gorguts - The Erosion of Sanity - 04: Orphans of Sickness

Syndicated 2007-08-09 04:22:42 from Jumpi's Notepad

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!