Generate all permutations of a certain length  no repeating characters
I am trying to use recursion to find all n length permutations of a 6letter string.
Given the string "abcd" and n = 3 it'd generate abc, abd, acd, acb, adb, adc, bcd, bca, bac, bad, bda, bdc, etc.
My code currently only generates all string length permutations
static void printPermutn(String str, String ans)
{
if (str.length() == 0)
{
System.out.println(ans);
return;
}
for (int i = 0; i < str.length(); i++)
{
char ch = str.charAt(i);
String ros = str.substring(0, i) +
str.substring(i + 1);
printPermutn(ros, ans + ch);
}
}
See also questions close to this topic

Independent java files running in standalone program
I am building a JavaFX application to be used by nonprogramming people and the goal is to download data from websites with one click only. The idea behind the process is:
 the program shows a list of bookmarks:
 each bookmark has a title, a description and a filename (all strings)
 the user selects the bookmark (select title on the ListView)
 the next step would be clicking a download button
The idea is also to add bookmarks (with each bookmark running a new Selenium session) along the way.
You can check here the screenshot of the program
I need to run independent class file with having dependecy with selenium and other lib.
Can Jython be a solution?
Am I being explicit enough?
Thanks in advance.
 the program shows a list of bookmarks:

How can I get the value of the 'Array of JTextField' and store it in an Array Integer?
I have two arrays of JTextField and I want to store it into another array.
JTextField[] proText, atText; int[] burst, arrive;
I have tried the usual way of the passing the value of the array
while(true){ if(atText[lowerBound].getText() != " " && proText[lowerBound].getText() != " "){ bt = proText[lowerBound].getText(); at = atText[lowerBound].getText(); burst[lowerBound] = Integer.parseInt(bt); arrive[lowerBound] =Integer.parseInt(at); break; }else break; }
***the 'lowerBound' is being incremented when I click the button.
BTW this is dynamic, in which it adds another JTextField when I am clicking the button. The problem here is that only the last number is displayed and the rest are zero. Is there another way to get the value of JTextField?

Converting private class from Kotlin to Java via bytecode
When the Kotlin code is compiled into Java byte code what happens with private class. I ask it, because private classes are absent in Java.

How to sum all elements in a nested array?
this is an array which is given:
let arrayNumbers = [ 5, 7, [ 4, [2], 8, [1,3], 2 ], [ 9, [] ], 1, 8 ];
and the output must be
50
This code must be WITHOUT Array.isArray;
let sum = 0; function treeSum(array) { for (let i = 0; i < array.length; i++) { if (array[i] === false) { treeSum(array[i]); } else { sum += array[i]; } } return sum; } treeSum(arrayNumbers);
Help, please with an idea or code, thanks.

For how much time will this recursive function run before crashing?
void func(){ func(); }
This is an interview question for Java backed developer role. There is no memory allocation for pushing data for each call. What will trigger the crash and in how much time?

Why is my recursion leading to self referencing dict values?
I aim to write a function that splits a budget across options by comparing options based on their benefit/cost ratio and stores them in a list of nested dicts. When multiple options with the same benefit/cost ratio are available, each option shall be pursued separately (as downstream element which in turn may have multiple downstream elements) and reflected as a list of dicts for its upstream dict. There is no limitation as to how many options may occur.
def get_all_allocation_proposals(budget, options, upstream_element=dict()): # accepts: # budget to be allocated # list of options # returns: # a list of allocation proposals # filter options for affordable options and sort by cost benefit ratio options = [x for x in options if x['cost'] <= budget] options = sorted(options, key=lambda x: ( x['benefit_cost_ratio'], x['benefit']), reverse=True) if (len(options) > 0): # select the best options best_bc_ratio = options[0]['benefit_cost_ratio'] best_options = [ x for x in options if x['benefit_cost_ratio'] == best_bc_ratio] upstream_element['downstream_elements'] = [] for current_element in best_options: downstream_options = remove_conflicting_options( current_element, options) downstream_budget = budget  current_element['cost'] current_element['donstream_budget'] = downstream_budget downstream_elements = get_all_allocation_proposals(downstream_budget, downstream_options, current_element) if downstream_elements is not None: current_element['downstream_elements'] = downstream_elements upstream_element['downstream_elements'].append(current_element) return upstream_element else: return None
In the code above, when the elements are appended, self referencing dict values are created. Why is that the case and how can I avoid that? All I want to do is to pass on all downstream elements to the first call stack. Is there something fundamentally flawed with my recursion pattern?

