View Poll Results: Who was the best beginner?

Voters
41. You may not vote on this poll
Page 27 of 27 FirstFirst ... 17252627
Results 261 to 268 of 268

Thread: [Beginner] Programming Challenge: 1

  1. #261
    Join Date
    Dec 2007
    Location
    Aberystwyth, Wales
    Beans
    Hidden!
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: [Beginner] Programming Challenge: 1

    PHP Code:
    #include <stdio.h>

    int main()
    {
          
    int bi;

       
    99;
       
    98;

     for(
    b=99;b>1;b--)
     {
       
    printf("%d bottles of beer on the wall %d bottles of beer.\nTake one down and pass it around, %d bottles of beer on the wall.\n\n",b,b,i--);
     }
     return(
    0);

    Here's my C code... not really that good but it does the job and it weighs in at about 256 bytes.

  2. #262
    Join Date
    Aug 2008
    Beans
    Hidden!

    Re: [Beginner] Programming Challenge: 1

    Quote Originally Posted by CLomax View Post
    it does the job
    Have you looked at the last two "verses" your program has to produce, i.e. at #bottles=1 and #bottles=0?

  3. #263
    Join Date
    Dec 2007
    Location
    Aberystwyth, Wales
    Beans
    Hidden!
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: [Beginner] Programming Challenge: 1

    Quote Originally Posted by pp. View Post
    Have you looked at the last two "verses" your program has to produce, i.e. at #bottles=1 and #bottles=0?
    Woops
    And I thought I manage to reduce it further than others did. I'll look into that. Thanks.

  4. #264
    Join Date
    Oct 2008
    Location
    $HOME
    Beans
    112
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: [Beginner] Programming Challenge: 1

    PHP Code:
    #!/usr/bin/python
    beer=99
    #normal stuff, 99 to 3
    while beer 2
        print 
    "%i bottles of beer on the wall, %i bottles of beer, take one down, pass it around, %i bottles of beer on the wall\n" % (beer,beer,beer-1)
        
    beer=beer-1
    #Ending with correct grammar
    print "2 bottles of beer on the wall, 2 bottles of beer.\nTake one down and pass it around, 1 bottle of beer on the wall.\n" 
    print "1 bottle of beer on the wall, 1 bottle of beer.\nTake one down and pass it around, no more bottles of beer on the wall.\n"
    print "No more bottles of beer on the wall, no more bottles of beer.  Go to the store and buy some more, 99 bottles of beer on the wall." 
    I am a python noobie. Edited beforehand for correct grammar on 1 and 2
    $(fortune)
    In a world without walls and fences, who needs windows and gates?

  5. #265
    Join Date
    Jul 2008
    Beans
    565

    Re: [Beginner] Programming Challenge: 1

    Here's my python one liner:

    Code:
    python -c 'bo,be,ta,wa,no="bottle","of beer","Take one down and pass it around","on the wall",range(99,0,-1); print "".join([ "%s %s%s %s %s,\n%s %s%s %s.\n%s, %s %s%s %s %s.\n\n" % (num,bo,["s",""][num==1],be,wa,num,bo,["s",""][num==1],be,ta,[num-1,"no more"][num-1==0],bo,["s",""][num-1==1],be,wa) for num in no ] + ["No more %ss %s %s, no more %ss %s.  Go to the store and buy some more, 99 %ss %s %s." % (bo,be,wa,bo,be,bo,be,wa)] )'
    Edit: Also, a version for bash:
    Code:
    bo="bottle";be="of beer";ta="Take one down and pass it around";wa="on the wall";i=99;while [ "$i" != 0 ]; do printf "$i $bo`[ $i != 1 ] && echo s` $be $wa,\n$i $bo`[ $i != 1 ] && echo s` $be.\n$ta, `[ $((i-1)) != 0 ] && echo $((i-1)) || echo "no more"` $bo`[ $i != 2 ] && echo s` $be.\n\n"  ;i=$((i-1));done;  printf "No more ${bo}s $be $wa,\nno more ${bo}s $be.\nGo to the store and buy some more, 99 ${bo}s $be $wa.\n"
    Last edited by eightmillion; January 25th, 2009 at 06:17 AM.
    Code:
    ruby -ne '$_.gsub(/<[^>]*>|\([^)]*\)|\[[^\]]*\]/,"").each_char{|i|STDOUT.flush.print(i);sleep(0.03)}if/(<\/li>|<ul>)<li>/' <(wget -qO- is.gd/e3EGx)

  6. #266
    Join Date
    Mar 2008
    Location
    Germany
    Beans
    171
    Distro
    Xubuntu 12.10 Quantal Quetzal

    Re: [Beginner] Programming Challenge: 1

    Java:
    Code:
    public class NinetyNineBottles {
    
    	private static void bottlesCounter(int bottles) {
    		for (; bottles > 0; bottles--) {
    			if (bottles == 1) {
    				System.out.println(bottles + " bottle of beer on the wall, " + bottles + " bottle of beer.");
    				System.out.println("Take one down and pass it around, no more bottles of beer on the wall.");
    			} else {
    				System.out.println(bottles + " bottles of beer on the wall, " + bottles + " bottles of beer.");
    				System.out.println("Take one down and pass it around, " + (bottles - 1) + " bottles of beer on the wall.");
    			}
    		}
    	}
    	
    	public static void main(String[] args) {
    		bottlesCounter(99);
    	}
    }

  7. #267
    Join Date
    Jun 2009
    Location
    Stavanger, Norway
    Beans
    6

    Re: [Beginner] Programming Challenge: 1

    Hello Everyone!

    This is my contribution in C++ of this challenge. I would just have some feedback from you.

    PHP Code:
    /* Version 1 of 99 bottles of beer
    Author: Benjamin Nordtorp
    Language: C++
    Date: 2009-06-01
    */
    #include <iostream>
    using namespace std

    void plural(int bottles)
    {
        if (
    bottles != 1cout << "s";
    }

    int main ()
    {
        
    int bottles 99;
        while (
    bottles 0)
        {
            
    cout << bottles << " bottle";
            
    plural(bottles);

            
    cout << " of beer on the wall, " << bottles << " bottle";
            
    plural (bottles);

            
    cout << " of beer.\n";

            
    cout << "Take one down and pass it around, " << --bottles << " bottle";
            
    plural (bottles);
            
            
    cout << " of beer on the wall.\n\n";
        }

        
    cout << "Go to the store and buy some more,\n"
             
    << "99 bottles of beer on the wall." << endl;

        
    // A pause, before exiting
        
    cin.get();
        return 
    0;


  8. #268
    Join Date
    May 2013
    Beans
    3

    Re: Beginners Team Programming Challenges Index

    Here is my answer in the first problem. any comments? I used C.

    #include<stdio.h>

    int qty;

    main(){
    for(qty=99;qty!=1;qty--){
    printf("%d bottles of beer on the wall, %d bottles of beer.\n", qty,qty);
    printf("Take one down and pass it around, %d bottles of beer on the wall.\n", qty-1);
    }
    if(qty=1){
    printf("%d bottle of beer on the wall, %d bottle of beer.\n", qty, qty);
    printf("Take one down and pass it around, no more bottles of beer on the wall.\n");

    printf("No more bottles of beer on the wall, no more bottles of beer. \nGo to the store and buy some more, 99 bottles of beer on the wall.\n");

    }
    }

Page 27 of 27 FirstFirst ... 17252627

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •