Problem 054

A place to air possible concerns or difficulties in understanding ProjectEuler problems. This forum is not meant to publish solutions. This forum is NOT meant to discuss solution methods or giving hints how a problem can be solved.
Forum rules
As your posts will be visible to the general public you
are requested to be thoughtful in not posting anything
that might explicitly give away how to solve a particular problem.

This forum is NOT meant to discuss solution methods for a problem.

In particular don't post any code fragments or results.

Don't start begging others to give partial answers to problems

Don't ask for hints how to solve a problem

Don't start a new topic for a problem if there already exists one


See also the topics:
Don't post any spoilers
Comments, questions and clarifications about PE problems.
MaJJ
Posts: 49
Joined: Tue Oct 14, 2008 12:14 am

Re: Problem 054

Post by MaJJ »

Is solution
Expand
539
anywhere near the real answer? Bah, I wish I knew where is my error in the code ... :D
Image
Image

User avatar
jaap
Posts: 550
Joined: Tue Mar 25, 2008 3:57 pm
Contact:

Re: Problem 054

Post by jaap »

Majj,
Not really. It is far enough away that checking one or two dozen cases from the file at random has a good chance of finding a wrong one.

MaJJ
Posts: 49
Joined: Tue Oct 14, 2008 12:14 am

Re: Problem 054

Post by MaJJ »

heh ... I had really nice error :D

Code: Select all

wins += 1 if s1 < s2
instead of

Code: Select all

wins += 1 if s1 > s2
Image
Image

dnosrc
Posts: 8
Joined: Tue Jul 27, 2010 4:58 pm

Re: Problem 054

Post by dnosrc »

can aces play low in streets?
example: A 2 3 4 5

User avatar
elendiastarman
Posts: 410
Joined: Sat Dec 22, 2007 8:15 pm

Re: Problem 054

Post by elendiastarman »

dnosrc wrote:can aces play low in streets?
example: A 2 3 4 5
Yes.
Want some
3.14159265358979323846264338327950288419716939937510
58209749445923078164062862089986280348253421170679...?
Image

beastmaster
Posts: 3
Joined: Thu Apr 21, 2011 4:29 pm

Re: Problem 054

Post by beastmaster »

Hi!
i've spent a lot of time on this problem and i keep getting the same result, xxx wins for player 1, which of course is wrong. Any tips on this one? i can add code too, but i'm not sure if that's ok.

User avatar
Lord_Farin
Posts: 239
Joined: Wed Jul 01, 2009 10:43 am
Location: Netherlands

Re: Problem 054

Post by Lord_Farin »

beastmaster wrote:Hi!
i've spent a lot of time on this problem and i keep getting the same result, xxx wins for player 1, which of course is wrong. Any tips on this one? i can add code too, but i'm not sure if that's ok.
I recall that I spent ages on this problem, rewriting my code over and over again, and keeping the same problem. In the end, it turned out I read the file wrong. So please make sure it's not something as trivial as that before spending time on rewriting all your algo's
Image

beastmaster
Posts: 3
Joined: Thu Apr 21, 2011 4:29 pm

Re: Problem 054

Post by beastmaster »

i found the problem, it was even more trivial and it only changed the result by 1. and i spent hours and hours trying to figure it out.

Hibernatus34
Posts: 31
Joined: Mon May 16, 2011 7:03 am

Re: Problem 054

Post by Hibernatus34 »

Hello,

It was a nice problem, but it's a shame some cases are missing :
- Straight starting with an ace (meaning the highest card in the straight is 5)
- Four of a kind
- Straight flush and royal flush

The first case would have added a nice trap to fall into.