How to iterate over all unique permutations of a sequence in Rust?
Given a list of values, such as
vec![0, 0, 1, 2]
, I would like to create an iterator generates all of its unique permutations. That is,[0, 0, 1, 2] [0, 0, 2, 1] [0, 1, 0, 2] [0, 1, 2, 0] [0, 2, 0, 1] [0, 2, 1, 0] [1, 0, 0, 2] [1, 0, 2, 0] [1, 2, 0, 0] [2, 0, 0, 1] [2, 0, 1, 0] [2, 1, 0, 0]
(Note that there are 12 different permutations, while if we had 4 distinct elements, there would be 24 different permutations).
There is already a way to generate permutations (as well as other iterators like combinations or combinations without replacements) using the itertools package, but for permutations, there is no way to limit the permutations to only those that are unique.
There is a fairly efficient algorithm for generating permutations in general known as Heap's Algorithm, however this does not take into account the equality / duplicity of values.
This problem is not too tricky to implement in languages with generators, such as Python, but I feel like this is more tricky in Rust (at least compared to the solution above), since it would require using iterators (which must maintain internal state), or using generators (which are currently unstable).

Get all unique combinations of a nested object
I want to run multiple backtests on certain stock data. I want to do this by generating an array of strategy options that I will pass to a backtest function.
In the object below I can define values as arrays so that multiple combinations of strategies will be formed.
The amount of combinations of [0,1] and [2,3] is 4, that's why my output array will consist of 4 strategy objects.
To illustrate, this is my (simplified) input:
const backtestSettings = { stopLoss: [5], bands: [ { timeframe: 1, openMinVolatility: [0,1], }, { timeframe: 5, openMinVolatility: [2,3], }, { timeframe: 15, openMinVolatility: [0], }, { timeframe: 30, openMinVolatility: [0], } ] };
And I am trying to get this as my output:
[ { stopLoss: 5, bands: [ { timeframe: 1, openMinVolatility: 0 }, { timeframe: 5, openMinVolatility: 2 }, { timeframe: 15, openMinVolatility: 0 }, { timeframe: 30, openMinVolatility: 0 } ] }, { stopLoss: 5, bands: [ { timeframe: 1, openMinVolatility: 1 }, { timeframe: 5, openMinVolatility: 2 }, { timeframe: 15, openMinVolatility: 0 }, { timeframe: 30, openMinVolatility: 0 } ] }, { stopLoss: 5, bands: [ { timeframe: 1, openMinVolatility: 0 }, { timeframe: 5, openMinVolatility: 3 }, { timeframe: 15, openMinVolatility: 0 }, { timeframe: 30, openMinVolatility: 0 } ] }, { stopLoss: 5, bands: [ { timeframe: 1, openMinVolatility: 1 }, { timeframe: 5, openMinVolatility: 3 }, { timeframe: 15, openMinVolatility: 0 }, { timeframe: 30, openMinVolatility: 0 } ] } ]
Question: How do I convert my input to the desired output? (I've spent days trying a lot of different things)
Bonus: I have something working without the bands (the fact that it is nested makes things complicated for me) by chaining some forEach functions, but in reality the amount of options is substantial, which makes my code really long and unreadable. So I'm hoping that there is a solution that can also accept an arbitrary amount of options instead of chaining forEach functions.

netsted loops in VBA acting weird
Hello i am trying to do permutation of some patterns. every pattern have 4 variables and i am trying so groupe which ones matches bases on criterias.
The problem is special when the calculation reaches "sheet 4" and "sheet 5" :
1 Sheet 4 : Showing Nothing at all, The results that should be in "Sheet 4" are shown in Sheet 5
2 Sheet 5 : that results here belongs to "Sheet 4", the results belongings to "sheet 5" are not shown. AND even the results of "sheet 4" are incorrect as i i am getting a long list of data, then a long list of blank rows, then long list of data, then long list of blank rows again.
Please any suggestions what i am doing wrong ? do i need to activate sheets ?
Sub Permutation() Dim z As Long Dim x As Long Dim y As Long Dim count As Long Dim name As String Dim wbB As Variant Application.ScreenUpdating = False Application.EnableEvents = False Set shA1 = Workbooks("template.xlsx").Sheets("139") Set shA2 = Workbooks("template.xlsx").Sheets("Middel") '======================================================= For z = 1 To 1 name = CStr(shA1.Cells(z, "F")) Set wbB = Workbooks.Add wbB.SaveAs Filename:="C:\....." & name DoEvents Dim shB As Worksheet Dim shC As Worksheet Dim shD As Worksheet Dim shE As Worksheet Dim shF As Worksheet Set shB = wbB.Sheets("Sheet1") Set shC = wbB.Sheets("Sheet2") Set shD = wbB.Sheets("Sheet3") Set shE = wbB.Sheets.Add(After:=shD) Set shE = wbB.Sheets("Sheet4") Set shF = wbB.Sheets.Add(After:=shE) Set shF = wbB.Sheets("Sheet5") '=============================================================== 'PHASE I  SHEET 1 shB.Range("A1:F1").Merge shB.Range("G1:L1").Merge shB.Range("A1:L1") = Array("Unique Piece", "", "", "", "", "", "Middel Pieces") shB.Range("A2:L2") = Array("Up", "Right", "Down", "Left", "P", "P R", "Up", "Right", "Down", "Left", "P", "P R") shB.Range("A1:L10000").HorizontalAlignment = xlCenter shB.Range("A1:L2").Font.Bold = True shA1.Range("A" & z, "F" & z).Copy shB.Range("A3") shA2.Activate shA2.Range("A1:F" & Cells(rows.count, "A").End(xlUp).row).Copy shB.Range("G3") '============================================================= 'PHASE I  SHEET 2 shC.Range("A1:C1").Merge shC.Range("D1:F1").Merge shC.Range("G1:I1").Merge shC.Range("J1:L1").Merge shC.Range("A1:L1") = Array("MPiece & UPiece (H)", "", "", "UPiece & MPiece (H)", "", "", "MPiece & UPiece (V)", "", "", "UPiece & MPiece (V)", "", "") shC.Range("A2:L2") = Array("P1P4", "P1 R", "P4 R", "P4P3", "P4 R", "P3 R", "P2P4", "P2 R", "P4 R", "P4P5", "P4 R", "P5 R") shC.Range("A1:L10000").HorizontalAlignment = xlCenter shC.Range("A1:L2").Font.Bold = True Middel_Piece = shB.Cells(rows.count, "G").End(xlUp).row Unique_Piece = 3 count = 3 For x = 3 To Middel_Piece For y = 3 To Unique_Piece If (shB.Cells(x, "H") = shB.Cells(y, "D")) Then If shB.Cells(x, "F") <> shB.Cells(y, "L") Then shC.Cells(count, "A") = shB.Cells(x, "K") & shB.Cells(y, "E") shC.Cells(count, "B") = shB.Cells(x, "L") shC.Cells(count, "C") = shB.Cells(y, "F") count = count + 1 End If End If Next y Next x count = 3 For x = 3 To Unique_Piece For y = 3 To Middel_Piece If (shB.Cells(x, "B") = shB.Cells(y, "J")) Then If shB.Cells(y, "L") <> shB.Cells(x, "F") Then shC.Cells(count, "D") = shB.Cells(x, "E") & shB.Cells(y, "K") shC.Cells(count, "E") = shB.Cells(x, "F") shC.Cells(count, "F") = shB.Cells(y, "L") count = count + 1 End If End If Next y Next x count = 3 For x = 3 To Middel_Piece For y = 3 To Unique_Piece If (shB.Cells(x, "I") = shB.Cells(y, "A")) Then If shB.Cells(x, "F") <> shB.Cells(y, "L") Then shC.Cells(count, "G") = shB.Cells(x, "K") & shB.Cells(y, "E") shC.Cells(count, "H") = shB.Cells(x, "L") shC.Cells(count, "I") = shB.Cells(y, "F") count = count + 1 End If End If Next y Next x count = 3 For x = 3 To Unique_Piece For y = 3 To Middel_Piece If (shB.Cells(x, "C") = shB.Cells(y, "G")) Then If shB.Cells(y, "L") <> shB.Cells(x, "F") Then shC.Cells(count, "J") = shB.Cells(x, "E") & shB.Cells(y, "K") shC.Cells(count, "K") = shB.Cells(x, "F") shC.Cells(count, "L") = shB.Cells(y, "L") count = count + 1 End If End If Next y Next x '================================================================================= 'PHASE III  SHEET 3 shD.Range("A1:D1").Merge shD.Range("E1:H1").Merge shD.Range("A1:H1") = Array("MPiece & UPiece & LPiece (H)", "", "", "", "MPiece & UPiece & LPiece (V)", "", "", "") shD.Range("A2:H2") = Array("P1  P4  P3", "P1 R", "P4 R", "P3 R", "P2P4P5", "P2 R", "P4 R", "P5 R") shD.Range("A1:H10000").HorizontalAlignment = xlCenter shD.Range("A1:H2").Font.Bold = True Middel_unique_H = shC.Cells(rows.count, "A").End(xlUp).row Unique_middel_H = shC.Cells(rows.count, "D").End(xlUp).row Middel_unique_V = shC.Cells(rows.count, "G").End(xlUp).row Unique_middel_V = shC.Cells(rows.count, "J").End(xlUp).row count = 3 For x = 3 To Middel_unique_H For y = 3 To Unique_middel_H If shC.Cells(x, "B") <> shC.Cells(y, "F") Then shD.Cells(count, "A") = Left(shC.Cells(x, "A"), 3) & shC.Cells(y, "D") shD.Cells(count, "B") = shC.Cells(x, "B") shD.Cells(count, "C") = shC.Cells(y, "E") shD.Cells(count, "D") = shC.Cells(y, "F") count = count + 1 End If Next y Next x count = 3 For x = 3 To Middel_unique_V For y = 3 To Unique_middel_V If shC.Cells(x, "H") <> shC.Cells(y, "L") Then shD.Cells(count, "E") = Left(shC.Cells(x, "G"), 3) & shC.Cells(y, "J") shD.Cells(count, "F") = shC.Cells(x, "H") shD.Cells(count, "G") = shC.Cells(y, "K") shD.Cells(count, "H") = shC.Cells(y, "L") count = count + 1 End If Next y Next x '================================================================================= 'PHASE VI  SHEET 4 shE.Range("A1:E1").Merge shE.Range("A1:E1") = Array("M1M2M3M5", "") shE.Range("A2:E2") = Array("P1  P2  P3  P5", "P1 R", "P2 R", "P3 R", "P5 R") shE.Range("A1:E10000").HorizontalAlignment = xlCenter shE.Range("A1:E2").Font.Bold = True Horizontal = shD.Cells(rows.count, "A").End(xlUp).row Vertical = shD.Cells(rows.count, "E").End(xlUp).row count = 3 For x = 3 To Horizontal For y = 3 To Vertical If ((shD.Cells(x, "B") <> shD.Cells(y, "F")) And (shD.Cells(x, "B") <> shD.Cells(y, "H"))) Then If ((shD.Cells(x, "D") <> shD.Cells(y, "F")) And (shD.Cells(x, "D") <> shD.Cells(y, "H"))) Then shE.Cells(count, "A") = Left(shD.Cells(x, "A"), 3) & "" & Left(shD.Cells(y, "E"), 3) & "" & Right(shD.Cells(x, "A"), 3) & "" & Right(shD.Cells(y, "E"), 3) shE.Cells(count, "B") = shD.Cells(x, "B") shE.Cells(count, "C") = shD.Cells(y, "F") shE.Cells(count, "D") = shD.Cells(x, "D") shE.Cells(count, "E") = shD.Cells(y, "H") End If End If count = count + 1 Next y Next x '================================================================================= 'PHASE V  SHEET 5 shF.Range("A1:E10000").HorizontalAlignment = xlCenter shF.Range("A1:E2").Font.Bold = True rows = shE.Cells(rows.count, "A").End(xlUp).row count = 3 For x = 3 To rows shF.Cells(count, "A") = shE.Cells(x, "B") & shE.Cells(x, "C") shF.Cells(count, "B") = shE.Cells(x, "C") & shE.Cells(x, "D") shF.Cells(count, "C") = shE.Cells(x, "D") & shE.Cells(x, "E") shF.Cells(count, "D") = shE.Cells(x, "E") & shE.Cells(x, "B") count = count + 1 Next x 'wbB.Close SaveChanges:=True Next z DoEvents Application.EnableEvents = True Application.ScreenUpdating = True End Sub