Programming Challenges - Page 6


Page 6 of 19 FirstFirst ... 234567891016 ... LastLast
Results 76 to 90 of 279

Thread: Programming Challenges

  1. #76
    Join Date
    Mar 2003
    Location
    Tampa, FL USA
    Posts
    2,193

    Re: Programming challenge

    Originally posted by kshim5
    Write a short program that asks for your height in integer inches and then convert your height to feet and inches.
    Attached Files Attached Files

  2. #77
    Join Date
    May 2001
    Location
    Uh, I'm somewhere where I don't know where I am.
    Posts
    1,228
    Originally posted by Strike
    tecknophreak: you underconstrained it

    mrBen, that works, here's a properly indented version:

    Code:
    >>> x = 0; y = 0
    >>> while y < 10000:
    ...     y = 0
    ...     for loop in range(x):
    ...             y += x
    ...     print y
    ...     x +=1
    ...
    Sure did.

    how's the "for loop in range(x)" work? and how do you know a loop(while/for) is done? cause in C/C++, etc, you have the { } to tell ya.

    P.S. you can do lose two lines from your code.
    if (i_forgot && this_is_about_code)
    language = c++;

  3. #78
    Join Date
    Apr 2003
    Location
    UK
    Posts
    305
    Originally posted by tecknophreak
    Sure did.

    how's the "for loop in range(x)" work? and how do you know a loop(while/for) is done? cause in C/C++, etc, you have the { } to tell ya.

    P.S. you can do lose two lines from your code.
    You only have to place the code inside the loop in a block if there is more than one statment.

    If there is no block around the code then only the first statment applies.

    C/C++ you only need the block (braces) if there is more than one statment.
    Although I use a block (braces) even if there is only one statment as I think it keeps the code more consistent and readable.
    Last edited by ricstr; 09-24-2003 at 01:56 PM.

  4. #79
    Join Date
    May 2001
    Location
    Uh, I'm somewhere where I don't know where I am.
    Posts
    1,228
    Originally posted by Sepero
    teckno, do you program in anything besides C/C++? I don't know what language that guy wrote that in, but I can read/understand it perfectly... Then again, maybe that's what makes me an outcast.
    want a cookie?

    i should have just ran the program, i see you need indents to run the program.
    if (i_forgot && this_is_about_code)
    language = c++;

  5. #80
    Join Date
    Apr 2001
    Location
    SF Bay Area, CA
    Posts
    14,936
    Strike: you don't even need the range(int(math.sqrt(10000))). The square root of 10000 is 100, so you can just use range(100).

    (Of course, this doesn't negate the fact that x**2 is "multiplication". However, the way that multiplication is done on the CPU does negate this fact -- multiplication is done on the CPU by a series of additions, IIRC from Architecture. So hah; any solution is valid. )

    Sepero: the language would be Python.

  6. #81
    Join Date
    Jan 2001
    Location
    Somewhere in middle America
    Posts
    164
    Multiplication by 2 is most often optimized into var << 1.

    The lucky thing with binary multiplicaiton is EVERYTHING is a multiple of 2, so shifts are all you need. After all the shifts you still need to add the individual products just as we do with decimal math.

    I found this animated picture that illustrates multiplication very well.


  7. #82
    Join Date
    Dec 2000
    Location
    Glasgow, Scotland
    Posts
    4,361
    Originally posted by tecknophreak
    Sure did.

    how's the "for loop in range(x)" work? and how do you know a loop(while/for) is done? cause in C/C++, etc, you have the { } to tell ya.

    P.S. you can do lose two lines from your code.
    In python range(x) gives you a list from 0 to x.

    In Python, your loop / condition ends at the next unindented line. Thus you always have pretty looking code
    mrBen "Carpe Aptenodytes"

    Linux User #216794

    My blog page

    3rd year running - get yourself to LugRadio Live 7th-8th July 2007, Wolverhampton, UK. The premier FLOSS community event.

  8. #83
    Join Date
    Oct 2002
    Posts
    81
    Originally posted by Trogdor
    I'm doing a project for my compy sci class. I'll have three years to work on it. I am going to do it in PHP (so I can make it on my linux box and run it on my teacher's winblows 98 . . . also for the MySQL integration), and I need a good idea for my project. There are seven requirements, that I must show mastery in my program. Almost all of them I could do in my sleep, but I need a good idea.
    1. Arrays || Records || Objects
    2. Selection Constructs (branching)
    3. Iteration Constructs (looping)
    4. subprograms (built-in && user defined)
    5. parameter passing (hah!)
    6. Sorting || Searching Techniques
    7. File Access

    It looks like a job for MySQL. But what should I make? Any ideas?

    Thanks,
    TROGDOR!!!
    I thought of something today that I'm not sure has ever been done. What about a website where people can go and store a list of favorites....like the favorites folder, but accessible anywhere. Users would log into their account to access and edit their list. You would have to allow new accounts to be created, possibly setup cookies so that the user can auto-login to the site from thier own computer...they could set it as their homepage. My friend was trying to get to a megatokyo comic today at school, but there were so many, he couldn't find the one he was looking for, but he had it bookmarked at home and a site like this would have fixed that problem. Maybe you could set it up so that you could just import the list of favorites from your browser, thereby avoiding having to type in all the URLs. I think a site of this sort could be very popular because almost everyone has wanted to go to a site on another computer that they had bookmarked on their own computer, but can't remember the URL.

  9. #84
    Join Date
    Sep 2003
    Location
    Edmonton, Alberta, Canada
    Posts
    311
    HeyMr.HockeyJockyBob,

    Great idea! I'll think about it. Actually . . . it isn't bad! I could use that.

    TROGDOR
    the BURNiNATOR !!!

    EDIT: Looking for a good name for it.
    Last edited by Trogdor; 09-25-2003 at 05:40 PM.
    MOUNT TAPE U1439 ON B3, NO RING

    Registered Linux user # 31337!

  10. #85
    Join Date
    Jan 2001
    Location
    Somewhere in middle America
    Posts
    164
    I don't recall what it was called, but Netscape offered something very simular to that several years ago. I'm not sure if they still do.
    There was a setting in the Netscape options that allowed you to store your settings and favorites on a network, so a user's multiple computers could share the same set of favorites.

    It's still a good idea... Go ahead and burninate the countryside.

  11. #86
    Join Date
    Mar 2003
    Location
    Tampa, FL USA
    Posts
    2,193
    Originally posted by Hey15Bob
    I thought of something today that I'm not sure has ever been done. What about a website where people can go and store a list of favorites....
    Search google for "online bookmarks".
    http://www.backflip.com/
    http://www.mybookmarks.com/
    http://murl.com/
    http://webfavorites.com/

    I used to use a site like this a couple years ago. I quit using it though. It's only really useful if you connect using public computers or have a lot of your own computers.

  12. #87
    Join Date
    Jun 2003
    Posts
    95
    I go to a school where there are quite a few people quit adept at programming, but I offer this challenge: Write your own programming language. The requirements:

    1. An executable parser/compiler
    2. A wide array of functions and variables
    3. Language should be able to handle a majority of programs that C/C++ can handle
    4. Must be able to run on both Linux and Windoze
    5. Simple syntax

    Maybe the "JL" language could come out of here. Start coding

  13. #88
    Join Date
    Sep 2001
    Location
    Just for kicks
    Posts
    1,831
    Originally posted by grady
    swap two integers without using a temporary variable.
    Here is my version in LISP. It's my first LISP program, so go easy on me.

    Code:
    (setq lis (list 3 8))
    (setq lis 
       (list 
          (second lis) 
          (first lis)))
    I put both numbers into one list, and that let me do it with only one data type. Hope that's legal.
    "You cannot invade the mainland United States. There would be a rifle behind each blade of grass." --Admiral Yamamoto, 1941

  14. #89
    Join Date
    Aug 2002
    Location
    Essex, UK
    Posts
    937
    If you're going to write your own programming language, take a look at flex and bison to help you. Linux Format (in the UK) has been running a great series on creating a programming language for several issues now, and flex and bison are what the author uses.
    Registered Linux User #325947

    Check out Feather Linux, my distro.
    (Yes, it's shameless self promotion, deal with it )

  15. #90
    Join Date
    Dec 2000
    Location
    Glasgow, Scotland
    Posts
    4,361
    Originally posted by sasKuatch
    Here is my version in LISP. It's my first LISP program, so go easy on me.

    Code:
    (setq lis (list 3 8))
    (setq lis 
       (list 
          (second lis) 
          (first lis)))
    I put both numbers into one list, and that let me do it with only one data type. Hope that's legal.
    Did anyone post the Python solution to this? It's really neat:

    Code:
    a,b = b,a
    Will swap the two I was dead impressed when I learnt that (I'm easily pleased)

    Code:
    >>> a=100
    >>> b=200
    >>> a,b=b,a
    >>> a
    200
    >>> b
    100
    >>>
    mrBen "Carpe Aptenodytes"

    Linux User #216794

    My blog page

    3rd year running - get yourself to LugRadio Live 7th-8th July 2007, Wolverhampton, UK. The premier FLOSS community event.

Posting Permissions

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