Beginners Brevity Contest: BUZZ

Online C++ programming contests.

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

Postby Corsix » Mon Oct 03, 2005 11:15 am

Safari wrote:Corsix: Is it just me but does mine and yours look like eachother a bit?
Indeed, they do look similar:

Yours:[syntax="cpp"]using namespace std;
class Safari : public player {
int counter, left, num;
string init (int player_position, int num_of_players) {
counter = 0;
return left = player_position, num = num_of_players, "Safari";
}
string respond (string last_response) {
left = last_response=="buzz"?num-left:left;
char s[++counter]; //Should be more than enough
return --left%num?"":counter%7*counter%11*!strchr(itoa (counter, s, 10),'7')?s:"buzz";
}
};
[/syntax]

Mine:[syntax="cpp"]using namespace std;

// "struct" to make everything public by default
// inherits from tm to save on declaring 3 ints
struct Corsix_Player : player, tm
{
// current turn no (1 is 1st), number of players in the game, and how many turns until 'our' go
// tm_sec == m_turn_number
// tm_min == m_number_of_players
// tm_hour == m_turns_to_go
// int m_turn_number, m_number_of_players, m_turns_to_go;

// string buffer for holding m_turn_number as a string
char buffer[64];

string init(int player_position, int num_of_players)
{
// I <3 the comma operator
return tm_sec = 0, tm_min = num_of_players, tm_hour = player_position, "Corsix";
}

string respond(string last_response)
{
// More comma and inline if goodness :)
return
tm_hour = "buzz" == last_response ? tm_min - tm_hour : tm_hour,
++tm_sec,
--tm_hour%tm_min ? "" : strchr(_itoa(tm_sec,buffer,10),'7') || "\1\0\0\0\0\0\0\1\0\0\0\1\0\0\1\0\0\0\0\0\0\1\1\0\0\0\0\0\1\0\0\0\0\1\0\1\0\0\0\0\0\0\1\0\1\0\0\0\0\1\0\0\0\0\0\1\1\0\0\0\0\0\0\1\0\0\1\0\0\0\1\0\0\0\0\0\0"[tm_sec%77] ? "buzz" : buffer;
}
};[/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 Dante Shamest » Mon Oct 03, 2005 11:33 am

Darryl wrote:Last, but not least, to get you guys thinking about the next contest and forming stategies. It's going to be an AI contest of the classic Nibble(snakes) game except there will be multiple snakes, each controlled by one of your player classes.


That sounds like a cool contest. Think I'll enter that one too. :)

I think Contests is quickly becoming my favourite forum on this site. :thumbs:

Darryl wrote:Updated results, I think i missed them when I switch to using Dev-c.


Thanks. :)

Darryl wrote:Speaking of which I have to say I am pretty impressed with Dev-C, i havn't used it in a while and it definitely outshone MS in string handling and the version I am using seemed pretty stable too. (Though it compiled a tad slow)


I use both but don't really see much of a difference in the string handling. In what area do they differ to you? Speed?
User avatar
Dante Shamest
Moderator
 
Posts: 3131
Joined: Wed Oct 22, 2003 10:29 pm
Location: Malaysia

Postby gamma » Mon Oct 03, 2005 12:11 pm

Darryl wrote:Gamma2: 101 (semi-hyperstring? 8 meg!!) Had u sent another solution u wanted me to count here as non-hyperstring?
I went for pure ultra low token count (as I could not make it below 110 orso with the "up-to-intmax" cat). That 101 was intended as hyperstring. It abused C-strings as storage for signed shorts. If somebody wants to see my one-liner-with-out-ternary-operator in respond(), feel free to ask.
while (true){sleep(28800);work(57600);}
"Free" as in speech is so much better than "free" as in beer.
User avatar
gamma
 
Posts: 178
Joined: Mon Dec 01, 2003 9:16 am
Location: The Netherlands

Postby gamma » Mon Oct 03, 2005 12:16 pm

Corsix wrote:Mine:[syntax="cpp"]..._itoa(...)[/syntax]
Aargh, are those allowed? IIRC g++ extended commands weren't allowed.
while (true){sleep(28800);work(57600);}
"Free" as in speech is so much better than "free" as in beer.
User avatar
gamma
 
