Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 34

Thread: [Beginner] Programming Challenge: 6

  1. #21
    Join Date
    Jun 2006
    Location
    Harbin, China
    Beans
    123
    Distro
    Ubuntu Studio 10.10 Maverick Meerkat

    Re: [Beginner] Programming Challenge: 6

    Writing in Scheme or Lisp isn't a challenge... it's a bonus.

    Now, writing all those bits of code in brain****... that would be a programing challenge!
    Science is open source religion

  2. #22
    Join Date
    Apr 2007
    Beans
    14,781

    Re: [Beginner] Programming Challenge: 6

    Quote Originally Posted by maximinus_uk View Post
    Writing in Scheme or Lisp isn't a challenge... it's a bonus.

    Now, writing all those bits of code in brain****... that would be a programing challenge!
    Brain**** isn't hard. It is TDS, but not hard.

  3. #23
    Join Date
    Mar 2007
    Beans
    Hidden!
    Distro
    Kubuntu 7.04 Feisty Fawn

    Talking Re: [Beginner] Programming Challenge: 6

    OK then. I take it by the dearth of responses that everybody else finds Lisp as confusing as I do. However, since I've spent the whole weekend trying to figure it out, I will submit my first attempt now before Sunday ends (depending where you are). I've gotta say that I had fun with this and I plan to continue learning more scheme, though all the sources I've found say it's only good for learning. Learning is what I want to do.

    Feedback is desired, encouraged, requested and welcomed. Thanks for the challenge LaRoza, this is something I definitely wouldn't have thought of on my own.

    Using PLT Scheme:
    Code:
    #lang scheme
    
    (define (part1 n)
       (cond 
         ((not (= n 1)) (string-append (number->string n) " bottles of beer on the wall. "))
         (else "1 more bottle of beer on the wall. ")))
    
    (define (part4 n) (part1 (- n 1)))
      
    (define (part2 n)
      (cond 
          ((> n 9) (string-append (substring (part1 n) 0 18) "."))
          ((or (> n 1) (= 0 n)) (string-append (substring (part1 n) 0 17) "."))
          (else "1 more bottle of beer.")))
    
    (define (part3 n)
      (cond
        ((> n 1) "Take one down, pass it around, ")
        ((= n 1) "Take it down, pass it around, ")
        ((= n 0) "Go to the store, buy some more, ")))
      
    (define (sing n)
        (when (>= n 0)
          (printf "~a~a ~n ~a~a ~n~n"
                  (part1 n)
                  (part2 n)
                  (part3 n)
                  (part4 n))
          (sing (- n 1))))
    
    (sing 99)
    Edit: And I've already found an error.

    I'll have to fix the procedure (part4 n) so that it prints 99 instead of -1 in the last verse. I'm getting on it now.
    Last edited by SteelDragon; September 28th, 2008 at 11:21 PM.

  4. #24
    Join Date
    Jul 2008
    Beans
    1,706

    Re: [Beginner] Programming Challenge: 6

    question to help me with one of the challenges: in scheme does anyone remember the funtion that returns what type a paramter is...i thought it was like (? 1) would return integer...i read about this long ago but i cant find the tutorial now

  5. #25
    Join Date
    Apr 2007
    Location
    (X,Y,Z) = (0,0,0)
    Beans
    3,715

    Re: [Beginner] Programming Challenge: 6

    Quote Originally Posted by SteelDragon View Post
    (...) I've gotta say that I had fun with this and I plan to continue learning more scheme, though all the sources I've found say it's only good for learning. Learning is what I want to do.

    (...)
    Ah, you'll be surprised with what you can do with Scheme. Just play some more around.

    And congratulations, it's a nice Scheme code. And you clearly have looked at your implementation's features to find your way... That's good.

  6. #26
    Join Date
    Jul 2008
    Beans
    1,706

    Re: [Beginner] Programming Challenge: 6

    this language isnt in the rules but i think i want to post my answer for answer 1 in a non C/BASIC syntax anyway...

    PHP Code:

    this answer is written in HQ9+

  7. #27
    Join Date
    Sep 2006
    Location
    BC, Canada
    Beans
    347
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: [Beginner] Programming Challenge: 6

    **EDIT:

    Whoops! I misread the challenge! I thought you were to do the challenge in a language you didn't know LIKE the ones listed (as if they were examples) rather than you MUST use one of the listed languages. My bad!

    **END

    I am learning how to use Bash scripting. I am VERY much a newbie at it so forgive me! Here is my first attempt at a script that solves Beginner Programming Challenge #2 (which I would have normally solved in either C or C++). I plan on attempting to fix the code using something like sed to qualify if a user has entered a number for their name and a string for an age or uid. The user name causes no error but the uid and age will throw an un-handled exception.

    PHP Code:
    #!/bin/sh

    # A bash script which takes prompts for a user's name, age, and UID then
    # outputs the result in a meaningful manner after qualifying the supplied
    # data.

    menu_choice=""
    username=""
    userage=0
    userid
    =0

    get_return
    () {
        
    printf "Press return"
        
    read x
        
    return 0
    }

    get_confirm() {
        
    printf "Are you sure? (y/n)"
        
    while true
        
    do
            
    read x
            
    case "$xin
                y 
    yes Yes YES )
                    return 
    0;;
                
    no No NO )
                    echo
                    echo 
    "Cancelled"
                    
    return 1;;
                *) echo 
    "Sorry, choice not recognized";;
            
    esac
        done
    }

    show_menu() {
        echo
        echo
        echo 
    "Options :-"
        
    echo
        echo 
    "    e) Enter Data"
        
    echo "    q) Quit"
        
    echo
        
    printf "Please enter choice then press return: "
        
    read menu_choice
        
        
    return
    }

    get_username() {
        
    printf "Please enter your name: "
        
    read username
        
        
    if [ "$username"" ]; then
            
    echo "You didn't enter a name!"
            
    get_username
        fi
        
        
    return
    }

    get_userage() {
        
    printf "Please enter your age: "
        
    read userage
        
        
    if [ "$userage-lt 1 ]; then
            userage
    =1
        fi
        
    if [ "$userage-gt 100 ]; then
            userage
    =100
        fi
        
        
    return
    }

    get_userid() {
        
    printf "Please enter you user ID (1-999999)"
        
    read userid
        
        
    if [ "$userid-lt 1 ]; then
            userid
    =
        fi
        
    if [ "$userid-gt 999999 ]; then
            userid
    =999999 
        fi
        
        
    return
    }

    enter_data() {
        
    clear
        get_username
        get_userage
        get_userid
        
        
    if get_confirm then
            
    echo
            echo
            echo 
    "You are $username, aged $userage."
            
    echo "Next year you will be $(($userage + 1)), with user id $userid. "
            
    echo "The next user is $(($userid + 1))."
            
    echo
            
    get_return
        
    else
            
    sleep 1
        fi
    }

    # application proper (main())

    quit=n
    while [ "$quit!= "y" ];
    do    
        
    clear
        
    echo "Ubuntu Challenge 6 Script v0.1!"
        
    echo
        echo
        echo 
    "Enter your user name, age and ID for some Ubuntu challenge fun!"
        
    show_menu
        
    case "$menu_choicein
            e 
    enter_data;;
            
    quit="y";;
            *) echo 
    "Sorry, choice not recognized";;
        
    esac
    done

    echo "Finished!"

    exit 
    Last edited by JupiterV2; October 2nd, 2008 at 06:56 AM.

  8. #28
    Join Date
    Apr 2007
    Location
    (X,Y,Z) = (0,0,0)
    Beans
    3,715

    Re: [Beginner] Programming Challenge: 6

    Quote Originally Posted by jimi_hendrix View Post
    this language isnt in the rules but i think i want to post my answer for answer 1 in a non c/basic syntax anyway...

    PHP Code:

    this answer is written in hq9+
    lol!

  9. #29
    Join Date
    Sep 2007
    Beans
    Hidden!

    Re: [Beginner] Programming Challenge: 6

    Quote Originally Posted by jimi_hendrix View Post
    this language isnt in the rules but i think i want to post my answer for answer 1 in a non C/BASIC syntax anyway...

    PHP Code:

    this answer is written in HQ9+
    mm..it would be better to write a code,than to copy one ^^
    http://99-bottles-of-beer.net/language-hq9+-1334.html

  10. #30
    Join Date
    Jul 2008
    Beans
    1,706

    Re: [Beginner] Programming Challenge: 6

    Quote Originally Posted by Kadrus View Post
    mm..it would be better to write a code,than to copy one ^^
    http://99-bottles-of-beer.net/language-hq9+-1334.html
    i could add a few +'s in there...

    PHP Code:
    ++++++++++++++++++++++++++9++++++++++++++++++++++++++++++++ 
    now its my own code

Page 3 of 4 FirstFirst 1234 LastLast

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
  •