C Board  

Go Back   C Board > Community Boards > Contests Board

Reply
 
LinkBack Thread Tools Display Modes
Old 01-10-2006, 12:28 PM   #1
Registered User
 
Join Date: Dec 2005
Posts: 25
New Contest (Possibly Too Easy for Experts)

Seeing that this section currently has no active threads, I thought I'd start one. If you have already seen the question before, please don't give out the answer immediately.

*****

Problem: Write a programme that prints out its own source file.
Reisswolf is offline   Reply With Quote
Old 01-10-2006, 01:34 PM   #2
aoeuhtns
 
Join Date: Jul 2005
Posts: 581
Mind if I do my entry in Perl?

Here it is:
Rashakil Fol is offline   Reply With Quote
Old 01-10-2006, 02:01 PM   #3
Cat without Hat
 
CornedBee's Avatar
 
Join Date: Apr 2003
Posts: 8,439
I can do it in two statements of active code
__________________
All the buzzt!
CornedBee

"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
CornedBee is offline   Reply With Quote
Old 01-10-2006, 11:18 PM   #4
Administrator
 
webmaster's Avatar
 
Join Date: Aug 2001
Posts: 699
Scheme: ()
webmaster is offline   Reply With Quote
Old 01-10-2006, 11:38 PM   #5
Just Lurking
 
Dave_Sinkula's Avatar
 
Join Date: Oct 2002
Posts: 4,990
The Quine Page: C
__________________
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*

Last edited by Dave_Sinkula; 01-10-2006 at 11:40 PM.
Dave_Sinkula is offline   Reply With Quote
Old 01-12-2006, 08:22 AM   #6
Registered User
 
Join Date: Dec 2005
Posts: 25
Ha ha ha! I should have stated the question as follows: "Write a non-trivial programme that prints out its source code."

*****

Anyway, the solution I have is:

Code:
#include <stdio.h>
#include <stdlib.h>

int main() {
  system("cat <insert_filename_here>");
  return 0;
}
I suppose you could say that I have cheated by using "cat" instead of writing my own "cat." But I'll live with that charge!

*****

By the way, is the Scheme function given above correct? I mean, the output of that empty list is nothing--right? The output is not a pair of matching parentheses with nothing in between, is it?
Reisswolf is offline   Reply With Quote
Old 01-12-2006, 08:43 AM   #7
Cat without Hat
 
CornedBee's Avatar
 
Join Date: Apr 2003
Posts: 8,439
Well, outputting an empty list would output a formatted empty list - which is an empty pair of parentheses.

Reisswolf, point one, how isn't that trivial? Point two, have you tried running that on Windows?
__________________
All the buzzt!
CornedBee

"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
CornedBee is offline   Reply With Quote
Old 01-12-2006, 11:35 AM   #8
Registered User
 
Join Date: Dec 2005
Posts: 25
CornedBee, I am perfectly aware that my programme is specifically for *NIX systems.

Well, I only meant trivial in the sense that it contained a non-zero number of lines of code. Conceptually, it is pretty trivial. (Hence my caveat that the problem might be too easy for experts.)
Reisswolf is offline   Reply With Quote
Old 01-13-2006, 10:56 AM   #9
Budding Synth Programmer
 
samGwilliam's Avatar
 
Join Date: Feb 2002
Location: Trefforest
Posts: 368
Quote:
Originally Posted by Reisswolf
CornedBee, I am perfectly aware that my programme is specifically for *NIX systems.

Well, I only meant trivial in the sense that it contained a non-zero number of lines of code. Conceptually, it is pretty trivial. (Hence my caveat that the problem might be too easy for experts.)
Do you mean to say that a program with no lines of code is the most complex of all?
__________________
MSVC++ 6.0
samGwilliam is offline   Reply With Quote
Old 01-21-2006, 04:19 AM   #10
aoeuhtns
 
Join Date: Jul 2005
Posts: 581
Quote:
Originally Posted by webmaster
Scheme: ()
That's not syntactically valid.
Rashakil Fol is offline   Reply With Quote
Old 01-29-2006, 01:45 AM   #11
Dump Truck Internet
 
valis's Avatar
 
Join Date: Jul 2005
Posts: 357
how is that not valid scheme (or even lisp), it looks valid to me, a nil list in lisp and nothing in scheme.
valis is offline   Reply With Quote
Old 01-29-2006, 11:40 AM   #12
aoeuhtns
 
Join Date: Jul 2005
Posts: 581
() may be accepted by some (or many) Scheme implementations, but it is not a valid Scheme expression at least as defined by R5RS.

Quote:
Note: In many dialects of Lisp, the empty combination, (), is a legitimate expression. In Scheme, combinations must have at least one subexpression, so () is not a syntactically valid expression.
http://www.schemers.org/Documents/St...ml#%_sec_4.1.3
Rashakil Fol is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
WANTED: Contest Master kermi3 A Brief History of Cprogramming.com 15 01-23-2003 10:15 PM
Text Compression Contest -- Sept. 28, 2002 ygfperson C Programming 3 10-01-2002 06:25 PM
Results for *easy* contest: ygfperson A Brief History of Cprogramming.com 15 07-27-2002 11:35 AM
Ann: New easy contest ygfperson A Brief History of Cprogramming.com 0 07-01-2002 04:00 PM


All times are GMT -6. The time now is 07:42 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22