Jump to content


Photo

Challenge TRICKY001


  • Please log in to reply
7 replies to this topic

#1 rainwater_stillicide

rainwater_stillicide

    SUP3R 31337 P1MP

  • Agents of the Revolution
  • 282 posts
  • Location:Scotland

Posted 09 March 2010 - 01:45 PM

In the language of your choice: write a program which will output it's own source code.

#2 lintwurm

lintwurm

    I broke 10 posts and all I got was this lousy title!

  • Members
  • 15 posts
  • Country:
  • Gender:Male
  • Location:Pretoria

Posted 09 March 2010 - 02:37 PM

This is my c++ way of doing it...
Spoiler


Not sure if this is the best way, but it works ^_^

#3 rainwater_stillicide

rainwater_stillicide

    SUP3R 31337 P1MP

  • Agents of the Revolution
  • 282 posts
  • Location:Scotland

Posted 09 March 2010 - 04:03 PM

Nice. Ambitious hacker solution.

Can anyone write a version that doesn't need to read from it's own source file?

#4 JBu92

JBu92

    HACK THE PLANET!

  • Members
  • 58 posts
  • Country:
  • Gender:Male

Posted 09 March 2010 - 07:07 PM

in python:
Spoiler

it outputs to file, but you could output to shell instead, if you wanted

#5 FLW_FTW

FLW_FTW

    HACK THE PLANET!

  • Members
  • 59 posts
  • Country:
  • Gender:Male
  • Location:San Francisco

Posted 10 March 2010 - 01:18 AM

In the language of your choice: write a program which will output it's own source code.


Question: Does the outputted source code have to be able to then be compiled and repeat the objective? I can get the printing of the sourcecode to work, but I lose all formatting.

See my answer:
Spoiler

Edited by FLW_FTW, 10 March 2010 - 01:20 AM.


#6 rainwater_stillicide

rainwater_stillicide

    SUP3R 31337 P1MP

  • Agents of the Revolution
  • 282 posts
  • Location:Scotland

Posted 10 March 2010 - 07:38 AM


In the language of your choice: write a program which will output it's own source code.


Question: Does the outputted source code have to be able to then be compiled and repeat the objective? I can get the printing of the sourcecode to work, but I lose all formatting.

See my answer:
Spoiler


This is a good attempt and is along the right lines. Ideally the output would be identical to the source file (there's nothing stopping you smooshing the original source file onto one line if you like).
The problem with this solution isn't the formatting though (C ignores whitespace generally so even if a program is all on one line it'll still compile). it's that inside the strings the '\'s you use to escape \"%s\" aren't repeated and that you some quotation marks are lost etc...

Keep working at it, it's close to a full solution.

#7 z3ros3c

z3ros3c

    Will I break 10 posts?

  • Members
  • 4 posts
  • Gender:Male

Posted 18 May 2010 - 01:14 AM

In Python:

(saved as 'file.py')
#!/usr/bin/env python
print(open('file.py','r').read())

OR if you want to do it the PROPER way:

x='x=%s;x%%`x`';x%`x`


#8 heisenbug

heisenbug

    Gibson Hacker

  • Members
  • 79 posts
  • Country:
  • Gender:Male

Posted 06 February 2011 - 02:54 AM

In Perl:
Spoiler





BinRev is hosted by the great people at Lunarpages!