Posts: 178
Joined: Mon Dec 01, 2003 9:16 am
Location: The Netherlands

Postby gamma » Mon Oct 03, 2005 12:20 pm

About the "Corsix-trick" (yes, I think some credit is in order): can somebody (preferably by means of the standard) confirm that struct can have a class as base? g++ does not complain about, so I have a good feeling that it is allowed, but confirmation is welcome!
while (true){sleep(28800);work(57600);}
"Free" as in speech is so much better than "free" as in beer.
User avatar
gamma
 
Posts: 178
Joined: Mon Dec 01, 2003 9:16 am
Location: The Netherlands

Postby Alvaro » Mon Oct 03, 2005 12:29 pm

gamma wrote:About the "Corsix-trick" (yes, I think some credit is in order): can somebody (preferably by means of the standard) confirm that struct can have a class as base? g++ does not complain about, so I have a good feeling that it is allowed, but confirmation is welcome!

I don't know if this is explicitly mentioned in the standard, but I don't see the problem with a struct deriving from a class. Structs and classes are the same thing, except by default things are public in a struct and private in a class.

I think with the `tm' trick, the `_itoa' trick and my algorithm, I can build a super low token solution. I'll post what I get, just for fun.
User avatar
Alvaro
Moderator
 
Posts: 5185
Joined: Mon Sep 22, 2003 4:57 pm
Location: NY, USA

Postby Darryl » Mon Oct 03, 2005 12:39 pm

Dante Shamest wrote:I use both but don't really see much of a difference in the string handling. In what area do they differ to you? Speed?


Size, MS 2003 limits literal strings to like 2k even when \cr line continuations. The Beta has up that limit to 16k. Because of that, some of the entries would not compile which is the reason I switch to DevC...it's probably not dev-c per se but the underlying compiler that does not retrict the string literals.

Gamma, regarding itoa, accoring to one referrence, it's not ansi, but supported by some compilers. Well, it seems MS and Dev-c both supports it.

As far as structs with class bases, from the standard:
A structure is a class defined with the class-key struct; its members and base classes (clause 10) are public
by default (clause 11).


FYI it also list unions as a class type also.
User avatar
Darryl
 
Posts: 1342
Joined: Wed Sep 01, 2004 10:50 am
Location: Cayman Islands

Postby Corsix » Mon Oct 03, 2005 12:44 pm

ok gamma, same token count but using sprintf instead of _itoa:[syntax="cpp"]using namespace std;

