Thread: New Contest (Possibly Too Easy for Experts)

  1. #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.

  2. #2
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    Mind if I do my entry in Perl?

    Here it is:

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    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

  4. #4
    Administrator webmaster's Avatar
    Join Date
    Aug 2001
    Posts
    1,012
    Scheme: ()

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Last edited by Dave_Sinkula; 01-10-2006 at 11:40 PM.
    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.*

  6. #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?

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    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

  8. #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.)

  9. #9
    Registered User samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Newport
    Posts
    382
    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?
    Current Setup: Win 10 with Code::Blocks 17.12 (GNU GCC)

  10. #10
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    Quote Originally Posted by webmaster
    Scheme: ()
    That's not syntactically valid.

  11. #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.

  12. #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.

    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

Popular pages Recent additions subscribe to a feed

Similar Threads

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