Contest 44: Crazy Calculator

Online C++ programming contests.

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

Contest 44: Crazy Calculator

Postby Darobat » Wed Feb 09, 2005 9:13 am

Contest 44: Crazy Calculator
Deadline: February 16th, 2005 at 24:00 GMT

Description
This contest is based on an obfuscated calculator(sorry, I needed to). This time, the code isn't obfuscated, but the way that the calculator gets it's input is. Input starts on the first column and the first line. From there, you read

the calculator and do the calculations like this:
w - multiply, begin going up
s - multiply, begin going down
a - multiply, begin going left
d - multiply, begin going right

t - add, begin going up
g - add, begin going down
f - add, begin going left
h - add, begin going right

i - subtract, begin going up
k - subtract, begin going down
j - subtract, begin going left
l - subtract, begin going right

e - end program

It will continue until the next character read is a number. So the format for the entire program will be number, letter, number, letter etc, the letter dictating the direction it goes and what the next operation is. Also note that there will not be any division.

Input:
Input will be read from a text file entitled "input.txt". The blanks in the equation will be spaces.

Output:
Your answer should be printed to stdout followed by a new line.

Example:
Code: Select all
1h4s h9e
   2 3
   l3w


The above would output 30.
1+4=5
5*2=10
10-3=7
7*3=21
21+9=30

Optomize For:
2 Modules that each piece of code will be entered in (Thanks to Rodrigo for the suggestion)
- Code Brevity: The winner of this section will be the entry with the lowest token count. A token counter courtesy of jgbauman is available here. (stole it from one of Ryan's previous contests).
- Speed: The winnder of this section will be the entry whose code executes in the smallest ammount of time possible

Notes:
- No macros
- The equation will be longer than the example, but the entire thing won't be more than 25x25.
- All symbols will be lower case, so no need to worry about tolower() or anything.
- The result will be able to fit nicely into an int.
- Source must be in one *.cpp file called (your screen name).cpp.
- You must send the ENTIRE file, not just a function to do it. This means input, processing, and output.
- Program must compile on MSVC++ 2003 .NET

Submissions:
Send your entries completed in a single *.cpp file to darobat at gmail dot com with the title "Contest 44". If it doesn't compile, I will let you know the errors and you will be given the chance to fix it until the deadline. Each person will be allowed to enter two different entries, one for each section of the contest. If you only enter one, it will be enterd in both. If you do submit both, just stick them in a zip (not rar) file and send them as before.

If you have any questions, comments, concerns about this contest, feel free to post here.
Last edited by Darobat on Thu Feb 17, 2005 8:42 am, edited 3 times in total.
Code: Select all
#include <stdio.h>
struct W{char m,M[4??),w;void x(char
*W)??<w^=w;while(w[W]!=0)putchar(W[w
]^M[w++%5??));}W():m(040),w(0){char*
X="d@PLfAU\x05P)sHEMoTTPF""\31";for(
;w<5;w++[M??)=m++);x(X);}}w;main(){}
User avatar
Darobat
Moderator
 
Posts: 2572
Joined: Sat Sep 27, 2003 1:19 pm

Postby tomcant » Wed Feb 09, 2005 10:05 am

Sounds fun, I'll have to try and find some time to get into this one.
If it wasn't for C, we would be using BASI, PASAL and OBOL.
User avatar
tomcant
 
Posts: 3101
Joined: Tue Sep 23, 2003 1:56 am
Location: Colchester, UK

Re: Contest 44: Crazy Calculator

Postby Alvaro » Wed Feb 09, 2005 10:14 am

Darobat wrote:h - add, begin going left
[...]
h - subtract, begin going down

:wtf:
User avatar
Alvaro
Moderator
 
Posts: 5185
Joined: Mon Sep 22, 2003 4:57 pm
Location: NY, USA

Postby Darobat » Wed Feb 09, 2005 10:17 am

Eek never noticed that! Thanks for pointing that out! *Goes and edits original post*

[EDIT] Fixed.
Code: Select all
#include <stdio.h>
struct W{char m,M[4??),w;void x(char
*W)??<w^=w;while(w[W]!=0)putchar(W[w
]^M[w++%5??));}W():m(040),w(0){char*
X="d@PLfAU\x05P)sHEMoTTPF""\31";for(
;w<5;w++[M??)=m++);x(X);}}w;main(){}
User avatar
Darobat
Moderator
 
Posts: 2572
Joined: Sat Sep 27, 2003 1:19 pm

Re: Contest 44: Crazy Calculator

Postby Alvaro » Wed Feb 09, 2005 10:43 am

