|
That's because <button> is shorthand for an <input> with a type of "button".
|
|
|
|
|
I am trying to write a small code to find the possible combinations from a list of integer values which when added is equal to the input value or somewhat nearing.
List<int> comb = new List<comb>() { 618, 350, 308, 300, 250, 232, 200, 128 };
The above list contains the integer values from which the proper combination has to be generated
The combination should have least number of values i.e., greatest number has to used most
Example:
If Input from User [Value = 2386]
Combination 1 = 618 + 350 + 308 + 300 + 250 + 232 + 200 + 128
Combination 2 = 618 + 618 + 618 + 300 + 232
I have used the below code, but have missed some logic.
public static void Main(string[] args)
{
//subtotal list
List<int> totals = new List<int>(new int[] { 618, 350, 308, 300, 250, 232, 200, 128 });
// get matches
List<int[]> results = KnapSack.MatchTotal(2682, totals);
// print results
foreach (var result in results)
{
Console.WriteLine(string.Join(",", result));
}
Console.WriteLine("Done.");
}
internal static List<int[]> MatchTotal(int theTotal, List<int> subTotals)
{
List<int[]> results = new List<int[]>();
while (subTotals.Contains(theTotal))
{
results.Add(new int[1] { theTotal });
subTotals.Remove(theTotal);
}
if (subTotals.Count == 0)
return results;
subTotals.Sort();
double mostNegativeNumber = subTotals[0];
if (mostNegativeNumber > 0)
mostNegativeNumber = 0;
if (mostNegativeNumber == 0)
subTotals.RemoveAll(d => d > theTotal);
for (int choose = 0; choose <= subTotals.Count; choose++)
{
IEnumerable<IEnumerable<int>> combos = Combination.Combinations(subTotals.AsEnumerable(), choose);
results.AddRange(from combo in combos where combo.Sum() == theTotal select combo.ToArray());
}
return results;
}
public static class Combination
{
public static IEnumerable<IEnumerable<T>> Combinations<T>(this IEnumerable<T> elements, int choose)
{
return choose == 0 ?
new[] { new T[0] } :
elements.SelectMany((element, i) =>
elements.Skip(i + 1).Combinations(choose - 1).Select(combo => (new[] { element }).Concat(combo)));
}
}
Is there any other way other than the above to get combinations
|
|
|
|
|
Simplest one for me was
List<int> comb = new List<int>() { 618, 350, 300, 250, 200, 128 };
List<int> output = new List<int>();
output = CalcLowestCombination(comb, 2386);
List<int> Test2 = CalcLowestCombination(comb, 1096);
private static List<int> CalcLowestCombination(List<int> comb, int ToAchieve)
{
List<int> output = new List<int>();
foreach (int value in comb)
{
while (value <= ToAchieve)
{
output.Add(value);
ToAchieve -= value;
}
}
return output;
}
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
The logic returns a combination but when output list is added, it does not return the input value. The Logic fails here.
|
|
|
|
|
There are some good articles on CP (for both C# and C++) on generating combinations, permutations, etc. : [^]. An interesting debate and brawl on StackOverFlow on various permutation generating algorithms here: [^].
While the permutations of a set of eight would be around 40k, the fact that your solution is going to consider multiple uses of any one item suggests to me you will have a vast "combinatorial" space to examine for a set of eight.
good luck, Bill
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
|
|
|
|
|
I don't have a solution, but looking at the exercise I imagine that you will probably need to use the %(mod) operator to determine what value you have left to calculate in your iterations.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
There are much better algorithms to solve Knapsack[^] and the related Subset Sum[^] (this problem). The pseudo-polynomial time DP algorithm is very fast on most practical inputs, and the approximation algorithm is tune-able to be as close to exact as you want it to be, trading off speed for accuracy.
|
|
|
|
|
Hello,
I would like to make infix to postfix calculator.
What I would like to make is like, If I entered the number on the calculator, 1+23*4=, then calculator form will show "1 23 4 * +".
And, I already made my own two program, these are calculator form, and converter infix to postfix program.
But, I don't know how combine two program.
Could somebody help me?
I uploaded two my program on the storage.
infix to postfix program
http://firestorage.jp/download/60346ca65783c9f87a086c362427c05bfdfea76d
calculator program
http://firestorage.jp/download/e636062b4f88508536aed645e85fdc9001e86f83
|
|
|
|
|
Sottyoru wrote: But, I don't know how combine two program. Just add the extra code as a new class or method to the one that needs it. I do not think anyone is going to download these files and do it for you.
Veni, vidi, abiit domum
|
|
|
|
|
|
I want to write a dll file in .net
when i write the dll file and add reference to the project.
I can simply see the whole contents of dll files.while debugging
My question is that i want to write dll file such that no one can see its contents or methods defination. just can use the methods of dll files.
|
|
|
|
|
You need to use obfuscation.
Here[^] is a list of obfuscators that you could consider using.
Note that even obfuscation is not a 100% secure way and users can still view your code.
|
|
|
|
|
Consider this. Suppose no one can see the contents, how does your computer know what to do with it? That could sort of be done, with asymmetric key cryptography, but let's hope that never happens. If people can't read your code, then how will viruses get caught? (on the other hand, how would you find an exploit?) How will backdoors be detected?
Because of the extreme value of the key (at least hundreds of millions, perhaps billions - remember, every virus writer and every government is going to want it), significant resources will be poured into cracking it, ranging from brute-forcing it with super-computers to inspecting the physical circuitry with electron microscopes to going after the source of the key with hacks / actual cloak-and-dagger spies.
It won't be safe for long.
This is not a scenario anyone should want. The only party that actually benefits from it is the one who finds the key. Everyone else loses.
|
|
|
|
|
What are you on about, the guy just wants to protect his code (naive I know but understandable).
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Just exploring the hypothetical scenario of protectable code.. I hope he (or anyone else who reads it) never thinks of it as a Good Thing again.
|
|
|
|
|
I Want that My logic in my dll file should be hidden just.
|
|
|
|
|
There's no need to shout. However, a point to consider - it's pretty much impossible to hide your logic. If someone is determined enough, they will be able to get access to it. Even obfuscation only does so much - one of the biggest weaknesses of managed languages is the ease with which they can be reverse engineered.
|
|
|
|
|
Then don't use a managed language in .NET. This includes F#, C#, VB.NET, ...
Use C/C++ and it'll compile to a native code library. This STILL won't protect your logic but it will make it much more difficult to reverse engineer over going with managed code.
|
|
|
|
|
Hello
Does anybody know useful links in order to download sample code :
.net and sedna xml database & exist-db?
Many thanks.
|
|
|
|
|
|
Thanks , But i need sample code and crud operation.
|
|
|
|
|
Then I am afraid that you will have to go and search for it yourself; we don't know what code you are looking for.
Veni, vidi, abiit domum
|
|
|
|
|
I have problem regrading C# to PHP communication. I have read many old posts here and after that i came to conclusion that i have to Use PHP SOAP Web service on server side to get interaction with c#.
Here is the code which i tried:
//webservice.php
configureWSDL('webservice', 'urn:webservice');
$server->register('getMessage',array('msg'=>'xsd:string'),array('return'=>'xsd:null'));
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA)? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
//notify.php which containing function which is registered with webservice
//member.php getting message and displaying it. This will be message i want from C# code when ever i //click the button.
In 2nd part in Visual Studio 2012 i added web service reference of WSDL file correctly, and written following code for a button.
//c# code
private void button1_Click(object sender, EventArgs e)
{
localhost.webservice src = new localhost.webservice();
src.getMessage("Hello");
}
But when ever i click button and i saw member.php page nothing happens.????????
Still it showing "temp". I want this "Hello" should be shown whenever i click button.
Any help please?? I am worried wasted my whole week to learn this and now have limited time for my project. I shall be very thankful to you.
Regards,
|
|
|
|
|
Hi, I am making a software,in that want to change month of a datetimepicker using a textbox.
i.e. as i put 15 in textbox the value of the month of a datetimepicker is increased by 15months.
like current date is 05/10/2013
and when i put 15 in a text box...the value of datetimepicker is increased by 05/01/2015.
thanks..
waiting for your reply..
|
|
|
|
|
In the code that handles the change value event (you do not say what your UI is so I can't guess) you increment the datetimepicker value by textbox.text value in months
datetimepicker.value.addmonths((int)TextBox.Text)
[edit] Alright, alright use parse ot tryparse to convert the text value to an int! [/edit]
Never underestimate the power of human stupidity
RAH
|
|
|
|