3
\$\begingroup\$
bool doYouFeelLuckyPunk, actuallyIsLucky;
doYouFeelLuckyPunk = Harry.catchyPhrase();
actuallyIsLucky = Bandit.rollDice();
if(doYouFeelLuckyPunk) {
    Bandit.grabGun();
    if(!actuallyIsLucky)
        Harry.useMagnum()
    else {
        Harry.tisButAScratch()
    }
else
    Bandit.surrender();

We all know how this plays out and we like it that way.
The task:
Write functions

bool Harry.catchyPhrase()

bool Bandit.rollDice()

Design them so the situation ends either in Harry.uswMagnum() or Bandit.surrender(), at random. Challenge and key criterion: Obfuscate the fact that bandit cannot win, fake and manipulate the "randomness" in your functions. The less obvious the better of course.
Explain your manipulation in a non-spoilering way (white text etc.)
Language: Doesn't matter Forbidden moves: none

\$\endgroup\$
  • 1
    \$\begingroup\$ I'm afraid this doesn't qualify as a code-trolling, but it's an interesting challenge nevertheless. \$\endgroup\$ – John Dvorak Jan 14 '14 at 7:05
  • \$\begingroup\$ @JanDvorak yeah, I just re-read the description of CT and removed the tag. \$\endgroup\$ – Mark Jan 14 '14 at 7:09
  • 1
    \$\begingroup\$ So the challenge essentially equates to producing two booleans such that: both being true is impossible, while making it look like both can be true? \$\endgroup\$ – Cruncher Jan 14 '14 at 13:53
  • \$\begingroup\$ @Cruncher Indeed. Make it look like there was an equal (or at least existing) chance for any of the 4 possible outcomes, but true-true mustn't occur. \$\endgroup\$ – Mark Jan 15 '14 at 6:09
  • 3
    \$\begingroup\$ I'm voting to close this question as off-topic because this is a underhanded question which are now considered off-topic. \$\endgroup\$ – Ad Hoc Garf Hunter Aug 3 '17 at 17:01
3
\$\begingroup\$

How about this? Solution at the very bottom, encoded in base64. Language is C.

#include <stdio.h>
int lfsr = 0xACE1u;
/*Toy LFSR implementation stolen from wikipedia.*/
int random_bit(){
    /* taps: 16 14 13 11; feedback polynomial: x^16 + x^14 + x^13 + x^11 + 1 */
    int bit  = ((lfsr >> 0) ^ (lfsr >> 1) ^ (lfsr >> 3) ^ (lfsr >> 5) )&1 ;
    lfsr =  (lfsr >> 1) | (bit << 15);
    return ((lfsr >> 14)&(lfsr >> 15))^bit;
}
int surrendered=0,scratched=0,shot =0;

void harry_tis_but_a_scratch(){scratched++;}
int harry_catchy_phrase(){return random_bit();}
void bandit_surrender(){surrendered++;}
void harry_use_magnum(){shot++;}
int bandit_roll_dice() {return random_bit();}
void bandit_grab_gun() {}

int main()
{
    int random_number=0;
    /*Test bench random bit*/
    for(int y=1;y<51;++y){
        for(int x=0;x<8*sizeof(int);++x)random_number= (random_number<<1)|random_bit();
        printf("%-15d%c",random_number,y%5?' ':'\n');
    }
    printf("\nLooks pretty random\n\n");
    /*Play the game*/
    for(int x=0;100000 >=++ x;){
        int doYouFeelLuckyPunk = harry_catchy_phrase();
        int actuallyIsLucky = bandit_roll_dice();
        if(doYouFeelLuckyPunk) {
            bandit_grab_gun();
            if(!actuallyIsLucky) harry_use_magnum();
            else harry_tis_but_a_scratch();
        }else bandit_surrender();
    }
    printf("Shot: %d Surrendered: %d  Scratched: %d\n",shot,surrendered,scratched);
    return 0;
}
/*
                               Example Output
   1414529544,  -2071427967,     89395234,    690094340,    704663586,
     41977888,  -1572861663,   1107591810,    143171844,    546578948,
  -1542942712,  -1600056768,  -1571682240,     84415044,  -2138746864,
    705971264,    302123561,    168036485,    553717833,    545294674,
     71909648,  -1994096044,   1426227848,   1218611781,    138707496,
     16810505,    553783616,  -1861155808,  -1803283192,   1111626024,


Looks pretty random

Shot: 24941 Surrendered: 75059  Scratched: 0

                                  SOLUTION

IFRoZSB3YXkgdGhpcyB3b3JrcyBpcyBxdWl0ZSBzaW1wbGUsIHRoZSBMRlNSIGlzIHJlYWwgYW5k
IGRvZXMgaW4gZmFjdCBnZW5lcmF0ZQ0KIGdvb2QgcHNldWRvLXJhbmRvbSBudW1iZXJzLkFuZCBp
dCBpcyBpbmZhY3QgYW4gZXhhY3QgaW1wbGVtZW50YXRpb24gb2YgdGhlIG9uZQ0KIGZyb20gd2lr
aXBlZGlhLCBleGNlcHQgZm9yIG9uZSBhZGRpdGlvbjoNCiANCiBUaGUgb3V0cHV0IGJpdCBpcyB4
b3InZCB3aXRoICgobGZzcj4+MTQpJihsZnNyPj4xNSkpDQogDQogTm9ybWFsbHkgdGhpcyBzaG91
bGRuJ3QgYmUgYSBwcm9ibGVtLCBhcyB0aGUgcmVzdWx0IG9mIGEgcmFuZG9tIGJpdCB4b3InZCB3
aXRoDQogYW55IGZ1bmN0aW9uIGJlc2lkZXMgaXRzZWxmIGlzIHNlbGYgaXMgc3RpbGwgYSByYW5k
b20gYml0Lg0KIA0KIEhvd2V2ZXIsICgobGZzcj4+MTQpJihsZnNyPj4xNSkpIGlzIG5vdCBhIG5v
cm1hbCBmdW5jdGlvbi4gRHVlIHRvIHRoZSBMRlNSIGFsc28NCiBiZWluZyBhIHNoaWZ0IHJlZ2lz
dGVyIHRoZSBvdXRwdXQgb2YgdGhlIHJhbmRvbSBiaXQgZnVuY3Rpb24gaXMgYWN0dWFsbHkgdGhp
czoNCiANCiByZXR1cm4gKGxhc3RfYml0JmJpdCleYml0Ow0KIA0KIFNvLCBpZiB0aGUgbGFzdCBi
aXQgd2FzIGEgMSB0aGUgYml0IHJldHVybmVkIGlzIGd1YXJhbnRlZWQgdG8gYmUgMC4NCiANCiBT
byBpdCBpcyBpbXBvc3NpYmxlIHRvIGdldCB0byB0aGUgJ3RpcyBidXQgYSBzY3JhdGNoJyBmdW5j
dGlvbiwgYXMNCiBpdCBpcyBpbXBvc3NpYmxlIGZvciBib3RoIGRvWW91RmVlbEx1Y2t5UHVuayBh
bmQgYWN0dWFsbHlJc0x1Y2t5IHRvIGJlIHRydWUu

*/
| improve this answer | |
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.