Created
August 15, 2016 06:56
-
-
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
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
// 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