473,569 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Combination Testing to a predefined value

What I want to do is write a program to test lexicographical
combinations of various sets of numbers to a predefined number and
write that true values to a text file.

Example:

Number choosen between 1 and 50

Number set = 6

Value test = 150

Save to = 150.txt

So what happens is you are using 50 numbers in sets of 6 to test the
sets to equal to 150 and

save to file 150.txt

01 02 03 04 05 06 = 21 False -> Discard
01 10 20 30 40 49 = 150 True -> Store number set in text file
Any ideas would be appreciated as I am fairly new to C++ and would like
to make the program flexible to test any numbers and number sets.

Thanks

May 10 '06 #1
4 2307
ki***********@g mail.com wrote:
What I want to do is write a program to test lexicographical
combinations of various sets of numbers to a predefined number and
write that true values to a text file.

Example:

Number choosen between 1 and 50

Number set = 6

Value test = 150

Save to = 150.txt

So what happens is you are using 50 numbers in sets of 6 to test the
sets to equal to 150 and

save to file 150.txt

01 02 03 04 05 06 = 21 False -> Discard
01 10 20 30 40 49 = 150 True -> Store number set in text file
Any ideas would be appreciated as I am fairly new to C++ and would like
to make the program flexible to test any numbers and number sets.

Thanks


It is not at all clear to me what you are trying to do. What is the
"number set"? What is the "value test"? Are both of those supplied by
the user? Are the "number sets" supplied by the user? Do you always
just add the numbers together to see if the sum is equal to the "value
test"? Etc.

Please clarify, and perhaps we can help more.

Cheers! --M

May 10 '06 #2
The number sets , value test and number range will always be supplied
by the user.

If the user wants to test a number set of 5 numbers between 1 and 50
that will give the total of 100 ,then they will provide that.

So it will be
Range: 1 to 50
Number Set: 5
Value: 100
20 30 35 5 10 = 100 .

For now it will be only be adding the numbers. The other thing is that
each test will be a unigue set so that there is no confusion with
repeat sets of numbers
Only the number set will be stored in the text file.

Hope this helps

May 11 '06 #3
In message <11************ *********@i39g2 000cwa.googlegr oups.com>,
ki***********@g mail.com writes
The number sets , value test and number range will always be supplied
by the user.

If the user wants to test a number set of 5 numbers between 1 and 50
that will give the total of 100 ,then they will provide that.

So it will be
Range: 1 to 50
Number Set: 5
Value: 100
20 30 35 5 10 = 100 .

For now it will be only be adding the numbers. The other thing is that
each test will be a unigue set so that there is no confusion with
repeat sets of numbers

So you're looking for an algorithm to find unique *partitions* of the
total into sets of numbers each within the given range?

This sounds like a general algorithms problem, rather than anything
specific to C++. How about asking somewhere like comp.programmin g?

--
Richard Herring
May 16 '06 #4
In article <11************ ********@e56g20 00cwe.googlegro ups.com>,
ki***********@g mail.com wrote:
What I want to do is write a program to test lexicographical
combinations of various sets of numbers to a predefined number and
write that true values to a text file.

Example:

Number choosen between 1 and 50

Number set = 6

Value test = 150

Save to = 150.txt

So what happens is you are using 50 numbers in sets of 6 to test the
sets to equal to 150 and

save to file 150.txt

01 02 03 04 05 06 = 21 False -> Discard
01 10 20 30 40 49 = 150 True -> Store number set in text file
Any ideas would be appreciated as I am fairly new to C++ and would like
to make the program flexible to test any numbers and number sets.


Personally I would start by writing a generic algorithm with the
following signature and semantics:

template<class Function, class BidirectionalIt erator, class Size>
Function
for_each_combin ation(Bidirecti onalIterator first,
BidirectionalIt erator last,
Size k, Function f);

Requires: [first, last) is a valid range.

Effects: For each combination of elements in [first, last) taken k at a
time, permutes those elements into the range [first, first+k) and calls
f(first, first+k). If k < 1, no calls to f are made. If k >
last-first, it is truncated to last-first.

Notes: The effects clause does not imply random access. Iterator
addition used only for concise statements.

Returns f.

This is a valuable general purpose tool.

Then I would write a test functor more geared to your problem which has
an operator taking a range of int's, sums them up (perhaps using
std::accumulate ), compares the sum to the proper number (perhaps given
during the functor's constructor), and if equal, process the desired
range in the desired way.

Finally a driver program could create the array, and call
for_each_combin ation with the appropriately created test functor.

The implementation of for_each_combin ation is definitely the hard part
in this exercise. But fwiw, there are 183723 combinations of numbers in
the range [1, 50], where six of them add up to 150 (out of a total of
nearly 16 million combinations).

There are cheaper algorithms for this particular computation. But
having the for_each_combin ation function in your tool box is worth the
time creating it. It is much more general, and if nothing else, would
help you test a more specialized but higher performing algorithm for
this problem.

-Howard
May 16 '06 #5

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

Similar topics

1
2061
by: Jim Hefferon | last post by:
Hello, Does anyone have suggestions for unit testing CGI scripts? For instance, how can I set the FieldStorage to have certain values? Do I have to go with a dummy FieldStorage class? And is there a better way to check the output than to compare the resulting (sometimes very large) strings? Changing the HTML slightly means that I have to...
3
2295
by: Andrew | last post by:
Hi, I am thinking about ways for efficient techniques for isolation testing. Here is the problem as I see it: Complex OO systems are designed with massive number of dependencies between modules and classes. In most cases these dependencies end-up in external systems such as databases and OS. Overhead in designing systems with "could be...
1
3956
by: Bo Xu | last post by:
Object of Combination By Bo Xu Introduction A combination of n things, taken s at a time, often referred as an s-combination out of n, is a way to select a subset of size s from a given set of size n. There are n!/(s!(n-s)!) ways to do this. Donald E. Knuth gives several methods (algorithms) to generate all the s-combinations in . In such...
3
6007
by: gdogg1587 | last post by:
Greetings. I'm working on a program that will "descramble" words. Think of a word scramble game where there is a list of characters, and several blank spaces to denote the word(s) that you are to come up with from the list. i.e.(* denotes a space): _ _ _ _ _ * _ _ _ _ _ _ characters: .hwodlelrlo answer: hello world.
1
2135
by: lwoods | last post by:
Sorry for previous email...hit the wrong key! Original Email: I ran the following code: <?php $a=get_defined_constants(); foreach($a as $key=>$value){ echo "$key = $value<br/>"; }
0
1319
by: im20 | last post by:
I am helping a polish up a client's PPC campaign and when of the problems I have run into is that the real estate backend system he is using, does not allow the ability to link directly to a predefined search. Say for a city. You have to use a form to get anything out of the system in return. You can link directly to a listing but not a search. ...
2
3482
by: kernel_panic | last post by:
Consider the following code noting the two uses of sizeof(): unsafe struct A { int value; } unsafe struct B { fixed byte value; // Error: 'A' does not have a
0
980
by: sukatoa | last post by:
My friend ask me about how to copy the value of the key combination Alt - Tab in other key.... he is also a programmer, yet always opening 4 to 7 programs/tools/ diff browsers for testing.... He ask me about other way of "alt-tab".... Is it possible to edit a key and initialize the value similar to alt-tab? He must be getting lazy......
2
2687
by: =?windows-1252?Q?=22=C1lvaro_G=2E_Vicario=22?= | last post by:
Is there any way to tell PHP predefined variables ($GLOBALS, $argv, $argc, $_GET, $_POST…) from *global* user-defined variables? Neither $GLOBALS nor get_defined_vars() put user data apart. I’m writing a class to generate PHP definition files for syntax highlighting with two features: 1. It takes data from current install (e.g., you get...
0
7698
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7673
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7970
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.