## How to define combinations of a factorial in Mendix (following a Java code)?

0
Hi guys,   I am wondering how I can build the following Java code in Mendix (without using Java code): /****************************************************************************** * Compilation: javac Permutations.java * Execution: java Permutations n * * Enumerates all permutations on n elements. * Two different approaches are included. * * % java Permutations 3 * abc * acb * bac * bca * cab * cba * ******************************************************************************/ public class Permutations { // print n! permutation of the characters of the string s (in order) public static void perm1(String s) { perm1("", s); } private static void perm1(String prefix, String s) { int n = s.length(); if (n == 0) StdOut.println(prefix); else { for (int i = 0; i < n; i++) perm1(prefix + s.charAt(i), s.substring(0, i) + s.substring(i+1, n)); } } // print n! permutation of the elements of array a (not in order) public static void perm2(String s) { int n = s.length(); char[] a = new char[n]; for (int i = 0; i < n; i++) a[i] = s.charAt(i); perm2(a, n); } private static void perm2(char[] a, int n) { if (n == 1) { StdOut.println(new String(a)); return; } for (int i = 0; i < n; i++) { swap(a, i, n-1); perm2(a, n-1); swap(a, i, n-1); } } // swap the characters at indices i and j private static void swap(char[] a, int i, int j) { char c = a[i]; a[i] = a[j]; a[j] = c; } public static void main(String[] args) { int n = Integer.parseInt(args[0]); String alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; String elements = alphabet.substring(0, n); perm1(elements); StdOut.println(); perm2(elements); } } What I have done till now is: 1) creating variables: n, prefix, str, i, 2) created a permutationToSaveList (object of Permutation) 3) create new permutation, whereby permutation.string is : \$prefix+substring(\$NewPermutation/String,\$i,\$i)+'.'+ substring(\$NewPermutation/String,0,\$i)+ substring(\$NewPermutation/String,\$i+1,(if (\$i+1+\$n) >length(\$NewPermutation/String) then length(\$NewPermutation/String)-\$i-1 else \$n) ) 4) add newpermutation to permutationsToSaveList 5) change i: \$i + 1 Result: error on 4 after several iterations. I think i make mistake by creating perm1 and perm2. Can anyone advice me how to do this in Mendix?