BTW, how fast is the function supposed to be ?
I got 1.17 ms including file loading (but not the first read so it's in a cache somewhere), i expected less.
Image Joined PE in May 2011

matts1
Posts: 5
Joined: Sat May 07, 2011 11:19 pm

Re: Problem 054

Post by matts1 »

Could someone remove beastmaster's post. It states the answer he got, then he said that he was off by 1
Coding in Python (3rd year programming)
Image

User avatar
hk
Administrator
Posts: 10811
Joined: Sun Mar 26, 2006 10:34 am
Location: Haren, Netherlands

Re: Problem 054

Post by hk »

matts1 wrote:Could someone remove beastmaster's post. It states the answer he got, then he said that he was off by 1
It need not be removed, but only edited, which I did.
BTW: the removed answer given wasn't off by one actually.
Image

matts1
Posts: 5
Joined: Sat May 07, 2011 11:19 pm

Re: Problem 054

Post by matts1 »

Thanks. Also, would someone be able to take a look at my code for this (python). I'm afraid it's quite ugly and hard to read, but it looks like there is no problem with it (that's what I thought anyway).
Coding in Python (3rd year programming)
Image

User avatar
thedoctar
Posts: 74
Joined: Fri Apr 15, 2011 11:57 am
Location: Sydney, Australia

Re: Problem 054

Post by thedoctar »

You can pm me your code
4x Intel(R) Core(TM) i3-2330M CPU @ 2.20GHz
Image
fabas indulcet fames

olleicua
Posts: 8
Joined: Fri Oct 07, 2011 5:00 am

Re: Problem 054

Post by olleicua »

I'm not sure what I'm doing wrong here, my code seems to be working fine but I get the wrong number. I put in a bunch of print statements and hunted at random for places where it was coming to the wrong conclusion in hopes of finding a systematic error but found nothing. I thought I might be confused as to which high card is used in the case of for example:

6D 6S 7D 2C 3H | 5D 5H JH 2S 7S

Initially I was thinking that since player 1's pair was 6s as opposed to player 2's 5s that player 1 would win, then I thought maybe this was not the case and the tie would just immediately send us to high card (player 2 wins). I tried this but the number I got is still wrong. Could someone look at my code and point me in the right direction?

Peace
~Sam

TripleM
Posts: 382
Joined: Fri Sep 12, 2008 3:31 am

Re: Problem 054

Post by TripleM »

Hand 1 provided in the problem demonstrates exactly what to do in that case, namely that the pair is compared first.

I'll look at your code, as long as you don't expect more than an extremely subtle hint :)

Eventhorizon
Posts: 19
Joined: Fri Sep 23, 2011 2:16 am

Re: Problem 054

Post by Eventhorizon »

EDIT: Figured it out, problem with 3 of a kind.

PLUS: Suggestion to anyone else trying to verify their ranking algo: see if your counts of each type of hand (2 pair, 3 of a kind, etc) matches expectations - I found I had a count of 3 of a kind that had only a 0.08% probability. You can find the probs on Wikipedia.


So I thought it was about time I knocked this one off! I have checked the first 300 hands and my scoring algo agrees with my eye. I can't seem to get the number right but notice a couple things:

By hand 300, player1 has only won 112 hands (150 - 112) / sqrt(300 * 0.5 * 0.5) = 4.4 std devs below expectation! Still, my hand count agrees with this. Maybe player1 is the patsy!

Trying to figure out where I went wrong without spoiling it for others, I tracked the following statistics:

Out of 1000 hands 626 were decided on rank alone (i.e. FH beats Flush beats Straight beats 3 of a kind beats 2 pair beats 1 pair beats no hand)

159 matched rank and were decided on the highest value of involved cards (using the 3 from FH, highest pair of 2 pair).

0 required going to the second pair in 2 pair or the pair in the FH.

215 were then decided by the highest value of uninvolved cards.

Does this match with anyone else's experience?
Image

User avatar
SoboLAN
Posts: 39
Joined: Sat Aug 18, 2012 3:21 pm

Re: Problem 054

Post by SoboLAN »

Given that I'm a computer science student with a big passion for poker, I have to say this was my absolute favourite problem. If you would make a similar one involving Omaha instead of Texas Hold'em, that would be golden :) .

PS: For those who don't know: Omaha is similar to Texas Hold'em (the poker variation that is present here in problem 54) with the exception that there are 9 cards. The best 5 cards combination (like in this problem) must then be found from these 9 cards, but there are some additional rules involved. It's interesting, trust me :) .
Image

Loers
Posts: 10
Joined: Sun Aug 19, 2012 3:03 am

Re: Problem 054

Post by Loers »

this problem is reeeeally annoying ,,
in the case that two players have have 2 pairs.. how do I decide ?
what if the player A got (a pair of threes) and (a pair of queens)
while player B got (a pair of fives) and a pair of (jacks)
is there some sorta of comparing that can be done here ? or should we move to comparing highest card ?

for (one pair , four of a kind , three of kind,straight , flush , straight flush) I think that we compare the values of the winning set ,then move to highest card comparing..
but what if two got (Royal Flush) ?

and what if Highest card test fails ?!

TripleM
Posts: 382
Joined: Fri Sep 12, 2008 3:31 am

Re: Problem 054

Post by TripleM »

You always start with the highest frequency, and then work from highest ranked to lowest ranked.

For example, if both hands are two pairs, compare the highest pair. If they are equal, compare the second highest pair. If they are equal, compare the 5th card.

If both hands are three-of-a-kind, first compare the three-of-a-kind; if equal, compare the next highest card; if equal compare the next highest card, etc. For full houses, you compare the three-of-a-kind before the two-of-a-kind. For high card only, you compare them from highest to lowest.

The problem says there is always a clear winner, so you will never have two royal flushes, and the high card test never 'fails'.

Loers
Posts: 10
Joined: Sun Aug 19, 2012 3:03 am

Re: Problem 054

Post by Loers »

my code is giving me
all the following cases never appeared in the file {
Three of a Kind vs Three of a Kind
Straight vs Straight
Flush vs Flush
Full House vs Full House
Four of a Kind vs Four of a Kind
Straight Flush vs Straight Flush
Royal Flush vs Royal Flush(the only one that makes sense)
}
is that true !?!?!

Post Reply