add to 100

Problem (Project Euler 76)

It is possible to write five as a sum in exactly six different ways:

4 + 1
3 + 2
3 + 1 + 1
2 + 2 + 1
2 + 1 + 1 + 1
1 + 1 + 1 + 1 + 1

How many different ways can one hundred be written as a sum of at least two positive integers?

Code

public class ProjectEuler {
    public static void main(String[] args) {
        int num = 100;
        System.out.println("Results for euler(" + num +") " + eulerStep(num, num - 1));
    }

    public static int eulerStep(int value, int lastUsed){
        int total = 0;
        if (value == 0){
            return 1;
        }
        for (int i = Math.min(value, lastUsed); i >= 1;i--) {
            total += eulerStep(value - i, i);
        }
        return total;
    }
}

Explanation

coming soon

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License