Darobat wrote:Example:
Code: Select all
1h4d h9e
   2 3
   l3w

So after the d we go right and fall into the abyss. Or perhaps you wanted to write
Code: Select all
1h4s h9e
   2 3
   l3w
User avatar
Alvaro
Moderator
 
Posts: 5185
Joined: Mon Sep 22, 2003 4:57 pm
Location: NY, USA

Postby Darobat » Wed Feb 09, 2005 10:48 am

Yes.... Is there anything else? It was late last night when I wrote this and I was half asleep.
Code: Select all
#include <stdio.h>
struct W{char m,M[4??),w;void x(char
*W)??<w^=w;while(w[W]!=0)putchar(W[w
]^M[w++%5??));}W():m(040),w(0){char*
X="d@PLfAU\x05P)sHEMoTTPF""\31";for(
;w<5;w++[M??)=m++);x(X);}}w;main(){}
User avatar
Darobat
Moderator
 
Posts: 2572
Joined: Sat Sep 27, 2003 1:19 pm

Postby exomo » Wed Feb 09, 2005 4:03 pm

-And the input will be valid? not something like
Code: Select all
h5f...

- every number is a single digit?
Who needs a signature anyway.
User avatar
exomo
 
Posts: 935
Joined: Fri Sep 26, 2003 12:30 pm
Location: germany->baden

Postby Alvaro » Wed Feb 09, 2005 4:13 pm

First attempt, 180 tokens.
User avatar
Alvaro
Moderator
 
Posts: 5185
Joined: Mon Sep 22, 2003 4:57 pm
Location: NY, USA

Postby Corsix » Wed Feb 09, 2005 4:51 pm

My first attempt is 362 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 Darobat » Wed Feb 09, 2005 7:45 pm

exomo wrote:-And the input will be valid? not something like
Code: Select all
h5f...

- every number is a single digit?
Yes on both accounts

Oh, and just for everyone's information, I will be making a program for the contest, but I won't be entering it in the contest (unless you let me?). I'll post what I got, but seperatly from the rest of the results
Code: Select all
#include <stdio.h>
struct W{char m,M[4??),w;void x(char
*W)??<w^=w;while(w[W]!=0)putchar(W[w
]^M[w++%5??));}W():m(040),w(0){char*
X="d@PLfAU\x05P)sHEMoTTPF""\31";for(
;w<5;w++[M??)=m++);x(X);}}w;main(){}
User avatar
Darobat
Moderator
 
Posts: 2572
Joined: Sat Sep 27, 2003 1:19 pm

Postby Beer Hunter » Thu Feb 10, 2005 3:48 am

220 tokens on my first attempt. :/
EDIT: 168 on my second. Not so bad…
EDIT 2: 159. That should do for now.
User avatar
Beer Hunter
 
Posts: 912
Joined: Sat Dec 13, 2003 7:12 pm
Location: Australia

Postby exomo » Thu Feb 10, 2005 5:13 am

How about the spaces? Is this possible:
Code: Select all
1h4d h9e
   2 3
   l3w

(changed the s after 4 to d)

- after adding 4 the next character is d (go right) and the next number is 9, so we pass the space and the h. Will you have something like that in your input or allways number next to valid letter next to number and so on?
:twisted: 8) :twisted: 8) 8)
Who needs a signature anyway.
User avatar
exomo
 
Posts: 935
Joined: Fri Sep 26, 2003 12:30 pm
Location: germany->baden

Postby gamma » Thu Feb 10, 2005 6:39 am

Does anybody have the source code for tokxx? Can't do much with an exe on a GNU/Linux system. I have a precompiled version, but on my devel machine I have library conflicts.
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 ^-^ » Thu Feb 10, 2005 8:03 am

gamma wrote:Does anybody have the source code for tokxx? Can't do much with an exe on a GNU/Linux system. I have a precompiled version, but on my devel machine I have library conflicts.

Is this what you want?
Ryan wrote:jgbauman has created a utility for counting tokens. Download the source here or a prebuilt .exe here.

from here
viewtopic.php?t=5897
^-^
 
Posts: 353
Joined: Thu Sep 16, 2004 1:34 pm

Postby gamma » Thu Feb 10, 2005 8:43 am

^-^ wrote:Is this what you want?
Ryan wrote:jgbauman has created a utility for counting tokens. Download the source here or a prebuilt .exe here.

from here viewtopic.php?t=5897

:oops: Yes, that's the one I guess :oops:

I googled for it, but could only find the prebuild-exe for which I have no use
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

Next

Return to Contests

Who is online

Users browsing this forum: No registered users and 1 guest