niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » PHP
Two functions and one problem
Post new topic   Reply to topic Page 1 of 1 [4 Posts] View previous topic :: View next topic
Author Message
Nico
*nix forums beginner


Joined: 18 Jul 2006
Posts: 1

PostPosted: Tue Jul 18, 2006 9:37 am    Post subject: Two functions and one problem Reply with quote

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:
countcombinations(a,...;b,...)
listcombinations(a,...;b,...)

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

Example
countcombinations(element1;element2,element3)
Result: 2 ("element1 combined with element4" and "element1 combined with
element5")

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

Example
listcombinations(element1;element2,element3)
Result: element4, element5

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

Best,
Nico
Back to top
Shelly
*nix forums Guru Wannabe


Joined: 22 May 2005
Posts: 146

PostPosted: Tue Jul 18, 2006 10:14 am    Post subject: Re: Two functions and one problem Reply with quote

"Nico" <nico@nospam.it> wrote in message news:44bcabd9$1@news.unimib.it...
Quote:

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:
countcombinations(a,...;b,...)
listcombinations(a,...;b,...)

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

Example
countcombinations(element1;element2,element3)
Result: 2 ("element1 combined with element4" and "element1 combined with
element5")

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

Example
listcombinations(element1;element2,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 "combinations".

Is this a school project?

Shelly
Back to top
cdf
*nix forums Guru


Joined: 25 Apr 2005
Posts: 303

PostPosted: Tue Jul 18, 2006 11:45 am    Post subject: Re: Two functions and one problem Reply with quote

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

Nico

"Sheldon Glickler" <sheldonlg@asap-consult.com> ha scritto nel messaggio
news:Lv2vg.93$1Z5.65@twister.nyroc.rr.com...
Quote:

"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:
countcombinations(a,...;b,...)
listcombinations(a,...;b,...)

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

Example
countcombinations(element1;element2,element3)
Result: 2 ("element1 combined with element4" and "element1 combined with
element5")

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

Example
listcombinations(element1;element2,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 "combinations".

Is this a school project?

Shelly
Back to top
ImOk
*nix forums beginner


Joined: 07 Jul 2006
Posts: 29

PostPosted: Tue Jul 18, 2006 3:42 pm    Post subject: Re: Two functions and one problem Reply with quote

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:
Quote:
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:
countcombinations(a,...;b,...)
listcombinations(a,...;b,...)

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

Example
countcombinations(element1;element2,element3)
Result: 2 ("element1 combined with element4" and "element1 combined with
element5")

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

Example
listcombinations(element1;element2,element3)
Result: element4, element5

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

Best,
Nico
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [4 Posts] View previous topic :: View next topic
The time now is Thu Jan 08, 2009 6:45 am | All times are GMT
navigation Forum index » Programming » PHP
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Unknown in header problem -SOLVED- Light Speed Postfix 0 Thu Jul 03, 2008 10:40 am
No new posts problem with sending mail nuxia Postfix 0 Mon Apr 21, 2008 3:58 am
No new posts Postfix 2.3.8 Virtual problem Blotto Postfix 0 Fri Apr 04, 2008 6:11 am
No new posts Postfix sending problem for local domain remote email monkey_magix Postfix 0 Mon Sep 10, 2007 10:17 am
No new posts bounce problem murkis Postfix 0 Sun Oct 08, 2006 3:45 pm

Loans | Guitar Lessons | Debt Consolidation | Loans | Bournemouth Hen Party
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.4354s ][ Queries: 16 (0.3409s) ][ GZIP on - Debug on ]