The Programming Challenge Master Thread - Page 3 - Overclock.net - An Overclocking Community
Forum Jump: 

The Programming Challenge Master Thread

Reply
 
Thread Tools
post #21 of 263 (permalink) Old 11-22-2011, 07:19 PM
New to Overclock.net
 
Join Date: May 2006
Location: The boonies of Ontario
Posts: 3,532
Rep: 354 (Unique: 289)
Quote:
Originally Posted by Chris++ View Post

Python here, went for simple to understand rather than fancy code, but it gets the job done.
Code:
NUMBER_OF_STARS = 5
i = 1
while i <= NUMBER_OF_STARS:
    print ('*' * i)
    i = i + 1
while i > 0:
    print ('*' * i)
    i = i - 1




Hmm weird, you don't have to declare variable types in python like int, char etc?


Dman is offline  
Sponsored Links
Advertisement
 
post #22 of 263 (permalink) Old 11-22-2011, 07:23 PM
Linux Lobbyist
 
Join Date: May 2011
Location: Chicago suburbs
Posts: 152
Rep: 6 (Unique: 6)
Just saw this thread and I'm currently in an intro to C++ and java class and would love to participate!

Mullinz is offline  
post #23 of 263 (permalink) Old 11-22-2011, 07:51 PM
New to Overclock.net
 
surfbumb's Avatar
 
Join Date: Jul 2007
Location: San Diego
Posts: 1,231
Rep: 97 (Unique: 79)
Quote:
Originally Posted by Dman View Post

Hmm weird, you don't have to declare variable types in python like int, char etc?

i havent' used python but I think it uses implicit variable declaration.

surfbumb is offline  
Sponsored Links
Advertisement
 
post #24 of 263 (permalink) Old 11-22-2011, 07:54 PM
New to Overclock.net
 
surfbumb's Avatar
 
Join Date: Jul 2007
Location: San Diego
Posts: 1,231
Rep: 97 (Unique: 79)
heres my code...it works! lol
Code:
void stars(int max){
         for(int x = 0; x <= max ; ++x){
                for(int j = 0; j < x; ++j)
                       cout << '*';
                 cout << endl;
          }
          for(int x = max - 1; x > 0; --x){
                   for(int j = 0; j < x; ++j)
                           cout << '*';
                   cout << endl;
          }
}


here it is working with a max of 40 stars

338

surfbumb is offline  
post #25 of 263 (permalink) Old 11-22-2011, 11:50 PM
New to Overclock.net
 
Chris++'s Avatar
 
Join Date: Dec 2008
Posts: 511
Rep: 19 (Unique: 19)
Quote:
Originally Posted by Dman View Post

Hmm weird, you don't have to declare variable types in python like int, char etc?

Nope, Python's interpreter takes care of it based on the content and/or use of the variable, but make no mistake, they do in fact have a variable type.

Chris++ is offline  
post #26 of 263 (permalink) Old 11-23-2011, 05:48 AM
Rust Buckets for Days
 
axipher's Avatar
 
Join Date: Oct 2011
Location: Canada
Posts: 13,088
Quote:
Originally Posted by Chris++ View Post

Nope, Python's interpreter takes care of it based on the content and/or use of the variable, but make no mistake, they do in fact have a variable type.

BASIC is the same way, lots of dialects don't require you to declare variable types.



Spoiler!


axipher is offline  
post #27 of 263 (permalink) Old 11-23-2011, 07:16 AM
New to Overclock.net
 
Plan9's Avatar
 
Join Date: Nov 2011
Location: Planet Vegeta
Posts: 8,040
Rep: 574 (Unique: 277)
Perl (just because I haven't seen a Perl entry yet):
Code:
#!/usr/bin/perl

if (!$ARGV[0] =~ m/[0-9]+/) { die "Parameter must be an integer\n" }

my ($direction, $i) = qw(1 1);
do {
    for ($i; ($i <= $ARGV[0] && $direction == 1) || ($i > 0 && $direction == -1); $i += $direction) {
        printf "%s\n", "*"x$i;
    }
    $direction *= -1;
} while ($direction != 1)

edit: oops, outputted hashes rather than asterisks.

edit2: CLI version for instant gratification:
Code:
perl -e 'my ($d, $i) = qw(1 1); do {for ($i; ($i<=$ARGV[0] && $d==1) || ($i>0 && $d==-1); $i+=$d) {printf "%s\n", "*"x$i} $d*=-1} while ($d!=1)' 5
Plan9 is offline  
post #28 of 263 (permalink) Old 11-23-2011, 09:51 AM - Thread Starter
Retired Staff
 
{Unregistered}'s Avatar
 
Join Date: Jun 2010
Posts: 1,563
Rep: 17 (Unique: 15)
Hmmm... Nice work guys! thumb.gif

I've checked most of your codes and they look fine by me. (I'll be going over them again now.)

I personally did the task twice, once in Java (it looked sort of like Aximous's code) and once in Python (it looked sort of like Chris++'s code : only uselessly longer since I couldn't concentrate due to lack of sleep tongue.gif).
Python Code: (Click to show)
Code:
n = int(raw_input("Enter the max number of stars: "))
count = 0
inversecount = (2*n)

while (count+1 <= n):
    print "*" * (count + 1)
    count = count + 1

while (inversecount-1 > n):
    print "*" * (inversecount-n-1)
    inversecount = inversecount - 1

But I have just one question to ask you people: What sort of format should we have as to what happens after the results? Should we have some point-based system with a record of how people performed or should we just use these challenges as exercises to sharpen our programming skills?

I do believe that those who are enthusiastic about programming will try these exercises and want to improve but do you guys think we should continue like this or bring something new in?

Thanks for the wonderful participation.


Quote:
Originally Posted by andrews2547 go_quote.gif

Women suck at almost everything. The only time they were good at anything was when Cliopatra was in charge and they lived in triangles. Triangles aren't manly.


{Unregistered} is offline  
post #29 of 263 (permalink) Old 11-23-2011, 10:30 AM
New to Overclock.net
 
Join Date: Jan 2011
Location: Quebec, Canada
Posts: 436
Rep: 26 (Unique: 26)
You could make a simple spreadsheet with the name of those who are participating and the number of challenge the manage to make.

I do the challenge because it's a good way to practice. And it's fun to see what the other have done too.
spikexp is offline  
post #30 of 263 (permalink) Old 11-23-2011, 10:35 AM - Thread Starter
Retired Staff
 
{Unregistered}'s Avatar
 
Join Date: Jun 2010
Posts: 1,563
Rep: 17 (Unique: 15)
Quote:
Originally Posted by spikexp View Post

You could make a simple spreadsheet with the name of those who are participating and the number of challenge the manage to make.
I do the challenge because it's a good way to practice. And it's fun to see what the other have done too.

Good suggestion. I was thinking of doing that but wasn't sure if anyone else would want that.

I'll make the spreadsheet soon.


Quote:
Originally Posted by andrews2547 go_quote.gif

Women suck at almost everything. The only time they were good at anything was when Cliopatra was in charge and they lived in triangles. Triangles aren't manly.


{Unregistered} is offline  
Reply

Quick Reply
Message:
Options

Register Now

In order to be able to post messages on the Overclock.net - An Overclocking Community forums, you must first register.
Please enter your desired user name, your email address and other required details in the form below.
User Name:
If you do not want to register, fill this field only and the name will be used as user name for your post.
Password
Please enter a password for your user account. Note that passwords are case-sensitive.
Password:
Confirm Password:
Email Address
Please enter a valid email address for yourself.
Email Address:

Log-in



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page


Forum Jump: 

Posting Rules  
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off