[Solved] Algorithm to decide if giving rest is possible

What you are asking for is a SAT algorithm and it has an exponential complexity, therefore unless you have some extra constraints you must do an exhaustive check (brute force as you said). You may be interested in the function itertools.combinations(iterable, combinations_length) to sum all possible combinations. also you can represent your elements like this: … Read more

[Solved] Find Highest Divisible Integer In Set By X

Here is an adaptation of your code that doesn’t require storing intermediate results: private Int32 GetHighest(Int32 y, out Int32 totalMax) { var Set = new Int32[] { 4, 3, 2 }; totalMax = int.MinValue; int itemMax = int.MinValue; foreach (var x in Set) { int total = x * (y / x); if(total >= totalMax … Read more

[Solved] Get the largest, average and smallest value [closed]

Since you tagged this with C++, I would use std::vector objects mixed with the std::sort() algorithm for making it easy to find these stats. Here’s a simple example. #include <algorithm> #include <iostream> #include <vector> int main() { std::vector<float> numbers = { 1, 4, 3, 2 }; std::sort(numbers.begin(), numbers.end()); // numbers = { 1, 2, 3, … Read more

[Solved] PHP: How to create a linear function, calculating a credit card fee? [closed]

I’ve got what you want, so think in this way: you have original price you want to calculate final transferAmount that: transferAmount = originalPrice + fee but fee here depends on transferAmount fee = transferAmount * 0.029 + 2.25 now solve it: transferAmount = originalPrice + transferAmount * 0.029 + 2.25 transferAmount*(1-0.029) = originalPrice + … Read more

[Solved] about log(n),how to calculate? [closed]

I think this is what you’d like to know: b^x=y x=log(y)/log(b) For b=2 and y=11 you could write something like this: x=log(11)/log(2), where b is the logarithm base, whilst y is the logarithm argument. Therefore, you can calculate any logarithm in a programming language by evaluating it to base 10 first, then dividing it by … Read more

[Solved] C# Line is horizontal

I have solved the problem using the approach proposed by @MBo taking the difference in height and length. Here is the function: public static bool? isLineVertical(Line line) { double xDiff = Math.Abs(line.X2 – line.X1); double yDiff = Math.Abs(line.Y2 – line.Y1); bool? vertical = null; if (yDiff > xDiff) { vertical = true; } else if … Read more

[Solved] how to add strings together?

You have several issues here: First of all, your string cu is declared inside the if scope. It will not exist outside that scope. If you need to use it outside the scope of the if, declare it outside. Second, math operations cannot be applied to strings. Why are you casting your numeric values to … Read more

[Solved] Select three choices (multiple choices) in C [closed]

if(choice==1,3,9 && choice2==1,3,9 && choice3==1,3,9){ if( (choice== 1 || 3 || 10) && (choice2== 1 || 3 || 10) && (choice3== 1 || 3 || 10)) //always TRUE if(choice==1,3,11 && choice2==1,3,11 && choice3==1,3,11){ Do you consider these conditions as valid syntax to behave as your needs ? Correct would be if((choice==1 ||choice==3 ||choice==9) && (choice2==1 … Read more