Xmas competitions

This is a discussion on Xmas competitions within the Contests Board forums, part of the Community Boards category; You're aware it's the second you should obfuscate, right...

  1. #46
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    You're aware it's the second you should obfuscate, right
    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

  2. #47
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,824
    Competition 1 is now closed - 8 entries received
    Code:
    CornedBee_xmastree.cpp
    curlious_tree.cpp
    DaveSinkula_xmastree.c
    DavT_xmastree.c
    glUser3f_xmastree.cpp
    Magos_ChristmasTree.cpp
    Prelude_xmastree.c
    TheDog_xmastree.c
    Now to start looking at them....
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #48
    Registered User glUser3f's Avatar
    Join Date
    Aug 2003
    Posts
    345
    Originally posted by CornedBee
    You're aware it's the second you should obfuscate, right
    Originally posted by Salem
    The judging will be based on the most elegant solution (whatever that means)
    But presentation, comments, layout, etc will score big
    I explained how the program works in detail

  4. #49
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    We'll soon see how Salem sees this.
    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

  5. #50
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Question about #3:
    If I want to calculate the volume of all presents, can I do that outside the timing of the function? Or is that part of the packing too?
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  6. #51
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,824
    I had considered that the only thing I am interested in timing is the packing.

    If you want to calculate and pass volume information as a parameter to your packing function, then that is up to you.

    > can I do that outside the timing of the function?
    Yes
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #52
    Registered User
    Join Date
    Oct 2003
    Posts
    16
    Originally posted by Salem
    Competition 1 is now closed - 8 entries received
    Bummer! I discovered the contest too late... anyway, here's what I would have sent (i hope you don't mind me posting it here, feel free to delete this post if it's so):

    Code:
    //XmasTree: Prints out a wonderful Christmas tree to screen
    #include <iostream>
    
    using namespace std;
    
    //Declaration of function drawXmasTree
    //Function draws a given level of the tree and then calls itself to 
    //draw the next one (a tree is comprised of levels, which in turn 
    //are comprised of lines)
    void drawXmasTree(int order, int charactersToMiddle, int level = 0);
    
    
    int main()
    {
    	//Ask for input from the user
    	int order;
    	cout << "Order: ";
    	cin >> order;
    
    	cout << endl;
    
    	//This calculates the total amount of characters needed in a line
    	//up to the middle of the tree
    	int i;
    	int charactersToMiddle = 0;
    	for (i = 1; i <= order; i++)
    		charactersToMiddle += i;
    	charactersToMiddle++;
    
    	//Call function drawXmasTree, using default parameter level = 0
    	drawXmasTree(order, charactersToMiddle);
    
    	cout << endl;
    
    	return 0;
    }
    
    
    //Definition of drawXmasTree
    void drawXmasTree(int order, int charactersToMiddle, int level)
    {
    	int i, j;
    
    	//Variable "spaces" holds the amount of blank spaces needed at
    	//the beginning of a line (disregarding asterisks)
    	int spaces = 0;
    
    	//Initialization of "spaces" with the amount of blank spaces
    	//needed at the beginning of the first line in level
    	for (i = order; i >= level; i--)
    		spaces += i;
    
    	//This loop draws each line from the given level
    	for (i = 1; i <= (level + 1); i++)
    	{
    		//First some blank spaces...
    		for (j = 1; j <= spaces; j++) cout << " ";
    
    		//...then check to see if an asterisk needs to be drawn...
    		//(in which case we go back one space and print it)
    		if ( (level != 0) && (i == 1) ) cout << "\b*";
    
    		//...then one side of the tree
    		cout << "/";
    
    		//...and the spaces in the middle...
    		for (j = 1; j <= ( 2 * (charactersToMiddle - (spaces + 1)) ); j++) cout << " ";
    
    		//...the other side of the tree...
    		cout << "\\";
    
    		//...and a final check to see if an asterisk is due
    		if ( (level != 0) && (i == 1) ) cout << "*";
    
    		//We finish with a return carriage...
    		cout << endl;
    
    		//...and the amount of blank spaces needed for the beginning of a new line
    		spaces--;
    	}
    
    	//Level has been drawn, now variable "level" must be increased for
    	//the next one
    	level++;
    
    	//Leave the function if the last level, according to variable 
    	//"order", has been drawn
    	if (level == (order + 1)) return; 
    
    	//Function calls itself for next level
    	drawXmasTree(order, charactersToMiddle, level);
    }
    Are you planning on posting all of the entries, or just the winner? I think it would be very instructive watching what the others did...

    Peace!

  8. #53
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Yeah, I hope to see all entries. Though they're probably all very similar.

    After submitting I realized that the app would have been better using pure C and printf with %*c...
    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

  9. #54
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >After submitting I realized that the app would have been better using pure C and printf with %*c...
    I'm assuming you're talking about something like this:
    Code:
    printf ( "%*c%s%*c%s\n", external_spaces, ' ', ornament ? "*/" : "/", internal_spaces, ' ', ornament ? "\*" : "\" );
    In which case it wouldn't work. You would fail to meet the requirements because even if one of the *_spaces variables is 0, a single space will still be printed. I considered this briefly, but in the end opted to use simple loops instead because of the greater control. Of course, if you went with C++, the setw stream modifier can be used with an empty string literal (""), and the correct number of spaces is printed.
    My best code is written with the delete key.

  10. #55
    Registered User glUser3f's Avatar
    Join Date
    Aug 2003
    Posts
    345
    even if the entries weren't posted, we can share them together, right?
    As for the first problem, I just used loops and cout << , no fancy IO stuff.

  11. #56
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Prelude: actually I'm talking about writing the tree parts directly with the length specification.
    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

  12. #57
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Prelude: actually I'm talking about writing the tree parts directly with the length specification.
    So am I. Could you elaborate more as to what you mean?
    My best code is written with the delete key.

  13. #58
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Code:
    printf ( "%*s%*s\n", external_spaces+(ornament?2:1), ornament ? "*/" : "/", internal_spaces+(ornament?2:1),  ornament ? "\*" : "\" );
    Something like this.
    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

  14. #59
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Ah, I see.
    My best code is written with the delete key.

  15. #60
    Registered User heat511's Avatar
    Join Date
    Dec 2001
    Posts
    169

    my "entry"

    well you can't say this isn't obfuscatated...

    [code]
    //Contest Entry #2
    //Drew Heaton
    #include<iostream.h>
    main(){cout << "THE 12 DAYS OF CHRISTMAS" << endl << "A Babelfish translation" << endl << endl;cout << "day? : ? 2 days Thursday the perdiz: ? 3 days Thursday the perdiz 2: 3? ? 4 days Thursday the perdiz 2: 3? 5 days Thursday the perdiz 2? 4: 3? 6 days Thursday the perdiz 2? 5 Kim 4: 3? 7 days Thursday the perdiz 2? 5 Kim 4 6 gansos: 7 white Wednesday 3? 8 days Thursday the perdiz 2? 5 Kim 4 6 gansos: 8 person people 7 white Wednesday 3? 9 days Thursday the perdiz 2? 5 Kim 4 6 gansos: 9 person characteristics the Bailar 8 person person 7 white Wednesday 3? 10 days Thursday the perdiz 2? 5 Kim 4 6 gansos: 10 people 9 person characteristics 8 person people 7 white Wednesday 3? 11 days Thursday the perdiz 2? 5 Kim 4 6 gansos: The Instalar the Pipers 11 10 people 9 person characteristics 8 person people 7 white Wednesday 3? day Thursday the perdiz 2? 5 Kim 4 6 gansos: 12 Redoblantes Teclear Pipers 11 10 people 9 person characteristics 8 person people 7 white Wednesday 3? Thursday the perdiz 2 5 Kim 4 6 gansos $$ln" << endl << endl; return 0;}
    [\code]
    "uh uh uh, you didn't say the magic word"
    -Jurassic Park

Page 4 of 6 FirstFirst 123456 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The Xmas Tree competition results
    By Salem in forum Contests Board
    Replies: 10
    Last Post: 12-30-2003, 05:26 AM
  2. Xmas
    By Stoned_Coder in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 12-25-2002, 04:58 AM
  3. Competitions
    By Shakespeare in forum C++ Programming
    Replies: 2
    Last Post: 03-11-2002, 05:00 AM

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