Click here to get back home

Permutations - Perl or just Javascript embedded ?

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Permutations - Perl or just Javascript embedded ? Telemach 02-28-2008
Get Chitika Premium
Posted by Telemach on February 28, 2008, 7:19 am
Please log in for more thread options

Yesterday I was thinking all day long about what to use for
permutations and still can't figure out a solution. Situation is
this :

I found great small javascript function that does permutations but
this is quite an unusual one.
Every single digit is assigned to 3 or 4 letters so for example
permutations of number 23
could look like this :

ad
ae
af
bd
be
bf
cd
ce
cf

javascipt code is very simple and it looks like too simple to
understand by me (Perl newbie)
because there is no direct loop, just calling a sub from inside this
same sub

I'm having troubles in understanding this code and then rewriting in
Perl so my question is this :
would it be easier to use some javascript module for Perl and paste
javascipt code inside perl script or rewriting this but with help of
permutation modules ?

Problem is that there are 3 or 4 letters per digit and user can input
whatever long number string.

- Telemach -



Posted by Peter Ludikovsky on February 28, 2008, 7:23 am
Please log in for more thread options
Telemach wrote:
> javascipt code is very simple and it looks like too simple to
> understand by me (Perl newbie)
> because there is no direct loop, just calling a sub from inside this
> same sub

http://en.wikipedia.org/wiki/Recursion_(computer_science)

Posted by Joost Diepenmaat on February 28, 2008, 7:40 am
Please log in for more thread options

> I found great small javascript function that does permutations but
> this is quite an unusual one.

I can't really make sense of your description. If the code is that
simple it's probably short enough to post it here.

> javascipt code is very simple and it looks like too simple to
> understand by me (Perl newbie)
> because there is no direct loop, just calling a sub from inside this
> same sub

Yes, recursion. If you've never seen it before it may take a little
getting used to, I guess. Perl can do this just fine:

# this is an extremely silly example

function rec {
my $i = shift;
if ($i <= 0) {
return 0;
}
else {
return $i + rec($i-1);
}
}

> I'm having troubles in understanding this code and then rewriting in
> Perl so my question is this :
> would it be easier to use some javascript module for Perl and paste
> javascipt code inside perl script or rewriting this but with help of
> permutation modules ?

Using a javascript module for something that sounds as simple as this is
probably complicating the matter too much. You can translate most
javascript code fairly easily to perl.

> Problem is that there are 3 or 4 letters per digit and user can input
> whatever long number string.

I don't know what you're talking about.

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/

Similar ThreadsPosted
Permutations November 4, 2005, 1:53 pm
Permutations Problem May 31, 2006, 3:09 am
Embedded Perl April 25, 2005, 9:44 am
Permutations/combinations from multiple arrays June 13, 2006, 12:26 pm
"Incremental" Embedded Perl May 24, 2005, 8:49 am
Perl on embedded device June 10, 2008, 5:45 pm
Using strict and warnings in embedded perl July 14, 2004, 4:11 am
Using embedded PERL with commercial applications? November 23, 2004, 10:56 pm
Including modules in embedded perl with VC++ May 17, 2005, 11:56 pm
Error Handler in Embedded Perl May 23, 2005, 12:54 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap