integer to string conversion / integerstring concatenation in C++  more compact solutions?
By : smack081
Date : March 29 2020, 07:55 AM
This might help you How to do integer > string conversion has been answered many times on the internet... however, I'm looking for the most compact "C++way" to do this.

Using Python to Find Integer Solutions to System of Linear Equations
By : Štefan Lacko
Date : March 29 2020, 07:55 AM
will be helpful for those in need You can use Numpy Linear Algebra to solve a system of equations, the leastsquares solution to a linear matrix equation. In your case, you can consider the following vectors: code :
import numpy as np
# range(T): coefficients of the first equation
# np.ones(T): only 'ones' as the coefficients of the second equation
A = np.array([range(T), np.ones(T)) # Coefficient matrix
B = np.array([a, b]) # Ordinate or “dependent variable” values
x = np.linalg.lstsq(A, B)[0]
import numpy as np
def solve(T, a, b):
A = np.array([range(T), np.ones(T)])
B = np.array([a, b])
return np.linalg.lstsq(A, B)[0]

how to find all integer solutions to sum(xi) =b, with linear constraints
By : Rpitre
Date : March 29 2020, 07:55 AM
will be helpful for those in need Recursion is best. Here is the natural Python solution with generators: code :
def solutions(variables, sum_left, max_value):
if 0 == variables:
if 0 == sum_left:
yield []
else:
for i in range(0, max_value + 1):
if sum_left < i:
break
else:
for partial_solution in solutions(variables  1, sum_left  i,
max_value):
yield [i] + partial_solution
for x in solutions(10, 10, 2):
print(x)
def do_something_for_solutions(variables, sum_left, max_value, known=None):
if known is None:
known = []
if 0 == variables:
if 0 == sum_left:
do_something(known)
else:
for i in range(0, max_value + 1):
if sum_left < i:
break
else:
do_something_for_solutions(variables  1, sum_left  i,
max_value, known + [i])
def do_something(solution):
print(solution)
do_something_for_solutions(10, 10, 2)
def solutions(variables, sum_left, max_value):
if 0 == variables:
if 0 == sum_left:
return [[]]
else:
return []
else:
answer = []
for i in range(0, max_value + 1):
if sum_left < i:
break
else:
for partial_solution in solutions(variables  1, sum_left  i,
max_value):
answer.append([i] + partial_solution)
return answer
for x in solutions(10, 10, 2):
print(x)

How to find all positive integer solutions to an cubic equation?
By : anchordown
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further You can group by all the possible sums and print out groups which contain more than one item. This is O(N**2) algorithm: code :
// key is sum and value is a list of representations
Dictionary<int, List<Tuple<int, int>>> solutions =
new Dictionary<int, List<Tuple<int, int>>>();
for (int a = 1; a <= 1000; ++a)
for (int b = a; b <= 1000; ++b) {
int sum = a * a * a + b * b * b;
List<Tuple<int, int>> list = null;
if (!solutions.TryGetValue(sum, out list)) {
list = new List<Tuple<int, int>>();
solutions.Add(sum, list);
}
list.Add(new Tuple<int, int>(a, b));
}
String report = String.Join(Environment.NewLine,
solutions.Values
.Where(list => list.Count > 1) // more than one item
.Select(list => String.Join(", ",
list.Select(item => String.Format("({0}, {1})", item.Item1, item.Item2)))));
Console.Write(report);
(1, 12), (9, 10)
(1, 103), (64, 94)
(1, 150), (73, 144)
(1, 249), (135, 235)
(1, 495), (334, 438)
...
(11, 493), (90, 492), (346, 428) // < notice three representations of the same sum
...
(663, 858), (719, 820)
(669, 978), (821, 880)
(692, 942), (720, 926)
(718, 920), (816, 846)
(792, 901), (829, 870)
1**3 + 12**3 == 9**3 + 10**3
...
11**3 + 493**3 == 90**3 + 492**3 == 346**3 + 428**3
...
792**3 + 901**3 == 829**3 + 870**3
(11, 493), (90, 492), (346, 428)
(15, 930), (198, 927), (295, 920)
(22, 986), (180, 984), (692, 856)
(70, 560), (198, 552), (315, 525)
(111, 522), (359, 460), (408, 423)
(167, 436), (228, 423), (255, 414)
(300, 670), (339, 661), (510, 580)
(334, 872), (456, 846), (510, 828)

Find integer solutions to a set of equations with more unknowns than equations
By : Abhishek Kundu
Date : March 29 2020, 07:55 AM

