Obfuscate Code Contest 4 - Results Poll

Online C++ programming contests.

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

Postby MXP » Mon Dec 13, 2004 6:51 pm

Mattxl wrote:Hey gamma, main can be void. That's the way I was taught back in the day. "_"

If that day was before 1998 then that is understandable since the standard didn't exist then. After 1998, however, it does and it says main() must return an int.

I made the code in MSVC++ 6.0 and it works fine. Sorry you have problems with it.

MSVC++ 6.0 doesn't follow the standard very well, in part because the standard didn't exist when MSVC++ 6.0 was released.
Need information on a function I've posted? Chances are it's at the MSDN.
MXP
 
Posts: 6506
Joined: Mon Sep 22, 2003 5:27 pm

Postby Mattxl » Mon Dec 13, 2004 8:25 pm

Yeah I first learned C++ around 1995-97. I then took some classes to expand my knowledge in 2000-01. But even in those classes they never made a big deal about main returning an int. I sometimes return an int and sometimes don't. It just depends on my mood. :lol:
Mattxl
 
Posts: 19
Joined: Thu Nov 18, 2004 7:41 pm

Postby Beer Hunter » Tue Dec 14, 2004 12:44 am

gamma wrote:Note: Beerhunter assumes chars are unsigned, while they could be signed!
If I did, it was entirely by accident. Where did I do so?
User avatar
Beer Hunter
 
Posts: 912
Joined: Sat Dec 13, 2003 7:12 pm
Location: Australia

Postby exomo » Tue Dec 14, 2004 2:42 am

gamma wrote:How about a deal: I'll test yours and you try to unravel my code.
Since Darobat's compiler wasn't that ansi compliant, I had to make a second version, which is also nice to decrypt perhaps. Almost the same code, but with extra defines (stringification!) an some extra art. It is available here:http://www.fmf.nl/~dopheide/darobat/final03.cc


OK, I will try to make your first version readable. It compiles and runs perfectly for me.
Who needs a signature anyway.
User avatar
exomo
 
Posts: 879
Joined: Fri Sep 26, 2003 12:30 pm
Location: germany->baden

Postby Togra » Tue Dec 14, 2004 3:17 am

Difficult choice....

Corsix and Gamma.
Togra
 
Posts: 188
Joined: Wed Jul 28, 2004 8:51 am
Location: NL

Postby Safari » Thu Dec 16, 2004 9:43 am

Can someone tell me how to think? I'm thinking like this.

It should read the file and find @. And then it puts the position of the @ in a array (position like in a graph (1, 4)). Then it should "move" from the @. If it's a wall on the left it should try another direction (if-s. But Then it will allways first check left and then right. It would be better if it went in random directions, right?). If it enters a dead end it should put another wall there. For example:

Code: Select all
###########  ##...
#
##############...

1st loop:

###########  ##...
##<--------<-------<----
##############...

2nd loop:

###########  ##...
###<----------------<-----
##############...

10th loop

###########  ##...
###########^----<---<--
##############...


Is that a smart way? Ofcourse the whole map is saved in a array with cordinates.

Then it should loop until it find !.

Now the trycky part. How will it find the fastest way? Maybe I should but X on roads it have traveled. So it should forst take roads where there isn't X, but if there's no way out it should take X. But then another question comes up.


Code: Select all
#######!############
#######XXXXXXXXXXXX#
####### ##########X#
##XXXXXXXXX#XXXXXXX#
###X###X##X####X####
###X######XXXXX?####
###X###X#######X####
###X###XX#####XX####
###X#XXX#XXXXXXX####
####X## #######X####
####X## #######X####
##XXXXXXXXXXXXXX####
##### ## ###X#######
##### ## ###X#######
##       ###@      #
##### ## ######### #
##### ## ######### #
#        ######### #
##### #######      #
####################


Now it's at ? . The problem is that it first goes up and down, then left and right. So now it would rather go up then the fastest way.

I'm not that good at c++ so I didn't understand that much from the code gamma "decrypted" :oops:
Last edited by Safari on Thu Dec 16, 2004 10:03 am, edited 1 time in total.
User avatar
Safari
 
Posts: 1362
Joined: Sun Sep 19, 2004 11:07 am

Postby exomo » Thu Dec 16, 2004 9:56 am

Not bad for the start. That is what I had first.

Look at my code to see a simple way. It's not the fastest algorithm I know, but it is the simplest.

I added information for every point in the map on "where to go" and "how long it took me to go there. If I come across a point again I can see if the new way is shorter or not. If it is shorter overwrite it.
Who needs a signature anyway.
User avatar
exomo
 
Posts: 879
Joined: Fri Sep 26, 2003 12:30 pm
Location: germany->baden

Postby gamma » Thu Dec 16, 2004 10:45 am

The easiest to code and to understand would be a flood fill I guess. (Well... perhaps a simple recursion would be easier to understand). Anyway, here is my explanation of flooding this maze by example:
N = 0
1) See what you can reach in N steps without using a square double.
2) If you can reach the end point, it must be shortest.
3) Otherwise: increase N.
Code: Select all
######    ######    ######    #######   ######    ######
@   # -> 1@1  # -> 1@12 # -> 1@12 # -> 1@123# -> 1@123#
#  # !    #1 # !    #12# !    #12# !    #12#4!    #12#45 <- found it.
###  #    ###  #    ###  #    ###  #    ###  #    ### 5#

For the implementation, I advise a queue. Pseudo code:
1) push the starting point in the (back of the) queue.
2) while queue_not_empty repeat
3) get the position in front of the queue ("pop")
4) if the front is end point, you are done (leave while)
5) mark this spot.
6) push all neighbours that are possible (i.e. inside map, not wall, not marked etc)

If you did not find an endpoint, the queue will drain and become empty (because there are no more spaces that are possible). There seems to be no solution.
If you find a endpoint, you have found just 1 shortest route. There may be other that are equally fast. But there can't be a route that is faster (no proof given here).

humor mode:
See my code for an example 8)
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 schloob » Sun Dec 19, 2004 12:26 am

the only part about my thing thats actually like obfuscated is this line

Code: Select all
(s>1)[schloooooob]+=((s%2)*2-1);


i forgot how about it works :D



im gonna go with corsix and beer hunter, for originality..

darobats are always cliché, the others were just not as good :P

mattxl was third but we only get 2 votes so, sorry ;P
:]
User avatar
schloob
 
Posts: 1853
Joined: Mon Feb 16, 2004 10:29 am
Location: Seattle

Postby Safari » Mon Dec 20, 2004 12:59 pm

Yeay, I solved it with flood fill :) But in php
User avatar
Safari
 
Posts: 1362
Joined: Sun Sep 19, 2004 11:07 am

Previous

Return to Contests

Who is online

Users browsing this forum: No registered users and 2 guests