Two functions and one problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nico

    Two functions and one problem


    Hi,

    I've created the following sample php code.

    Elements<br>
    <?php
    $elements[1]="element1";
    $elements[2]="element2";
    $elements[3]="element3";
    $elements[4]="element4";
    $elements[5]="element5";
    ?>
    Combinations
    <?php
    $combinations[1][1]="element1"; // Combination of element 1 with element
    2
    $combinations[1][2]="element2";
    $combinations[2][1]="element3"; // Combination of element 1 with element
    3
    $combinations[2][2]="element1";
    $combinations[3][1]="element4"; // Combination of element 1 with element
    4
    $combinations[3][2]="element1";
    $combinations[4][1]="element5"; // Combination of element 1 with element
    5
    $combinations[4][2]="element1";
    ?>

    I'd like to define two simple functions:
    countcombinatio ns(a,...;b,...)
    listcombination s(a,...;b,...)

    The first function "countcombinati ons(a,...;b,... )" should count how many
    combinations exist in which "a" and "..." are included and "b" and "..."
    are not included.

    Example
    countcombinatio ns(element1;ele ment2,element3)
    Result: 2 ("element1 combined with element4" and "element1 combined with
    element5")

    The second function "listcombinatio ns(a,...;b,...) " should list the elements
    combined with "a" and "...", excluding from the list the elements "b" and
    "...".

    Example
    listcombination s(element1;elem ent2,element3)
    Result: element4, element5

    I've some difficult in defining this two functions.
    Can you help me please?
    Many thanks.

    Best,
    Nico
  • Sheldon Glickler

    #2
    Re: Two functions and one problem


    "Nico" <nico@nospam.it wrote in message news:44bcabd9$1 @news.unimib.it ...
    >
    Hi,
    >
    I've created the following sample php code.
    >
    Elements<br>
    <?php
    $elements[1]="element1";
    $elements[2]="element2";
    $elements[3]="element3";
    $elements[4]="element4";
    $elements[5]="element5";
    ?>
    Combinations
    <?php
    $combinations[1][1]="element1"; // Combination of element 1 with element
    2
    $combinations[1][2]="element2";
    $combinations[2][1]="element3"; // Combination of element 1 with element
    3
    $combinations[2][2]="element1";
    $combinations[3][1]="element4"; // Combination of element 1 with element
    4
    $combinations[3][2]="element1";
    $combinations[4][1]="element5"; // Combination of element 1 with element
    5
    $combinations[4][2]="element1";
    ?>
    >
    I'd like to define two simple functions:
    countcombinatio ns(a,...;b,...)
    listcombination s(a,...;b,...)
    >
    The first function "countcombinati ons(a,...;b,... )" should count how many
    combinations exist in which "a" and "..." are included and "b" and "..."
    are not included.
    >
    Example
    countcombinatio ns(element1;ele ment2,element3)
    Result: 2 ("element1 combined with element4" and "element1 combined with
    element5")
    >
    The second function "listcombinatio ns(a,...;b,...) " should list the
    elements
    combined with "a" and "...", excluding from the list the elements "b" and
    "...".
    >
    Example
    listcombination s(element1;elem ent2,element3)
    Result: element4, element5
    >
    I've some difficult in defining this two functions.
    Can you help me please?
    Many thanks.
    >
    Best,
    Nico
    I don't know if these ae related to your problem, but:
    1 - indices start with zero, not one.
    2 - A semicolon ends a sentence so I don't understand your argument list
    3 - I cannot follow your naming in "combinatio ns".

    Is this a school project?

    Shelly


    Comment

    • Nic

      #3
      Re: Two functions and one problem

      Thanks for the answer.
      No. This is not a school project. Just a funny hobby.

      Nico

      "Sheldon Glickler" <sheldonlg@as ap-consult.comha scritto nel messaggio
      news:Lv2vg.93$1 Z5.65@twister.n yroc.rr.com...
      >
      "Nico" <nico@nospam.it wrote in message news:44bcabd9$1 @news.unimib.it ...
      >>
      >Hi,
      >>
      >I've created the following sample php code.
      >>
      >Elements<br>
      ><?php
      >$elements[1]="element1";
      >$elements[2]="element2";
      >$elements[3]="element3";
      >$elements[4]="element4";
      >$elements[5]="element5";
      >?>
      >Combinations
      ><?php
      >$combination s[1][1]="element1"; // Combination of element 1 with element
      >2
      >$combination s[1][2]="element2";
      >$combination s[2][1]="element3"; // Combination of element 1 with element
      >3
      >$combination s[2][2]="element1";
      >$combination s[3][1]="element4"; // Combination of element 1 with element
      >4
      >$combination s[3][2]="element1";
      >$combination s[4][1]="element5"; // Combination of element 1 with element
      >5
      >$combination s[4][2]="element1";
      >?>
      >>
      >I'd like to define two simple functions:
      >countcombinati ons(a,...;b,... )
      >listcombinatio ns(a,...;b,...)
      >>
      >The first function "countcombinati ons(a,...;b,... )" should count how many
      >combinations exist in which "a" and "..." are included and "b" and "..."
      >are not included.
      >>
      >Example
      >countcombinati ons(element1;el ement2,element3 )
      >Result: 2 ("element1 combined with element4" and "element1 combined with
      >element5")
      >>
      >The second function "listcombinatio ns(a,...;b,...) " should list the
      >elements
      >combined with "a" and "...", excluding from the list the elements "b" and
      >"...".
      >>
      >Example
      >listcombinatio ns(element1;ele ment2,element3)
      >Result: element4, element5
      >>
      >I've some difficult in defining this two functions.
      >Can you help me please?
      >Many thanks.
      >>
      >Best,
      >Nico
      >
      I don't know if these ae related to your problem, but:
      1 - indices start with zero, not one.
      2 - A semicolon ends a sentence so I don't understand your argument list
      3 - I cannot follow your naming in "combinatio ns".
      >
      Is this a school project?
      >
      Shelly
      >

      Comment

      • ImOk

        #4
        Re: Two functions and one problem

        Nico,

        This is not a PHP problem. I would pose this question in one of the
        math or statistical groups.

        Once you get the pseudo code in place it should be easy to program it
        in PHP.

        Nico wrote:
        Hi,
        >
        I've created the following sample php code.
        >
        Elements<br>
        <?php
        $elements[1]="element1";
        $elements[2]="element2";
        $elements[3]="element3";
        $elements[4]="element4";
        $elements[5]="element5";
        ?>
        Combinations
        <?php
        $combinations[1][1]="element1"; // Combination of element 1 with element
        2
        $combinations[1][2]="element2";
        $combinations[2][1]="element3"; // Combination of element 1 with element
        3
        $combinations[2][2]="element1";
        $combinations[3][1]="element4"; // Combination of element 1 with element
        4
        $combinations[3][2]="element1";
        $combinations[4][1]="element5"; // Combination of element 1 with element
        5
        $combinations[4][2]="element1";
        ?>
        >
        I'd like to define two simple functions:
        countcombinatio ns(a,...;b,...)
        listcombination s(a,...;b,...)
        >
        The first function "countcombinati ons(a,...;b,... )" should count how many
        combinations exist in which "a" and "..." are included and "b" and "..."
        are not included.
        >
        Example
        countcombinatio ns(element1;ele ment2,element3)
        Result: 2 ("element1 combined with element4" and "element1 combined with
        element5")
        >
        The second function "listcombinatio ns(a,...;b,...) " should list the elements
        combined with "a" and "...", excluding from the list the elements "b" and
        "...".
        >
        Example
        listcombination s(element1;elem ent2,element3)
        Result: element4, element5
        >
        I've some difficult in defining this two functions.
        Can you help me please?
        Many thanks.
        >
        Best,
        Nico

        Comment

        Working...