Skip to content

Instantly share code, notes, and snippets.

@h2rashee
Created August 15, 2016 06:56
Show Gist options
  • Save h2rashee/dd7051122fea712677cb16fe276e02bd to your computer and use it in GitHub Desktop.
Save h2rashee/dd7051122fea712677cb16fe276e02bd to your computer and use it in GitHub Desktop.
Given a list of bases for individual digit positions, find all possible numbers in that system
// Given digits,
public void calculateNumberSystem(int[] bases) {
int[] num = new int[bases.length];
HashSet<String> nums = new HashSet<String>();
for(int i = bases.length-1; i >= 0; i--) {
// Add result to set
nums.add(Arrays.toString(num));
if(num[i]+1 < bases[i]) {
num[i] = num[i] + 1;
} else {
num[i] = 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment