Contest 44: Crazy Calculator

Online C++ programming contests.

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

Postby Invictus » Sat Feb 12, 2005 1:49 am

97 tokens
User avatar
Invictus
 
Posts: 3054
Joined: Tue Oct 21, 2003 12:59 pm

Postby gamma » Sat Feb 12, 2005 2:02 am

97? That is very scary. Or to quote others: BLOODY HELL! WTF? This contest is getting insane.

Any exploits of the knowledge of the target compiler?
Did you count all your header file includes too?
I have no idea where to cut 17 tokens. I'm not sure I can even save 1 token to tie with Corsix. (At the time of writing, I'm still at 114 tokens, but WITH a good night's sleep!)
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 » Sat Feb 12, 2005 2:04 am

I'd like IV to send that to Darobat so that he can confirm that a 97 token working solution is out there. (yes, I am slightly sceptical)
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 » Sat Feb 12, 2005 2:15 am

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
User avatar
Beer Hunter
 
Posts: 912
Joined: Sat Dec 13, 2003 7:12 pm
Location: Australia

Postby Corsix » Sat Feb 12, 2005 2:17 am

LOL yes it would.
BTW. 111 tokens
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 Invictus » Sat Feb 12, 2005 2:36 am

95 tokens

















No... I lied. :cry:
User avatar
Invictus
 
Posts: 3054
Joined: Tue Oct 21, 2003 12:59 pm

Postby Corsix » Sat Feb 12, 2005 5:38 am

Ah well, you tricked gamma. 8)
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 Invictus » Sat Feb 12, 2005 7:18 am

Corsix wrote:Ah well, you tricked gamma. 8)

pwn3d
User avatar
Invictus
 
Posts: 3054
Joined: Tue Oct 21, 2003 12:59 pm

Postby Darryl » Sat Feb 12, 2005 8:59 am

Ok I have to ask for some hints on how you guys got so low... I am stuck @ 204.

1. do you manipulate the file directly using something like fseek or do you load it to a buffer/string 1st?

2. are you using any headers or just std functions that don't necessarily need a header with msvc to work?

what else is there? I've done all the tokxx and msvc exploits I could think of.
User avatar
Darryl
 
Posts: 1342
Joined: Wed Sep 01, 2004 10:50 am
Location: Cayman Islands

Postby Corsix » Sat Feb 12, 2005 9:02 am

The only header I use is fstream. (which includes stdio.h for me - output)
I load the data from the file (using ifstream) into a buffer.

detailed token count:
Code: Select all
Comp44_Tokens.cpp 111
Includes 3
Variables 17
Main Head 5
File IO 25
Processing 53
Output 7
Main Foot 1


Edit: down to 110 tokens
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 Feb 12, 2005 11:23 am

Is there a setting for tokxx that provided that detailed token count, or did you do that by hand. I tried the variouos setting given with tokxx - h

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

Postby Corsix » Sat Feb 12, 2005 11:27 am

I have a batch file:
Code: Select all
echo off
tokxx -a -f html -o analysis.html Comp44_Tokens.cpp
tokxx -f html -o analysis_sections.html Comp44_Tokens.cpp
cls
tokxx -a Comp44_Tokens.cpp
tokxx  Comp44_Tokens.cpp
pause
(mark sections with //BEG: Section -> //END)
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 » Sat Feb 12, 2005 11:44 am

Darryl wrote:1. do you manipulate the file directly using something like fseek or do you load it to a buffer/string 1st?

Load it to a buffer first.

2. are you using any headers or just std functions that don't necessarily need a header with msvc to work?


You need include files to do file input and console output. On my compiler, <fstream> includes <iostream> internally, but Darobat told me that that is not the case with the reference compiler. <cstdio> has everything, though, although the C syntax is not as compact.

what else is there? I've done all the tokxx and msvc exploits I could think of.

Instead of switch statements, you can try and use tables. Now replace the tables with string constants.

Well, I'll let the experts give you advice. My best effort right now is 129, since Darobat turned down two of my ideas because that compiler doesn't accept them. I guess I am at a disadvantage for not having that specific compiler, but anyway, I don't think I could do 110, no matter what I could do with the compiler.
User avatar
Alvaro
Moderator
 
Posts: 5185
Joined: Mon Sep 22, 2003 4:57 pm
Location: NY, USA

Postby Corsix » Sat Feb 12, 2005 11:49 am

Alvaro wrote:Instead of switch statements, you can try and use tables. Now replace the tables with string constants.
Very good hint that one... :wink:
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 Feb 12, 2005 12:48 pm

Alvaro wrote:
You need include files to do file input and console output. On my compiler, <fstream> includes <iostream> internally, but Darobat told me that that is not the case with the reference compiler. <cstdio> has everything, though, although the C syntax is not as compact.


I have<fstream> and <string>: I used printf for output because I didn't need to include a header with it. Guess I should switch from string to char*, though string has what I need and It would be more tokens do do same with char*. Also, including fstream does not inlcude iostream for me automatically.

Instead of switch statements, you can try and use tables. Now replace the tables with string constants.
Instead of switch I was using a string lookup with nested ?: but will look at an all string lookup approach

Well, I'll let the experts give you advice. My best effort right now is 129, since Darobat turned down two of my ideas because that compiler doesn't accept them. I guess I am at a disadvantage for not having that specific compiler, but anyway, I don't think I could do 110, no matter what I could do with the compiler.


You could always download the vc toolkit, it's command line only, but I am sure that's no problem for you.

Darryl
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