Skip to content

Instantly share code, notes, and snippets.

@robmoore
Created October 9, 2018 21:42
Show Gist options
  • Save robmoore/a829b870f289845a70d157d9b7d0fa32 to your computer and use it in GitHub Desktop.
Save robmoore/a829b870f289845a70d157d9b7d0fa32 to your computer and use it in GitHub Desktop.
Can calculate count of odd integer partitions
public class PartitionCounter {
public static void main(String[] args) {
// System.out.print("[");
// for (int k = 0; k < 201; k++) {
// System.out.print(count(k) + (k != 200 ? ", " : ""));
// }
// System.out.print("]");
System.out.println("11: " + count(11));
}
private static int count(int x) {
if (x < 3) {
return 0;
}
int f[] = new int[x + 1];
f[0] = 1;
f[1] = 1;
for (int n = 2; n <= x; n++) {
for (int k = x; k > n - 1; k--) {
f[k] += f[k - n];
}
}
return f[x] - 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment