Indeed, they do look similar:Safari wrote:Corsix: Is it just me but does mine and yours look like eachother a bit?
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]
