Problem 054
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.
See also the topics:
Don't post any spoilers
Comments, questions and clarifications about PE problems.
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
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.
-
tommyjcarpenter
- Posts: 3
- Joined: Wed May 03, 2017 4:58 pm
problem 054 needs updated wording
I am a poker player, and at least in HoldEm an Ace can start a straight. The wording on the problem is incorrect and ambiguous, because from it it would seem that an ace can only end a straight as in TJQKA because of the value listing, but A1234 is a valid poker straight.
So can an ace start a straight and can this be clarified in the wording?
So can an ace start a straight and can this be clarified in the wording?
Last edited by tommyjcarpenter on Wed May 03, 2017 6:20 pm, edited 1 time in total.
- rayfil
- Administrator
- Posts: 1412
- Joined: Sun Mar 26, 2006 5:30 am
- Location: Quebec, Canada
- Contact:
Re: problem 54 needs updated wording
Being a new member on this forum, please be advise that problem numbers are listed with leading "0s" to provide a 3-digit number in order to facilitate archiving and easier searching.
When you assume something, you risk being wrong half the time.
-
th72
- Posts: 1
- Joined: Tue Aug 15, 2017 3:52 pm
Re: Problem 054
Hi! This one really has me stumped.
I've been doing random checks on the winning hands, but I really can't find the mistake. And I'm pretty sure I've evaluated the tie-breakers properly (again, random checks seem to work).
Would anyone be willing to take a look at my list of who won which hand and tell me the first result I've gotten wrong? I think that would put me on the right track, thanks!
I've been doing random checks on the winning hands, but I really can't find the mistake. And I'm pretty sure I've evaluated the tie-breakers properly (again, random checks seem to work).
Would anyone be willing to take a look at my list of who won which hand and tell me the first result I've gotten wrong? I think that would put me on the right track, thanks!
- rayfil
- Administrator
- Posts: 1412
- Joined: Sun Mar 26, 2006 5:30 am
- Location: Quebec, Canada
- Contact:
Re: Problem 054
th72
Send me a PM with your list and I'll try to have a look at it.
Send me a PM with your list and I'll try to have a look at it.
When you assume something, you risk being wrong half the time.
-
Junglemath
- Posts: 72
- Joined: Fri Sep 20, 2019 1:25 pm
- Location: Minsk
Re: Problem 054
I've seen conflicting answers about whether an ace can be considered the lowest card for the purposes of making a straight. In every version of (high) poker, which this problem seems to be about, the lowest straight is A2345, with the ace assuming the value of 1. For all other purposes it is considered to rank above a king.
Does anyone know for sure what this problem wants?
And to the admins, if A2345 does not count as a straight, it should be changed. This is extremely nonstandard. At the very least, a sentence should be included in the problem statement as this is a huge ambiguity to anyone who knows anything about poker.
Thanks
Does anyone know for sure what this problem wants?
And to the admins, if A2345 does not count as a straight, it should be changed. This is extremely nonstandard. At the very least, a sentence should be included in the problem statement as this is a huge ambiguity to anyone who knows anything about poker.
Thanks
-
LilStalker
- Posts: 74
- Joined: Thu Nov 03, 2016 4:32 pm
Re: Problem 054
I do think this is considered a straight 5 high.
Are there many hands where this is a problem? Otherways you can try 2 or 3 values if there are a few hands with this occurence.
Are there many hands where this is a problem? Otherways you can try 2 or 3 values if there are a few hands with this occurence.

-
Junglemath
- Posts: 72
- Joined: Fri Sep 20, 2019 1:25 pm
- Location: Minsk
Re: Problem 054
Someone on reddit claimed they solved it without assuming that the ace counts as low. I tried it this way and indeed I got the right answer.LilStalker wrote: Fri Sep 20, 2019 9:47 pm I do think this is considered a straight 5 high.
Are there many hands where this is a problem? Otherways you can try 2 or 3 values if there are a few hands with this occurence.
BTW, did you really solve 509 problems? Did you omit 54 for some reason?
Unlikely spoiler ahead:
(No spoilers allowed on this forum. <moderator>)
-
s4mp
- Posts: 5
- Joined: Sat Apr 25, 2020 6:28 pm
Problem 054
I've coded a solution, but for some reason the answer i get is one off.
My only thought at the moment is that it counts a straight from a low ace (e.g A 2 3 4 5), As i haven't programmed this. Is this true? I've searched for similar posts but it seems to be getting mixed answers.
My only thought at the moment is that it counts a straight from a low ace (e.g A 2 3 4 5), As i haven't programmed this. Is this true? I've searched for similar posts but it seems to be getting mixed answers.
-
Junglemath
- Posts: 72
- Joined: Fri Sep 20, 2019 1:25 pm
- Location: Minsk
Re: Problem 054
There is a thread about this problem already. Did you look there?
viewtopic.php?f=50&t=6550
By the way, how do you know you're one off if you haven't solved it yet?
viewtopic.php?f=50&t=6550
By the way, how do you know you're one off if you haven't solved it yet?
-
s4mp
- Posts: 5
- Joined: Sat Apr 25, 2020 6:28 pm
Re: Problem 054
I've looked through the thread and that answers about the ace but i still cant work out why im off by one.
Is there any chance i could PM you a list of my results for each pair of hands and you let me know which one is wrong?
EDIT: I managed to solve it, no help needed anymore
Is there any chance i could PM you a list of my results for each pair of hands and you let me know which one is wrong?
EDIT: I managed to solve it, no help needed anymore
Last edited by s4mp on Wed May 06, 2020 2:05 pm, edited 1 time in total.
-
Junglemath
- Posts: 72
- Joined: Fri Sep 20, 2019 1:25 pm
- Location: Minsk
Re: Problem 054
Sure. But how do you know you're one off if you haven't solved it yet?s4mp wrote: Wed May 06, 2020 10:00 am I've looked through the thread and that answers about the ace but i still cant work out why im off by one.
Is there any chance i could PM you a list of my results for each pair of hands and you let me know which one is wrong?
- hk
- Administrator
- Posts: 12831
- Joined: Sun Mar 26, 2006 10:34 am
- Location: Haren, Netherlands
Re: Problem 054
Great.s4mp wrote: Wed May 06, 2020 10:00 am I've looked through the thread and that answers about the ace but i still cant work out why im off by one.
Is there any chance i could PM you a list of my results for each pair of hands and you let me know which one is wrong?
EDIT: I managed to solve it, no help needed anymore
Next time please read the pink box at the top of the page carefully.

