Permutation algorithm without recursion? Java

You should use the fact that when you want all permutations of N numbers there are N! possibilities. Therefore each number x from 1..N! encodes such a permutation. Here is a sample that iteratively prints out all permutations of a sting. private static void printPermutationsIterative(String string){ int [] factorials = new int[string.length()+1]; factorials[0] = 1; … Read more

Generate tail call opcode

C# compiler does not give you any guarantees about tail-call optimizations because C# programs usually use loops and so they do not rely on the tail-call optimizations. So, in C#, this is simply a JIT optimization that may or may not happen (and you cannot rely on it). F# compiler is designed to handle functional … Read more

What’s the reason of ‘let rec’ for impure functional language OCaml?

When you define a semantics of function definition, as a language designer, you have choices: either to make the name of the function visible in the scope of its own body, or not. Both choices are perfectly legal, for example C-family languages being far from functional, still do have names of definitions visible in their … Read more

How can I recursively delete folder with a specific name with PowerShell?

This one should do it: get-childitem -Include .svn -Recurse -force | Remove-Item -Force -Recurse Other version: $fso = New-Object -com “Scripting.FileSystemObject” $folder = $fso.GetFolder(“C:\Test\”) foreach ($subfolder in $folder.SubFolders) { If ($subfolder.Name -like “*.svn”) { remove-item $subfolder.Path -Verbose } }

Java 8: Copy directory recursively?

In this way the code looks a bit simpler import static java.nio.file.StandardCopyOption.*; public void copyFolder(Path src, Path dest) throws IOException { try (Stream<Path> stream = Files.walk(src)) { stream.forEach(source -> copy(source, dest.resolve(src.relativize(source)))); } } private void copy(Path source, Path dest) { try { Files.copy(source, dest, REPLACE_EXISTING); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } … Read more

Recursively compare two directories to ensure they have the same files and subdirectories

Here’s an alternative implementation of the comparison function with filecmp module. It uses a recursion instead of os.walk, so it is a little simpler. However, it does not recurse simply by using common_dirs and subdirs attributes since in that case we would be implicitly using the default “shallow” implementation of files comparison, which is probably … Read more