Contest 45: 7 Card Draw

Online C++ programming contests.

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard, raimo

Contest 45: 7 Card Draw

Postby Darryl » Fri Aug 12, 2005 2:05 pm

Contest 45: 7 Card Draw
Deadline: August 31st, 2005 at 24:00 EST

Description:
Given 2 seven card poker hands your program will output the 5 card winning hand. This contest is coincidentally similar to mathschallnge #54.

Example:

input: ah kh qh jh 10h 10d 10s 5d 5c 5s 5h 2s 2h 2c
output: ah kh qh jh 10h


Input:
Input will be read from a text file entitled "input.txt". Each card is separated by a blank. There will be 14 cards per line, the 1st seven are hand1, 2nd 7 are hand 2. There will be up to 10 pairs of hands in the file.

Output:
For each set of hands output the winning 5 card hand, in case of ties, output either hand. Your answer should be printed to stdout with each winning hand followed by a new line.

Judging:

This is a Code Brevity contest. The program that produces the correct output using the fewest tokens will be the winner. I will use the same token counter we've used for previous contest

Fine Print:
- No macros
- All symbols will be lower case.
- Source must be in one *.cpp file called (your screen name).cpp.
- You must send the ENTIRE file, not just a function to do it. This means input, processing, and output.
- Program must compile on MSVC++ 2003 .NET, MSVC++ Express Beta, or Dev-C++ 5.0 beta 9.2 (4.9.9.2)
- must use use int before main, no gcc >?= (whatever that is) .

Submissions:
Send your entries completed in a single *.cpp file to littled at gmail dot com with the title "Contest 45". If it doesn't compile, I will let you know the errors and you will be given the chance to fix it until the deadline.

If you have any questions, comments, concerns about this contest, feel free to post here.
Last edited by Darryl on Thu Aug 18, 2005 7:34 pm, edited 6 times in total.
User avatar
Darryl
 
Posts: 1342
Joined: Wed Sep 01, 2004 10:50 am
Location: Cayman Islands

Postby Dante Shamest » Fri Aug 12, 2005 2:10 pm

Do I need to know Poker?
User avatar
Dante Shamest
Moderator
 
Posts: 3131
Joined: Wed Oct 22, 2003 10:29 pm
Location: Malaysia

Postby Wizard » Fri Aug 12, 2005 3:15 pm

User avatar
Wizard
Site Admin
 
Posts: 3250
Joined: Mon Sep 22, 2003 4:52 pm
Location: ON, CA

Postby Corsix » Sat Aug 13, 2005 11:28 am

A few test input files please?

EDIT:
You mention Input, Output, but not "Processing". Are we meant to output the winning hand from the 1-10 given? Or are we meant to output the best you can get from each hand? Is there always a winning hand? How do you define winning?
Code: Select all
#include <stdio.h>
char*_="XxTIHRCXCxTIHRXRCxTIHXHRCxTIXIHRCxTXTIHRCxXxTIHRCX";
int main(int l){for(l+=7;l!=putchar(010);++l);if(*(++_))main
(*_!=88?(putchar(*_^073)|putchar(33))&1:0xffff2a8b);}
User avatar
Corsix
 
Posts: 1181
Joined: Fri Jul 23, 2004 9:33 am
Location: Berkeley, UK

Postby Darryl » Sat Aug 13, 2005 5:44 pm

Ok, you can download a test file here:
http://venus.walagata.com/w/darryl/input.txt

Each line in the file represents 2, 7 card hands. For those two hands you will output the winning(best) 5 card poker hand. There possibly could be a tie for example:

ah 5h 3h 2h 10h ad 3c as 5s 3s 2s 10s 3d 9h

both hands have an "equal" flush, therefore either flush is acceptable as the "Best" hand of the 2
Last edited by Darryl on Sun Aug 14, 2005 7:07 am, edited 1 time in total.
User avatar
Darryl
 
Posts: 1342
Joined: Wed Sep 01, 2004 10:50 am
Location: Cayman Islands

Postby Beer Hunter » Sat Aug 13, 2005 11:43 pm

Weren't all the letters supposed to be lowercase?
User avatar
Beer Hunter
 
Posts: 912
Joined: Sat Dec 13, 2003 7:12 pm
Location: Australia

Postby Corsix » Sun Aug 14, 2005 3:52 am

Also, you've put two spaces between some of the cards.
Code: Select all
#include <stdio.h>
char*_="XxTIHRCXCxTIHRXRCxTIHXHRCxTIXIHRCxTXTIHRCxXxTIHRCX";
int main(int l){for(l+=7;l!=putchar(010);++l);if(*(++_))main
(*_!=88?(putchar(*_^073)|putchar(33))&1:0xffff2a8b);}
User avatar
Corsix
 
Posts: 1181
Joined: Fri Jul 23, 2004 9:33 am
Location: Berkeley, UK

Postby Togra » Sun Aug 14, 2005 4:50 am

I'm in, expecting this to be challenging!
Togra
 
Posts: 188
Joined: Wed Jul 28, 2004 8:51 am
Location: NL

Postby Darryl » Sun Aug 14, 2005 7:08 am