// "struct" to make everything public by default
// inherits from tm to save on declaring 3 ints
struct Corsix_Player : player, tm
{
// current turn no (1 is 1st), number of players in the game, and how many turns until 'our' go
// tm_sec == m_turn_number
// tm_min == m_number_of_players
// tm_hour == m_turns_to_go
// int m_turn_number, m_number_of_players, m_turns_to_go;

// string buffer for holding m_turn_number as a string
char buffer[64];

string init(int player_position, int num_of_players)
{
// I <3 the comma operator
return tm_sec = 0, tm_min = num_of_players, tm_hour = player_position, "Corsix";
}

string respond(string last_response)
{
// More comma and inline if goodness :)
return
tm_hour = "buzz" == last_response ? tm_min - tm_hour : tm_hour,
sprintf(buffer,"%i",++tm_sec),
--tm_hour%tm_min ? "" : strchr(buffer,'7') || "\1\0\0\0\0\0\0\1\0\0\0\1\0\0\1\0\0\0\0\0\0\1\1\0\0\0\0\0\1\0\0\0\0\1\0\1\0\0\0\0\0\0\1\0\1\0\0\0\0\1\0\0\0\0\0\1\1\0\0\0\0\0\0\1\0\0\1\0\0\0\1\0\0\0\0\0\0"[tm_sec%77] ? "buzz" : buffer;
}
};[/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 gamma » Mon Oct 03, 2005 12:46 pm

I dance with joy! I'm still impressed with tricks presented. I thought my mind was twisted, but it seems not half as twisted as yours. Congratulations!
while (true){sleep(28800);work(57600);}
"Free" as in speech is so much better than "free" as in beer.
User avatar
gamma
 
Posts: 178
Joined: Mon Dec 01, 2003 9:16 am
Location: The Netherlands

Postby Corsix » Mon Oct 03, 2005 12:48 pm

gamma wrote:I thought my mind was twisted, but it seems not half as twisted as yours.
Is that a good thing or a bad thing? :lol:
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 Alvaro » Mon Oct 03, 2005 12:49 pm

98 tokens:
[syntax="cpp"]using namespace std;

struct Alvaro_with_Corsixs_tm_trick:player,tm {
string init(int player_position, int num_of_players) {
tm_sec=0;
tm_min=player_position;
tm_hour=num_of_players;
return "Alvaro with Corsix's tm trick:";
}

string respond(string response) {
char s[1000];
tm_min*="\1\377"[response=="buzz"];
sprintf(s,"%d",++tm_sec);
return --tm_min%tm_hour?"":"\1\0\0\0\0\0\0\1\0\0\0\1\0\0\1\0\0\0\0\0\0\1\1\0\0\0\0\0\1\0\0\0\0\1\0\1\0\0\0\0\0\0\1\0\1\0\0\0\0\1\0\0\0\0\0\1\1\0\0\0\0\0\0\1\0\0\1\0\0\0\1\0\0\0\0\0\0"[tm_sec%77]||strchr(s,'7')?"buzz":s;
}
};

[/syntax]
Last edited by Alvaro on Mon Oct 03, 2005 12:57 pm, edited 1 time in total.
User avatar
Alvaro
Moderator
 
Posts: 5185
Joined: Mon Sep 22, 2003 4:57 pm
Location: NY, USA

Postby gamma » Mon Oct 03, 2005 12:51 pm

Corsix wrote:
gamma wrote:I thought my mind was twisted, but it seems not half as twisted as yours.
Is that a good thing or a bad thing? :lol:
In these contests? The madder the better (or is this crappy English?) As mad as a hat as you can be. Always thinking abouth other strategies, algorithms, styles, notations... yes, that is a good thing.

Note: ... and thinking about other ways is what costs me loads of time, but brings me also a lot of joy.

Edit: typo/crappy english.
Last edited by gamma on Mon Oct 03, 2005 12:53 pm, edited 1 time in total.
while (true){sleep(28800);work(57600);}
"Free" as in speech is so much better than "free" as in beer.
User avatar
gamma
 
Posts: 178
Joined: Mon Dec 01, 2003 9:16 am
Location: The Netherlands

Postby gamma » Mon Oct 03, 2005 12:53 pm

Alvaro wrote:98 tokens/struct Alvaro_with_Corsixs_tm_trick
Can you save a token on the 78 solution too?
while (true){sleep(28800);work(57600);}
"Free" as in speech is so much better than "free" as in beer.
User avatar
gamma
 
Posts: 178
Joined: Mon Dec 01, 2003 9:16 am
Location: The Netherlands

Postby Corsix » Mon Oct 03, 2005 12:53 pm

Alvaro wrote:[syntax="cpp"] tm_min*="\1\377"[response=="buzz"];[/syntax]
Could you explain that bit please?
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 gamma » Mon Oct 03, 2005 12:56 pm

Corsix wrote:
Alvaro wrote:[syntax="cpp"] tm_min*="\1\377"[response=="buzz"];[/syntax]
Could you explain that bit please?
"response=="buzz" results in either 1 or 0. "\1\377"[0] yields the character '\1' (which can be used like an int with value 1) and "\1\377"[1] yields the character '\377' (which can be used like an int with value -1).

Octal character notation comes handy for writing small negative ints ;-).

Edit:
Effectively, tm_min is negated when the response was "buzz".
while (true){sleep(28800);work(57600);}
"Free" as in speech is so much better than "free" as in beer.
User avatar
gamma
 
Posts: 178
Joined: Mon Dec 01, 2003 9:16 am
Location: The Netherlands

PreviousNext

Return to Contests

Who is online

Users browsing this forum: No registered users and 1 guest