Created
February 4, 2015 04:44
-
-
Save ayberk/8170cb232f5ac5401389 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
/** | |
* Created by ayberk on 2/3/15. | |
*/ | |
public class sdfsf | |
{ | |
private static ArrayList<String> combs = new ArrayList<String>(); | |
public static void setCombs(String initial) { | |
setCombHelper(initial.toCharArray()); | |
} | |
private static void setCombHelper(char[] pattern) { | |
int first = leftMostUnknown(pattern); | |
if (first < 0) { | |
combs.add(new String(pattern)); | |
return; | |
} | |
pattern[first] = '0'; | |
setCombHelper(pattern.clone()); | |
pattern[first] = '1'; | |
setCombHelper(pattern.clone()); | |
} | |
private static int leftMostUnknown(char[] pattern) | |
{ | |
for (int i=0; i<pattern.length; i++) { | |
if (pattern[i] == '?') { | |
return i; | |
} | |
} | |
return -1; | |
} | |
public static void main(String[] args) | |
{ | |
String s = "01010?101?"; | |
setCombs(s); | |
for (String x : combs) { | |
int foo = Integer.parseInt(x, 2); | |
System.out.println(x + ": "+ foo); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment