Skip to content

Instantly share code, notes, and snippets.

@leons727
leons727 / FortyPounds.java
Created October 31, 2011 01:58
Solution: http://beust.com/weblog/2011/10/30/a-new-coding-challenge (updated using some ideas from other comments)
public class FortyPounds {
static final int[] s = {-1, 0, 1};
public static void main(String[] args) {
for (int w1 = 1; w1 <= 37; w1++)
for (int w2 = 1; w2 <= 38 - w1; w2++)
W3: for (int w3 = 1; w3 <= 39 - w1 - w2; w3++) {
int w4 = 40 - w1 - w2 - w3;
W: for (int w = 1; w <= 40; w++) {