• (cs)

    As it turned out, Automating the Knight's Tour was a bit more difficult than I had realized. When initially researching the problem, I saw a relatively simple algorithm and figured, oh yeah, I can do that! Of course, without knowing the trick... there was no way I could have solved it in a long coffee break or lunch break. Either way, I was most impressed by DaveC's Excel VBA solution.

    And just to note, The Perch is much, much easier than the Knight's tour. For an added challenge, you can pick a new language.

  • JK (unregistered)

    ALl sounds very Fear and Loathing to me... road trip, drinking and gambling with your lawyer!

  • JoPoser (unregistered)

    3rd? I miss getting these early.

  • It Girl (unregistered) in reply to JK
    JK:
    ALl sounds very Fear and Loathing to me... road trip, drinking and gambling with your lawyer!

    Ha, and here I was flipping a coin with Guidenstern and Rosencrantz by the end of the second paragraph.... wait until he gets a load of those bats.

  • (cs)
    Like my netbook, I never like to leave town without legal representation.
    Your netbook never leaves town without legal representation? Why, is it harboring illegally obtained debit card data?
    ...drank until we were confident we’d win, and headed over to the casino.
    Wouldn't the drinks have been free if you'd gone to the casino first?
  • thnurg (unregistered)

    What the hell does quote-unquote The Law of Large Numbers mean?

    Surely that should be quote The Law of Large Numbers unquote.

    quote-unquote bothers the crap out of me. The whole point of it is to quote a phrase, but if you simply say quote-unquote before the phrase how do we know when the phrase is finished?

    This isn't grammer Nazism, it's logic Nazism.

  • (cs)

    Ok, I've got the program ready, but I'm not sure where exactly to place my CasinoEmployeesTakeYouToALittleBasementRoomAndSweatYouException

  • 50% Opacity (unregistered) in reply to thnurg
    thnurg:
    What the hell does quote-unquote The Law of Large Numbers mean?

    Especially when you can actually type quotes: "The Law of Large Numbers".

  • Me (unregistered)

    OK, ignoring the irrelevant waffle about the multiple tables and runs of luck, here's a perl golf version at 92 characters, assuming you can bet any integer number of dollars above 10.

    sub p{my($b)=@_;while($b>9){my$t=10;while((rand 38)<18){$b+=$t;$t=int($t*1.5);}$b-=$t;}$b;}

  • (cs) in reply to thnurg
    thnurg:
    What the hell does quote-unquote The Law of Large Numbers mean? *snip*
    I think it's Alex's way of reproducing the sound and feel of blathering legalese without having to remember what the lawyer said verbatim. Let's cut him some slack.
  • Daniel (unregistered)
    There should be two inputs (starting bankroll and number of tables) and a single output (final bankroll)
    Not sure when to stop... the obvious answer is when the money is all gone, so the single output will allways be zero!
    The odds for betting on black or red are 1-to-1.
    The Perch does not specify that we should be the color oposit to the one that came 4 times?

    Also, the odds are 18/38 for red, 18/38 for black and 2/38 for green...

  • There is so much WTF in this I don't know where to start (unregistered)

    The roulette table has NO MEMORY of the previous sequence of events (black or red). Read this several times till you understand this concept.

    Randomness is not the roulette table keeping a tally of all the reds and blacks in sequence and making sure there are the same number of each (ignoring the greens which I'll get to in a minute) or a fair-looking alternation of red and black sequences.

    The sequence of random black and red is truly random - 100 black followed by 100 red is JUST AS LIKELY as RED-BLACK-RED-BLACK (repeated forever) or RRRR-BBBB-RRRR-BBBB...or any other combination.

    Each subseqent outcome is completly unaffected by the previous colour.

    As far as the odds being 1:1 - the 2 greens are how the house winds. Yes - there are equal number of reds and blacks, so 1:1 payout looks like a good deal. However, there a 2 green possibilites on the table (i.e. neither red nor green) - this is why the house always win on average.

    Suggest your coding competition is scrapped in favour of reading 'Probabilities for Dummies'

  • Dazed (unregistered)

    My first little book on mathematics did a good job of explaining how roulette works, and how roulette strategies don't. It ended with advice along the lines of: rather than play roulette, flush your money down the toilet; it's equally effective and saves the hassle of getting to the casino.

  • Yazeran (unregistered) in reply to Code Dependent
    Code Dependent:
    thnurg:
    What the hell does quote-unquote The Law of Large Numbers mean? *snip*
    I think it's Alex's way of reproducing the sound and feel of blathering legalese without having to remember what the lawyer said verbatim. Let's cut him some slack.
    Especially considering that he explicitly mentioned something about being drunk.. I mean who here can honestly say that he/she would be able to remember precisely something a Lawyer has said (drunk or not)... ;-)

    Yours Yazeran

    Plan: To go to Mars one day with a hammer

  • Me (unregistered) in reply to There is so much WTF in this I don't know where to start

    "Suggest your coding competition is scrapped in favour of reading 'Probabilities for Dummies'"

    Methinks the mention of "gambler's fallacy" in the original post means he already knows and he's just trolling for responses like yours ;)

  • Addison (unregistered)

    I'm afraid I don't understand the point of this problem.

    The chances that something will hit a certain colour on the next roll are exactly the same no matter what was rolled before. So coding a solution to this will wind up exactly the same as if you just coded regular roulette.

  • MC (unregistered)
    Suggest your coding competition is scrapped in favour of reading 'Probabilities for Dummies'

    Suggest that you have never actually been gambling before. The lawyer in the story already states that The Perch was thought up in a situation "[w]herein both parties understand...the Gambler’s Fallacy" so it's useless to get on your soapbox and preach about a basic tenet of probability. I'm pretty sure we all know that one. This is about having fun, one of the things you're supposed to do at a casino (along with losing all your money due to the aforementioned Gambler's Fallacy).

  • James (unregistered) in reply to There is so much WTF in this I don't know where to start
    There is so much WTF in this I don't know where to start:
    The roulette table has NO MEMORY of the previous sequence of events (black or red). Read this several times till you understand this concept.

    Randomness is not the roulette table keeping a tally of all the reds and blacks in sequence and making sure there are the same number of each (ignoring the greens which I'll get to in a minute) or a fair-looking alternation of red and black sequences.

    The sequence of random black and red is truly random - 100 black followed by 100 red is JUST AS LIKELY as RED-BLACK-RED-BLACK (repeated forever) or RRRR-BBBB-RRRR-BBBB...or any other combination.

    Each subseqent outcome is completly unaffected by the previous colour.

    As far as the odds being 1:1 - the 2 greens are how the house winds. Yes - there are equal number of reds and blacks, so 1:1 payout looks like a good deal. However, there a 2 green possibilites on the table (i.e. neither red nor green) - this is why the house always win on average.

    Suggest your coding competition is scrapped in favour of reading 'Probabilities for Dummies'

    I was thinking that too but I am assuming that is part of the joke and the idea was to come up with some WTF code?

  • (cs) in reply to Dazed
    Dazed:
    My first little book on mathematics did a good job of explaining how roulette works, and how roulette strategies don't. It ended with advice along the lines of: rather than play roulette, flush your money down the toilet; it's equally effective and saves the hassle of getting to the casino.

    Also, it saves you the cost of renting a tux, so it might even be less money lost.

    Then again, calling a plumber to fix the drains might reverse that...

  • Yazeran (unregistered) in reply to There is so much WTF in this I don't know where to start
    There is so much WTF in this I don't know where to start:
    The roulette table has NO MEMORY of the previous sequence of events (black or red). Read this several times till you understand this concept.

    Randomness is not the roulette table keeping a tally of all the reds and blacks in sequence and making sure there are the same number of each (ignoring the greens which I'll get to in a minute) or a fair-looking alternation of red and black sequences.

    The sequence of random black and red is truly random - 100 black followed by 100 red is JUST AS LIKELY as RED-BLACK-RED-BLACK (repeated forever) or RRRR-BBBB-RRRR-BBBB...or any other combination.

    Each subseqent outcome is completly unaffected by the previous colour.

    As far as the odds being 1:1 - the 2 greens are how the house winds. Yes - there are equal number of reds and blacks, so 1:1 payout looks like a good deal. However, there a 2 green possibilites on the table (i.e. neither red nor green) - this is why the house always win on average.

    Suggest your coding competition is scrapped in favour of reading 'Probabilities for Dummies'

    Actually there is one sure way to win on the roulette:

    1. Bet 1 dollar on red
    2. If you win goto 1.
    3. bet the double amount you did last time (bet on red again)
    4. If you win goto 1.
    5. Goto 3.

    It should be noted that you may need the entire worlds gross national product available for this to work.... (Not to mention that the casino should not have a limit on the maximum bet you can make, which incidentally exists exactly because of the recipe described above)

    Yours Yazeran

    Plan: To go to Mars one say with a hammer

  • Spelling Nazism (unregistered) in reply to thnurg

    And grammer (sic) is spelled grammar.

    Captcha: Capio which sounds Italian, which reminds me of fascism.

  • ThatsALotOfGravy (unregistered) in reply to There is so much WTF in this I don't know where to start
    There is so much WTF in this I don't know where to start:
    The sequence of random black and red is truly random - 100 black followed by 100 red is JUST AS LIKELY as RED-BLACK-RED-BLACK (repeated forever) or RRRR-BBBB-RRRR-BBBB...or any other combination.

    Woah woah woah, slow down. The chance of the combined event of getting black 100 times in a row is EXTREMELY low, on the order of 1 in 2^100 (let's ignore green). However, if it has already been black 99 times in a row, the chance of it being black again is still 1 in 2.

  • (cs) in reply to Alex Papadimoulis

    This is the same problem for any game like this, black jack is a perfect example.

    Take your initial $10 bet. If you lose place a $20 bet. Continue doubling the bet until you win. Congratulations! You just won $10...

    That's why most tables have a min and a max, to limit the amount of times you can double up.

  • (cs) in reply to Yazeran
    Yazeran:
    Actually there is one sure way to win on the roulette:
    1. Own the casino
    2. ???
    3. Profit!
    FTFY
  • Rev. Creflo Baller (unregistered)

    He has, indeed, seen a lot more 4-in-a-rows than 5-in-a-rows. Approximately twice as many.

  • @Deprecated (unregistered) in reply to Yazeran
    Yazeran:
    There is so much WTF in this I don't know where to start:
    The roulette table has NO MEMORY of the previous sequence of events (black or red). Read this several times till you understand this concept.

    Randomness is not the roulette table keeping a tally of all the reds and blacks in sequence and making sure there are the same number of each (ignoring the greens which I'll get to in a minute) or a fair-looking alternation of red and black sequences.

    The sequence of random black and red is truly random - 100 black followed by 100 red is JUST AS LIKELY as RED-BLACK-RED-BLACK (repeated forever) or RRRR-BBBB-RRRR-BBBB...or any other combination.

    Each subseqent outcome is completly unaffected by the previous colour.

    As far as the odds being 1:1 - the 2 greens are how the house winds. Yes - there are equal number of reds and blacks, so 1:1 payout looks like a good deal. However, there a 2 green possibilites on the table (i.e. neither red nor green) - this is why the house always win on average.

    Suggest your coding competition is scrapped in favour of reading 'Probabilities for Dummies'

    Actually there is one sure way to win on the roulette:

    1. Bet 1 dollar on red
    2. If you win goto 1.
    3. bet the double amount you did last time (bet on red again)
    4. If you win goto 1.
    5. Goto 3.

    It should be noted that you may need the entire worlds gross national product available for this to work.... (Not to mention that the casino should not have a limit on the maximum bet you can make, which incidentally exists exactly because of the recipe described above)

    Yours Yazeran

    Plan: To go to Mars one say with a hammer

    Coincidentally, that is also the exact method used to dispose of all your money.

  • Sid2K7 (unregistered)

    Oh, you're talking about American Roulette. Not Roulette. Just like American Football isn't usually played with one's foot...

    scnr...

  • (cs)
    As soon as a table shows four consecutive blacks or reds, swoop in and place a bet.
    On what colour?
    Otherwise, place another bet worth 150% of the previous bet (instead of $10, place $15).
    On what colour?

    Software requirements are getting vague these days... oh wait, they always were.

  • Guillaume (unregistered)

    Ok, let me write this function then. Firstly, the number of tables is irrelevant as the chance to with is 50% regardless of tables. Secondly, you don't specify how many runs to do in a single function, and provide no way to store state between runs, so I can only end the function when you can't play anymore. And of course, you can't play anymore when you reach $0.

    So here's my function in C:

    int perch(int numTables, int initialMoney)
    {
       return 0;
    }
    

    And for fun, here it is in Haskell:

    perch :: (Num a) => a -> a -> a
    perch nt m = 0
    

    And why not in perl:

    sub perch
    {
       0;
    }
    

    Why yes, I am quite pedantic, how did you know?

    Captcha: ludus, nearly ludicrous?

  • Dan (unregistered)
    The odds for betting on black or red are 1-to-1.

    Not quite. Only 19 out of 40 spots are red; the same applies for black.

    When green comes up, red and black both lose.

    The quote wasn't saying that the odds of winning are 1 to 1, ie 50%. It was saying that the payoff for winning the bet are 1 to 1. If you bet $5, you get your original $5 back plus another $5. You win the amount of your bet.

  • (cs)

    The specification is incomplete. "As soon as a table shows four consecutive blacks or reds, swoop in and place a bet." How big? Should it always be the minimum? Is the intention that you should play $10 if you have exactly $10 or >$25, and otherwise you should play the amount you have (since you won't have enough to place the second bet if you lose the first)? Or is part of the challenge figuring out the optimum (for some metric) amount to bet each time?

  • Kiriai (unregistered)

    Returning 0 doesn't work. The minimum bet is $10. Your final total should be distributed between 0-9.

  • Jim Cooper (unregistered) in reply to Me

    There's no need for any code, a calculator will do perfectly well.

    In order to win $400 starting $10, with winning bets paying even money, the quickest way to get there is to win 6 times in a row, betting all you have each time (so you could get $640, actually).

    The odds for each bet are 18/37 (for normal roulette wheels with one zero), or 18/38 (for American roulette wheels with a zero and a double zero).

    Raising those numbers to the 6th power gets you the odds: 0.013 probability for normal wheels 0.011 probability for American wheels

    So about 1 chance in 100.

    As we all know, what the wheel span last time is completely irrelevant - although it is truly surprising the number of people who don't actually believe that in their heart of hearts :-)

    If you don't bet the whole lot every time it gets more difficult to work out :-)

  • Kanazuchi (unregistered) in reply to Yazeran
    Yazeran:
    Actually there is one sure way to win on the roulette:
    1. Bet 1 dollar on red
    2. If you win goto 1.
    3. bet the double amount you did last time (bet on red again)
    4. If you win goto 1.
    5. Goto 3.

    It should be noted that you may need the entire worlds gross national product available for this to work....

    It's called the Martingale -- and it doesn't work.

    http://wizardofodds.com/askthewizard/bettingsystems-martingale.html

  • randomlyVarying (unregistered) in reply to ThatsALotOfGravy

    Yes, the outcomes of two tosses (turn? role? death spiral?) of the roulette. Yes, the sequence is completely random. That does not mean, however, that all sequences are equally likely to occur.

    For an entertaining summary, see: http://www.ted.com/talks/lang/eng/peter_donnelly_shows_how_stats_fool_juries.html

  • fmtaylor (unregistered)

    I think the point of this exercise is not so much to program a mathematical proof of how and why you will go broke, but more to actually write the code that actually functions as described and watch it run. I suspect that if you do this you may be surprised at the results you will get. (and learn why some people actually win)

    Back in the "before time" I coded up a battleship game in HP basic, you against the machine, no brains for the machine, just totally random, with a memory of where the pegs were. This got boring after a while (a very short while), so I made a few changes so the machine could play itself, fascinating for a few minutes, but a lot of paper was coming out of the teletype, so I eliminated all of the output except for the final win/lose results. Shortly after that I got a call from the system admin. Seems that eating up that kind of CPU time in 1975 was kinda frowned upon, go figure ;)

    The point is that I could have just put the variables down and calculated the result, but where is the fun in that.

  • Jim (unregistered)

    echo '$0'

  • (cs) in reply to Daniel
    Daniel:
    Not sure when to stop... the obvious answer is when the money is all gone, so the single output will allways be zero!

    Not so, because you may end up with greater than zero but insufficient to meet the $10 minimum bet on the next spin...

  • Guillaume (unregistered) in reply to Kiriai
    Kiriai:
    Returning 0 doesn't work. The minimum bet is $10. Your final total should be distributed between 0-9.

    After a night like that, I'd probably spend that $0-9 on drinks. But yes, good point.

  • Jim Cooper (unregistered) in reply to Jim Cooper

    BTW, in the calculations above, I left out step 3 (the betting 150% of a losing bet), as it wasn't clear when to stop betting*, so there's no way to work out how many bets can be placed.

    • Well, actually, it was. Anyone tempted to use this hare-brained scheme shouldn't place any bets at all, and should just drink $10 of beer :-)
  • Capt. Awesome (unregistered) in reply to Sid2K7
    Sid2K7:
    Oh, you're talking about American Roulette. Not Roulette. Just like American Football isn't usually played with one's foot...

    scnr...

    An American football is a foot long.

  • (cs) in reply to ThatsALotOfGravy
    ThatsALotOfGravy:
    There is so much WTF in this I don't know where to start:
    The sequence of random black and red is truly random - 100 black followed by 100 red is JUST AS LIKELY as RED-BLACK-RED-BLACK (repeated forever) or RRRR-BBBB-RRRR-BBBB...or any other combination.

    Woah woah woah, slow down. The chance of the combined event of getting black 100 times in a row is EXTREMELY low, on the order of 1 in 2^100 (let's ignore green).

    The probability is low, however equal any other combination of the same length.

  • sep332 (unregistered) in reply to ThatsALotOfGravy
    ThatsALotOfGravy:
    There is so much WTF in this I don't know where to start:
    The sequence of random black and red is truly random - 100 black followed by 100 red is JUST AS LIKELY as RED-BLACK-RED-BLACK (repeated forever) or RRRR-BBBB-RRRR-BBBB...or any other combination.

    Woah woah woah, slow down. The chance of the combined event of getting black 100 times in a row is EXTREMELY low, on the order of 1 in 2^100 (let's ignore green). However, if it has already been black 99 times in a row, the chance of it being black again is still 1 in 2.

    Yes, it's ludicrously low. But it's the EXACT SAME as the odd of getting R-B-R-B-R-B... for 100 bets in a row, or getting RRRR-BBBB-RRRR-BBBB... for 100 bets, or ANY exact sequence of 100.

  • (cs) in reply to ThatsALotOfGravy
    ThatsALotOfGravy:
    There is so much WTF in this I don't know where to start:
    The sequence of random black and red is truly random - 100 black followed by 100 red is JUST AS LIKELY as RED-BLACK-RED-BLACK (repeated forever) or RRRR-BBBB-RRRR-BBBB...or any other combination.

    Woah woah woah, slow down. The chance of the combined event of getting black 100 times in a row is EXTREMELY low, on the order of 1 in 2^100 (let's ignore green). However, if it has already been black 99 times in a row, the chance of it being black again is still 1 in 2.

    He didn't say it was a high probability, only that the probabilities of same-length sequences are equal. Which is true.

    ARGH. Three identical answers to the same question, and this WTF POS forum doesn't let me delete my post...

  • (cs)

    I can't get this method to produce any winnings (like I suspected from the start). Most of the time I lose the first bet so I don't get anywhere. Also the complicated method of playing the against "streaks" of rolls does not have any greater chance of winning (as prediced). Still sometimes I can make a series of wins.

    But most importantly the series always converges on $0, so it is impossible to keep this going forever.

    I'm not posting code, because it's messy and I have to get back to work.

  • Michael A (unregistered)

    "I’ve seen a heckuva lot more 4-in-a-rows than I have 5-in-a-rows."

    No, you've seen slightly less than 1/2 the number of 5-in-a-rows as 4-in-a-rows (would be exactly 1/2 except for greens.

  • (cs) in reply to Alex Papadimoulis
    Alex Papadimoulis:
    As it turned out, Automating the Knight's Tour was a bit more difficult than I had realized. When initially researching the problem, I saw a relatively simple algorithm and figured, oh yeah, I can do that! Of course, without knowing the trick... there was no way I could have solved it in a long coffee break or lunch break. Either way, I was most impressed by DaveC's Excel VBA solution.

    And by DaveC, I assume you mean BradC? Thanks!

    After cheating and reading the Wikipedia page, I started a second Excel VBA version that uses the Warnsdorff's algorithm (cool algorithm, Warnsdorff!! Much faster and more efficient than brute force!).

    I got the basic algorithm to work, but didn't get as far as designing a backup-and-retry if it didn't work from the start.

  • Guillaume (unregistered)

    In light of the losing condition be less than $10, here's my revised solution:

    int perch(int numTables, int m)
    {
       int bet = 10;
       int win = 0;
       while(m >= 10)
       {
          if(win)
             bet += bet >> 1;
          else
             bet = 10;
          if(bet > m)
             bet = 10;
          m += (win = (rand() % 2)) ? bet : -bet;
       }
       return m;
    }
    
  • aBase (unregistered) in reply to Sid2K7
    Sid2K7:
    Oh, you're talking about American Roulette. Not Roulette. Just like American Football isn't usually played with one's foot...

    scnr...

    It's merely an American idiom, similar to calling a group of second-rate clubs "Premier League".

  • CommonSense (unregistered)

    The point of this "practice" clearly isn't to try coding a solution, but being a good enough programmer to analyze the problem first and realize there's no pattern to roulette so no code needs to be written.

Leave a comment on “Knocking Me Off The Perch”

Log In or post as a guest

Replying to comment #282630:

« Return to Article