Contest 45: 7 Card Draw

Online C++ programming contests.

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

Postby exomo » Mon Aug 15, 2005 6:24 pm

I solved mathschallenge #54 but I don't have the source any more.

I just finished the "read in the symbols" section, but I'm not satisfied yet. The results are too hard to handle which will result in many tokens I need.
When I looked at the mathschallenge problem again I noticed that ten was written as 'T' in the input file. But I guess you won't change the rules to make it easier to handle for me 8)
Who needs a signature anyway.
User avatar
exomo
 
Posts: 894
Joined: Fri Sep 26, 2003 12:30 pm
Location: germany->baden

Postby Beer Hunter » Mon Aug 15, 2005 11:59 pm

Darryl wrote:what's a >?= operator do?
Something that takes more tokens in standard C++. :-)
Just disallow the use of compiler extensions; they're not in the spirit of the contest.
User avatar
Beer Hunter
 
Posts: 912
Joined: Sat Dec 13, 2003 7:12 pm
Location: Australia

Postby Togra » Tue Aug 16, 2005 1:24 am

Beer Hunter, contest 44 wrote:I could get down to 74 tokens just by converting my main loop into machine code, putting it in a string literal and executing it — but that would be cheating
Well, I don't see an explicit rule against such a thing (no macro's maybe?)... But I agree it's cheating.

However, I'd really like to have consensus on these kind of approaches. I had an idea during coffee break yesterday (well, actually a friend inspired me). The idea theoretically allows any token-brevity problem to be solved in a few hundred tokens. So it gives a upper limit - whenever the programming task is too great, flip over to BF. It involves a lot more coding, but exploits the "string literals is one token"-fact maximally! Before sharing this idea with you (and abandoning it), take a guess...
Togra
 
Posts: 188
Joined: Wed Jul 28, 2004 8:51 am
Location: NL

Postby Wilderness Child » Tue Aug 16, 2005 2:03 am

Darryl wrote: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

Does anyone have the source of this? An MS-DOS .exe is a bit difficult to run on a Linux system.
Wilderness Child
 
Posts: 11
Joined: Tue Nov 02, 2004 11:42 am
Location: The Netherlands

Postby Corsix » Tue Aug 16, 2005 2:52 am

exomo wrote:When I looked at the mathschallenge problem again I noticed that ten was written as 'T' in the input file. But I guess you won't change the rules to make it easier to handle for me 8)
That would make it too easy, it's alot harder when one card is three characters instead of two.

Edit: Part 1 of my checking program in done:
Code: Select all
if(HandMatches("ah qh kh 10h jh","ah kh qh jh 10h"))
    /* code */

if(HandMatches("10h 10c 7s 7c 5d","10h 10c 7s 7c $1","5c 5d"))
    /* code */
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 Beer Hunter » Tue Aug 16, 2005 4:59 am

Well, I finally got some time to work on my code. My first, completely unoptimised attempt is 420 tokens. What on earth are you people doing wrong? ;-)
User avatar
Beer Hunter
 
Posts: 912
Joined: Sat Dec 13, 2003 7:12 pm
Location: Australia

Postby Corsix » Tue Aug 16, 2005 5:01 am

Beer Hunter wrote:Well, I finally got some time to work on my code. My first, completely unoptimised attempt is 420 tokens. What on earth are you people doing wrong? ;-)
What ??!?

Edit: In other news, I'm down to 1432
Edit2: 1399
Last edited by Corsix on Tue Aug 16, 2005 5:22 am, edited 1 time in total.
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 Beer Hunter » Tue Aug 16, 2005 5:19 am

Well, clearly the problem is that you special-cased the royal flush, which already beats every other hand even without special casing. ;-)
By the way, I believe the punctuation you're looking for is '‽'. ;-)
User avatar
Beer Hunter
 
Posts: 912
Joined: Sat Dec 13, 2003 7:12 pm
Location: Australia

Postby Corsix » Tue Aug 16, 2005 5:23 am

Yes, I did spot and fix that.

Code: Select all
==Overall:==
C45.cpp 1318
==Breakdown:==
Includes 14
Declarations 28
Helper: PutInCardSuits 84
Generic Processing 111
  Royal Flush 3
  Straight Flush 144
  Four of a Kind 113
  Full House 75
  Flush 121
  Straight 93
  Three of a Kind 103
  Two Pairs 121
  One Pair 103
  High Card 74
Input 89
Output 35


... 1268
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 Beer Hunter » Tue Aug 16, 2005 7:39 am

Code: Select all
includes: 24
globals: 3
function to examine a group of seven cards: 251
main(): 113

(total: 391)
The third thing, the function that examines seven cards, takes a pointer to an array of strings in the same format as in the input file. It rearranges the array elements so that the best group of five cards is at the beginning, and then returns an incomprehensible number. I'd like to tell you how many tokens are spent on each rule, but it's much too hard to tell.
User avatar
Beer Hunter
 
Posts: 912
Joined: Sat Dec 13, 2003 7:12 pm
Location: Australia

Postby Togra » Tue Aug 16, 2005 1:00 pm

No please, you're already telling too much :(! Now I'm afraid my own creativity will be suppressed by the need to reconstruct your method...
Togra
 
Posts: 188
Joined: Wed Jul 28, 2004 8:51 am
Location: NL

Postby Corsix » Wed Aug 17, 2005 5:17 am

I've got an idea of how to get a very low token count without a machine code string literal. :twisted: :twisted:
I just have to wait for my computer to look at 311,875,200 computations...
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 » Wed Aug 17, 2005 6:05 am

Not that I am condoning it for this contest, but out of curiosity, how to you execute machine code from a string literal?
User avatar
Darryl
 
Posts: 1342
Joined: Wed Sep 01, 2004 10:50 am
Location: Cayman Islands

Postby Corsix » Wed Aug 17, 2005 6:22 am

[syntax="cpp"]char sASM[] = "\x8B\x45\x08\xC7\x00\x2A\x00\x00\x00\xC3";

void ExecuteStringAsm(char* sAsm, ...)
{
__asm call dword ptr [sAsm]
}
[/syntax]
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 » Wed Aug 17, 2005 4:10 pm

Ok I rewrote mine from scratch with a new strategy and I am at 728 for my new first draft with plenty of fat to cut. :-)

.. 758 :-(

There was a problem differentiating 2-6 vs A-5 straights) The whole Ace hi-lo thing has been my most difficult problem I think

:-) 736 - back on track

includes 19
globals 41
Rank Hands 419
main 5
input 20
Hand Sorting/comparison 161
Output + closing brace 29


..694
..662 off to bed
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 1 guest