War ruins the life and health of untold numbers of innocent children.
-
DeKlod
Re: Problem 054
Allow me to add my pinch of salt in s4mp's defence: any internet search on an Euler-like problem (particularly the older ones) will invariably turn up page after page of spoilers!Junglemath wrote: Wed May 06, 2020 1:40 pmSure. But how do you know you're one off if you haven't solved it yet?s4mp wrote: Wed May 06, 2020 10:00 am I've looked through the thread and that answers about the ace but i still cant work out why im off by one.
Is there any chance i could PM you a list of my results for each pair of hands and you let me know which one is wrong?
Now, it is everyone's decision - and in Covid times, we're all supposed to act responsibly so we do the same with Euler Project questions - but one of the cheats I personally find quite acceptable is to look up the answer. Not the algorithm that gets you there - just the actual answer.
I should state that my goal, in tackling Euler questions, is to teach myself computer programming. In formal education, there would be a tutor or teacher who would look at my code/thinking behind the code and give me some feedback: am I getting close or is my approach ridiculously wrong.
So I too have benefitted from looking up the odd answer - value - and find that I inadvertently missed setting the initial sum-value to 5 because my loop only started at 6, or some similar mistake. Easy to spot if you're a seasoned programmer, but a devilish trap for the self-taught novice.
So what I really want to say is: please can we avoid judging someone's message from the simple fact that he/she may have looked up (or inadvertently seen - that's Google for you!) the answer beforehand? The great thing about Project Euler is that it allows people like me to start self-taught coding without any pressure!
Besides: I know from bitter experience how hard it can be - again as a self-taught novice programmer - to find stupid little errors like the one s4mp might have made... Have you ever converted an integer into a double by forcing and multiplying by '1.*' only to find after hours and hours that you missed the dot and simply multiplied by '1' ...
There are enough traps for us novices - at least allow us to seek some guidance to keep us on the right track!
Here endeth the lesson
Claude
- hk
- Administrator
- Posts: 12831
- Joined: Sun Mar 26, 2006 10:34 am
- Location: Haren, Netherlands
Re: Problem 054
There's actually no need to have looked up the answer somewhere.
Some people simply try some answers around the value their program gives. Just to rule out off by one answers.
Some people simply try some answers around the value their program gives. Just to rule out off by one answers.

War ruins the life and health of untold numbers of innocent children.
-
DeKlod
Re: Problem 054
Never thought of thathk wrote: Fri May 08, 2020 9:28 am There's actually no need to have looked up the answer somwhere.
Some people simply try some answers around the value their program gives. Just to rule out off by one answers.
-
ksaho
- Posts: 4
- Joined: Sun Aug 11, 2024 10:41 am
Re: Problem 054
I would discourage attempting to guess due to a off by 1 issue. I just had that issue with this problem and the off by 1 issue here was a fundamental misunderstanding on my part which if I had simply entered my result in with a variance of 1(+/-) I would never have figured it out.
- Vinny360
- Posts: 19
- Joined: Tue Jan 21, 2025 11:02 pm
Re: Problem 054
I need help, I don't know if you should treat all flushes as equal or compare the cards. 
3.141592653589793238462643383... PE is fun.
Hello from

↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
Hello from

↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
-
DJohn
- Posts: 90
- Joined: Sat Oct 11, 2008 12:24 pm
Re: Problem 054
The rules cover that:Vinny360 wrote: Mon Apr 13, 2026 7:22 am I need help, I don't know if you should treat all flushes as equal or compare the cards.![]()
So if I have the 2, 4, 6, 8, and Jack of clubs and you have the 3, 5, 7, 9, and Jack of hearts, we both have a flush. We then look at our highest cards. They're both Jacks, so we look at the next highest. I have an 8 and you have a 9, so you've won that hand.But if two ranks tie, for example, both players have a pair of queens, then highest cards in each hand are compared (see example 4 below); if the highest cards tie then the next highest cards are compared, and so on.
- Vinny360
- Posts: 19
- Joined: Tue Jan 21, 2025 11:02 pm
Re: Problem 054
Thanks a lot. This is probably why my code went wrongDJohn wrote: Sat Apr 18, 2026 11:25 amThe rules cover that:Vinny360 wrote: Mon Apr 13, 2026 7:22 am I need help, I don't know if you should treat all flushes as equal or compare the cards.
So if I have the 2, 4, 6, 8, and Jack of clubs and you have the 3, 5, 7, 9, and Jack of hearts, we both have a flush. We then look at our highest cards. They're both Jacks, so we look at the next highest. I have an 8 and you have a 9, so you've won that hand.But if two ranks tie, for example, both players have a pair of queens, then highest cards in each hand are compared (see example 4 below); if the highest cards tie then the next highest cards are compared, and so on.
3.141592653589793238462643383... PE is fun.
Hello from

↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
Hello from

↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