Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Train Carriage Game Solutions

Name: Anonymous 2012-08-26 2:11

I'm looking to program a function that can check if you can "make 10" from some 4 digit number (0000 to 9999).

The function should use these rules when performing the check:
https://www.facebook.com/pages/Train-Carriage-Game/108348062559174?sk=info

Does /prog/ know if there's a simple way to perform such a check short of checking every combination individually? I obviously don't want to be writing the following:


boolean makesTen (int a, int b, int c, int d) {
    if (a + b + c + d == 10) {
        return true;
    } else if (-a + b + c + d == 10) {
        return true;
    } else if (a - b + c + d == 10) {
        return true;
    }
    ...
    ...
    } else {
        return false;
    }
}

Name: Eduardo 2012-08-29 13:39

>>39 here
I realised I was making a mistake in evaluating expressions of the form:

-a^b


I was evaluating it as

(-a)^b

instead of

-(a^b)


The latter method allows me to take advantage of the way a carriage number (and it's sign -- +ve or -ve) is permuted, because

(b mod 2)==2

will always be positive.

I now think 9161 of 10000 carrage numbers from 0000 to 9999 make 10. Although (this time) I'm highly confident in my answer, I'd like someone else to confirm. The reason I'm confident in my answer is because the answers in the "cheat sheet" (http://tinyurl.com/everyfuckingsolution) seem reasonable. I also checked that the same 9161 carriage numbers make -10, though this could just mean I'm making the same mistake twice. (If a carriage number can make n, it can also make -n, right?)

Another thing. I was able to check (and show answers to) all 10000 carriage numbers in 4 minutes and a half on an stock i7 950. Can anybody check more than 37 solutions per second?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List