Permutations - Perl or just Javascript embedded ?

Discussion in 'Perl Misc' started by Telemach, Feb 28, 2008.

  1. Telemach

    Telemach Guest

    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 -
     
    Telemach, Feb 28, 2008
    #1
    1. Advertising

  2. Telemach <> writes:

    > 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/
     
    Joost Diepenmaat, Feb 28, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. walterbyrd
    Replies:
    1
    Views:
    377
    Damjan
    Apr 10, 2006
  2. Colin Paul Gloster
    Replies:
    48
    Views:
    1,911
    Colin Paul Gloster
    Apr 10, 2007
  3. Thomas Dodds

    Databind an embedded control in an embedded datagrid

    Thomas Dodds, Jul 26, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    416
    Thomas Dodds
    Jul 26, 2004
  4. Trans
    Replies:
    11
    Views:
    316
    micathom
    Sep 5, 2007
  5. Num GG
    Replies:
    2
    Views:
    381
    Num GG
    Nov 17, 2008
Loading...

Share This Page