473,398 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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:
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
Jul 18 '06 #1
3 1190

"Nico" <ni**@nospam.itwrote in message news:44********@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
Jul 18 '06 #2
Nic
Thanks for the answer.
No. This is not a school project. Just a funny hobby.

Nico

"Sheldon Glickler" <sh*******@asap-consult.comha scritto nel messaggio
news:Lv*************@twister.nyroc.rr.com...
>
"Nico" <ni**@nospam.itwrote in message news:44********@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

Jul 18 '06 #3
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:
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
Jul 18 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

99
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less...
2
by: Wenjie | last post by:
Hello, I read someone posted assertions that even the (public) member function is not static, there are probably only one copy of the code in the executable. Then except the...
25
by: Stijn Oude Brunink | last post by:
Hello, I have the following trade off to make: A base class with 2 virtual functions would be realy helpfull for the problem I'm working on. Still though the functions that my program will use...
9
by: Gibby Koldenhof | last post by:
Hiya, Terrible subject but I haven't got a better term at the moment. I've been building up my own library of functionality (all nice conforming ISO C) for over 6 years and decided to adopt a...
30
by: Will Pittenger | last post by:
Does C# inline functions? I do not see a inline keyword. Is there an implicit inline? Can the compiler select functions for auto-inlining? I am more used to C++ where all these things are...
22
by: TC | last post by:
I have an Access database application with a lot of custom row functions written in VBA. In other words, a lot of queries contain calculated fields which use functions defined in the modules. I...
1
by: ashutosh | last post by:
hi, i am making the dll for clamav antivirus libraray so that i can make activex control for windows. i complied the library successfully and make the Libclamav.dll file using win32 Api...
23
by: Timothy Madden | last post by:
Hello all. I program C++ since a lot of time now and I still don't know this simple thing: what's the problem with local functions so they are not part of C++ ? There surely are many people...
8
by: Edward Diener | last post by:
By reuse, I mean a function in an assembly which is called in another assembly. By a mixed-mode function I mean a function whose signature has one or more CLR types and one or more non-CLR...
14
by: v4vijayakumar | last post by:
Why we need "virtual private member functions"? Why it is not an (compile time) error?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.