Be the first to rate this file! 16 downloads (last 30 days) File Size: 9.07 KB File ID: #24605

Solution to Project Euler Problem 54

by Husam Aldahiyat

 

01 Jul 2009 (Updated 02 Jul 2009)

Code covered by the BSD License  

How many hands did player one win in the game of poker?

Download Now | Watch this File

File Information
Description

This is the solution to the problem found here:

<http://projecteuler.net/index.php?section=problems&id=54&gt;

When I solved the problem I found the code to be modular and simple. I thought it can help others in learning logical thinking and how to simplify a big problem into several smaller ones. This is why I don't think I'm breaking any ethical barriers by submitting the solution here.

MATLAB release MATLAB 7.7 (R2008b)
Zip File Content  
Other Files
euler54.m,
findv.m,
get_fourv.m,
get_fullhv.m,
get_onepv.m,
get_threev.m,
get_twopv.m,
geth.m,
getrank.m,
is_flush.m,
is_four.m,
is_fullh.m,
is_onep.m,
is_royalf.m,
is_sflush.m,
is_straight.m,
is_three.m,
is_twop.m,
license.txt
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
02 Jul 2009 John D'Errico

Ok. I'll admit that part of me wishes that Husam did not post this submission, but only a small part of me thinks that way. Why? Because I am a great admirer of the Project Euler problems. They afford a great sense of satisfaction in the solving, knowing that you have used your skills in MATLAB to solve these problems. Most problems require some insight, some understanding of a mathematical concept, as well as not insignificant programming skill to solve in your chosen language. As such they are a tremendous vehicle to help you to learn to use a tool like MATLAB. I have always maintained that the best way to learn a language is to have a project that requires solving.

So I hope that most Euler solvers will choose to solve the problems on their own, first, only then look to the occasional published solutions they will find on the net.

On the other hand, this is one of the moderately easy PE problems. if this particular solution causes others to find an interest of their own in these same problems, then it is worth having posted it. As I said, my opinion is mixed here. While I am quite happy to see some advertising for others to begin the Project Euler adventure, I hope not to see solutions to each problem appear here on the FEX.

As for the code itself, I won't offer a rating because of those mixed feelings. I do very much like that the code is written in a modular fashion.

There are useful comments in the main block of code - a good start there, although the comments get sparser towards the end. The individual modules are entirely without comments though, and this is a place where those comments would have been most valuable. How for example, did the author choose to test if a hand is a flush? 3 of a kind? A tutorial code should explain itself.

Is there anything else that I might have hoped to see? Yes. Very often solving a problem like this requires the programmer to implement an encoding for the data. In this case, is there an efficient way to encode the hands for evaluation of the potential of those hands? I'd have liked to see some exposition on the data structure employed, as I can think of at least two or three ways to store them. Careful advance thought about the data structures employed is often critical to an efficient solution of the problem down the line.

Again, my point is to use this tool as a means to teach how to use matlab to solve a problem. Help the person reading your code to understand how you solved the problem.

02 Jul 2009 John D'Errico

I see some changes have been made. These extra comments really help the person reading the code. My thanks there.

Personally, I'd still hope that beginning PE solvers try the problem first, before looking at this. Only afterwards should you read through this submission to compare this code to yours. But this is a reasonable approach to the problem.

I'll still abstain on an actual rating, but if I were to give this a numeric rating, my rating would be a decent one.

Please login to add a comment or rating.
Updates
02 Jul 2009

Commented files, did minor corrections, added joke.

Tag Activity for this File
Tag Applied By Date/Time
poker Husam Aldahiyat 01 Jul 2009 11:52:33
text Husam Aldahiyat 01 Jul 2009 11:52:34
function Husam Aldahiyat 01 Jul 2009 11:52:34
modular Husam Aldahiyat 01 Jul 2009 11:52:34
unique Husam Aldahiyat 01 Jul 2009 11:52:34
comments Husam Aldahiyat 02 Jul 2009 10:13:46
help Husam Aldahiyat 02 Jul 2009 10:13:46
tips Husam Aldahiyat 02 Jul 2009 10:13:46
projecteuler Steven Lord 06 Jul 2009 13:30:32
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com