Contest 45: 7 Card Draw

Online C++ programming contests.

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

Postby Safari » Thu Aug 25, 2005 4:51 am

Alvaro wrote:The expression `A[B]' just means `*(A+B)'. A string constant has type `const char *', and its value is the address of the first character of the string, so

"foo"[var] == *("foo"+var),

which is the character `var' places after the beginning of the string constant.

An even more obscure way of doing the same thing is reversing the operands, like this:

variable["some string here"]

That makes sence. So "foo" (in your example) transforms to an integer?

Lets say that "foo" = 5. So writing

cout << "foo"[var]

equals

cout << var[5]
?

BTW: If we find the best hand are we allowed to output all types of hand if we output the best one first? ie, say that a hand both have Two Pair and flush, am I allowed to print both of them IF I print flush first?
User avatar
Safari
 
Posts: 1362
Joined: Sun Sep 19, 2004 11:07 am

Postby Darryl » Thu Aug 25, 2005 7:17 am

Safari wrote:BTW: If we find the best hand are we allowed to output all types of hand if we output the best one first? ie, say that a hand both have Two Pair and flush, am I allowed to print both of them IF I print flush first?


Uh..no, for each line in the file there are 2 7-card hands, and you should output the best 5 card poker hand that comes from one of the 2 hands. Also just to note, if a hand has two pair and a flush, you must output the flush, even if the 2 pair beats the other hand which might only have 1 pair.
User avatar
Darryl
 
Posts: 1342
Joined: Wed Sep 01, 2004 10:50 am
Location: Cayman Islands

Postby Safari » Thu Aug 25, 2005 8:49 am

Darryl wrote:Here's another sample input with some of the more difficult to eval hands.
ah kh qh jh 10h 2h 8s as 2s 3s 6d 4s 2c 5s
2h 3h 4d jd 4h 5h 6h as 2s 3s 6d 4s 2c 5s
ad kh qs jd 10h 2h 8s as 2d 3s 6d 4s 2c 5h
2h 3c 4d jd 4s 5h 6h as 2s 3c 6d 4s 2c 5h
qh 7h qd 4d 4h 2h 8s as 3s 3d 6d 4c 2c ah
5s 2s ks 3s 8d 10s 5c 4c 2c 7h 3c 10c kc 6s
ks 6s ac 9c 6c 3c kh 9s 4c 9d 7d jc 2h 10c
kc 8s kh ks 6h 5h 4s 5s 2h 10h 10s 9h ah ad
5d 5c 5h 8d 8h js 10s 3c 7c 4h 6s 2s ah 4s


and the expected output

qh kh jh ah 10h
6h 5h 4h 3h 2h
qs kh jd ad 10h
6h 5h 4d 3c 2h
as ah 6d 3s 3d //4d 4h 4c ah as better?
ks 5s 3s 2s 10s
ks kh ac 6s 6c //9d 9s 9c kh ks
ks kh kc 8s 6h //ks kh kc ad ah
8h 8d 5h 5d 5c



My first working solution (I think) = 768 tokens :?
I guess that's OK since only bh had a lower token count on his first try. :)
User avatar
Safari
 
Posts: 1362
Joined: Sun Sep 19, 2004 11:07 am

Postby Darryl » Thu Aug 25, 2005 9:32 am

No you are treating the whole line as one hand when there are two

qh 7h qd 4d 4h 2h 8s as 3s 3d 6d 4c 2c ah
treat above like this:

qh 7h qd 4d 4h 2h 8s <--hand 1 hand2--> as 3s 3d 6d 4c 2c ah

best for hand 1 = qh qd 4d 4h 8s
best for hand 2 = as ah 3s 3d 6d
hand 2 is better and should be output
safari wrote:My first working solution (I think) = 768 tokens :?
I guess that's OK since only bh had a lower token count on his first try. :)


keep it up, my first working solution was over 1500, then I rewrote it and my first rewrite was about what yours is

now at: 361
User avatar
Darryl
 
Posts: 1342
Joined: Wed Sep 01, 2004 10:50 am
Location: Cayman Islands

Postby Safari » Thu Aug 25, 2005 12:49 pm

Arrggh, more tokens.

This is frustrating. That stupid number "10" is killing me. No matter how I do I'll never get down to 400. :x
Anyways, I started with a new solutions and I'm currently at 139 tokens without the analysis function. Not even sure I'll manage to pull it off (school just started).

Well, looking forward to see the solutions @ 300 tokens.
User avatar
Safari
 
Posts: 1362
Joined: Sun Sep 19, 2004 11:07 am

Postby Corsix » Thu Aug 25, 2005 2:00 pm

You're allowing "iostream"? Then I'm down to 307.
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 » Thu Aug 25, 2005 3:07 pm

Sorry to tell you I'm out before I even started.
I had a very bad accident and I have other things in mind now. And I hardly can write with my left hand wrapped (don't know how to call it)
If I find some time and a free mind I will start, but I doubt this will happen in the next 5 days.
Who needs a signature anyway.
User avatar
exomo
 
Posts: 880
Joined: Fri Sep 26, 2003 12:30 pm
Location: germany->baden

Postby Corsix » Thu Aug 25, 2005 3:11 pm

Aww... :thumbdown:
Hope you get better soon :thumbup:
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 » Thu Aug 25, 2005 7:53 pm

Corsix wrote:You're allowing "iostream"? Then I'm down to 307.


Yea, but darn, I was hoping you were already counting that, anyway I am at 349 ... only 42 away... and closing


exomo, sorry to here, feel better soon!
User avatar
Darryl
 
Posts: 1342
Joined: Wed Sep 01, 2004 10:50 am
Location: Cayman Islands

Postby Corsix » Fri Aug 26, 2005 3:46 am

That 307 was so intimidating that I had to squeeze it down to 298.
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 coolian » Fri Aug 26, 2005 6:32 am

WTF corsix, you've got to slow down a bit :mrgreen:!
User avatar
coolian
 
Posts: 1012
Joined: Wed Oct 29, 2003 6:17 pm
Location: USA

Postby Corsix » Fri Aug 26, 2005 6:51 am

lol :D
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 » Fri Aug 26, 2005 7:35 am

Yea I'm almost at the point that my only hope is that corsix's evaluates a hand wrong. Beerhunter's been quiet lately, maybe on vacation, or waiting to suprises us with a ultra low count.
User avatar
Darryl
 
Posts: 1342
Joined: Wed Sep 01, 2004 10:50 am
Location: Cayman Islands

Postby Beer Hunter » Fri Aug 26, 2005 7:52 am

Oh, I've just been busy with other things. :-)
313.
User avatar
Beer Hunter
 
Posts: 912
Joined: Sat Dec 13, 2003 7:12 pm
Location: Australia

Postby Darryl » Sat Aug 27, 2005 10:31 am

OK everyone, since the deadline is coming up, I am going to stop working on mine and enter it at 346 tokens. I am doing this so you guys can start submitting entries and I can pre-test them to give you a chance to correct any errors.

I will be conducting three test, 2 randomly generated files and one file I custom produce in order to try and catch any wrong hand analysis. If your program doesn't compile or produces a runtime error or outputs a incorrect hand, I'll let you know. With the hand analysis though I won't reveal the cards but I will tell you what rank it was ie. straight, flush etc.

Thanks, for participating, this was kind of fun, I did better than I thought I would, but so did everyone else... i can't believe there's a solution under 300 tokens.
User avatar
Darryl
 
Posts: 1342
Joined: Wed Sep 01, 2004 10:50 am
Location: Cayman Islands

PreviousNext

Return to Contests

Who is online

Users browsing this forum: No registered users and 0 guests