OK, sorry about that . . had used an old program I wrote that generates rand cards, didn't check the output... anyway I edited my previous text to reflect the new file. All lowercase and no extra spaces ( I don't think)
User avatar
Darryl
 
Posts: 1342
Joined: Wed Sep 01, 2004 10:50 am
Location: Cayman Islands

Postby Corsix » Sun Aug 14, 2005 7:42 am

Time for a token count:
Code: Select all
==Overall:==
C45.cpp 1326
==Breakdown:==
Includes 10
Declarations 10
Helper: PutInCardSuits 100
Generic Processing 68
  Royal Flush 71
  Straight Flush 144
  Four of a Kind 136
  Full House 145
  Flush 99
  Straight 292
  Three of a Kind 112
Input 94
Output 38
I've implemented checking for royal flush, straight flush and four of a kind, and already my token count is up to 577. (note: breakdown does not include things that cannot be optimised, like the declaration of main())

Edit: Implemented Full House and upto 796.
Edit2: Added flush, striaght and three of a kind, raising my overall count to 1326
Code: Select all
#include <stdio.h>
char*_="XxTIHRCXCxTIHRXRCxTIHXHRCxTIXIHRCxTXTIHRCxXxTIHRCX";
int main(int l){for(l+=7;l!=putchar(010);++l);if(*(++_))main
(*_!=88?(putchar(*_^073)|putchar(33))&1:0xffff2a8b);}
User avatar
Corsix
 
Posts: 1181
Joined: Fri Jul 23, 2004 9:33 am
Location: Berkeley, UK

Postby exomo » Mon Aug 15, 2005 5:36 am

Just another thing:

We should ALL use int main() and not main() as some did in one of the last contests. Of course you can save 1 token, but if we don't allow this it's equal chances for everybody. It is just very bad code, isn't it?

PS: Starting right now
Who needs a signature anyway.
User avatar
exomo
 
Posts: 935
Joined: Fri Sep 26, 2003 12:30 pm
Location: germany->baden

Postby Beer Hunter » Mon Aug 15, 2005 7:03 am

Might want to disallow GCC's >?= operator as well.
User avatar
Beer Hunter
 
Posts: 912
Joined: Sat Dec 13, 2003 7:12 pm
Location: Australia

Postby Darryl » Mon Aug 15, 2005 7:59 am

what's a >?= operator do?

OK I added those to the rules, also since there where complaints last time no quotes for standard headers like #include "iostream"

maybe instead of giving choice of compiler, should had said it should compile on all three :-)
User avatar
Darryl
 
Posts: 1342
Joined: Wed Sep 01, 2004 10:50 am
Location: Cayman Islands

Postby Corsix » Mon Aug 15, 2005 11:30 am

Darryl wrote:also since there where complaints last time no quotes for standard headers like #include "iostream"
Damnit, why? It compiles without errors/warnings on both MSVC 2003.NET and Dev-C++ 4.9.9.2

I'm thinking compilation on both MSVC and Dev-C++ would be a good thing, as i think it only needs 1 token added ("const") to make my code compile on both.

Edit: In other news, I've finished my "first draft":
Code: Select all
==Overall:==
C45.cpp 1815
==Breakdown:==
Includes 14
Declarations 10
Helper: PutInCardSuits 100
Generic Processing 68
  Royal Flush 71
  Straight Flush 144
  Four of a Kind 138
  Full House 141
  Flush 125
  Straight 292
  Three of a Kind 146
  Two Pairs 197
  One Pair 146
  High Card 84
Input 94
Output 38
Now to make a testing program to check that it works in every situation...
Code: Select all
#include <stdio.h>
char*_="XxTIHRCXCxTIHRXRCxTIHXHRCxTIXIHRCxTXTIHRCxXxTIHRCX";
int main(int l){for(l+=7;l!=putchar(010);++l);if(*(++_))main
(*_!=88?(putchar(*_^073)|putchar(33))&1:0xffff2a8b);}
User avatar
Corsix
 
Posts: 1181
Joined: Fri Jul 23, 2004 9:33 am
Location: Berkeley, UK

Postby Darryl » Mon Aug 15, 2005 1:48 pm

I just finished my first draft too, though I guess I can't officially enter. (or can I?)

As far as the "iostream" goes, I personally like it, I will remove that rule if there are no objections, however it's really kind of pointles because everyone will do it, giving no one an advantage.

Can someone please post the token counter program, the old links don't work anymore.


EDIT: Nevermind, found a link here: http://www.cyberkopia.net/gamer/modules ... d=6&lid=13



Here's the output I got for the test file:
3d 3s 6d ah as
5d 6s 7h 8s 9d
6c 6s kh ks ac
9h 10h 10s ad ah
8h 8d 5h 5d 5c


Now to make a testing program to check that it works in every situation...


if you want for testing purposes, I can generate a large list of hands, if your program can handle it. I kept the contest list short because I'd figure I'd visually check them.


EDIT: 1st Token count 2071
going to bed with 1870
Last edited by Darryl on Mon Aug 15, 2005 8:44 pm, edited 1 time in total.
User avatar
Darryl
 
Posts: 1342
Joined: Wed Sep 01, 2004 10:50 am
Location: Cayman Islands

Next

Return to Contests

Who is online

Users browsing this forum: No registered users and 1 guest