View Poll Results: Who do you think is the best beginner?

Voters
19. You may not vote on this poll
Page 13 of 22 FirstFirst ... 31112131415 ... LastLast
Results 121 to 130 of 217

Thread: [Beginner] Programming Challenge: 2

  1. #121
    Join Date
    Jul 2008
    Beans
    1,706

    Re: [Beginner] Programming Challenge: 2

    ok on my ubuntu side now i followed the sticky instructions and got hello world to print to console using gmcs and mono

    now i tried my program and got

    Code:
    Cannot open assembly UserInput.cs.
    any idea?

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

    Re: [Beginner] Programming Challenge: 2

    Quote Originally Posted by jimi_hendrix View Post
    ok on my ubuntu side now i followed the sticky instructions and got hello world to print to console using gmcs and mono

    now i tried my program and got

    Code:
    Cannot open assembly UserInput.cs.
    any idea?
    I compiled your code with gmcs.

    Code:
    gmcs p.cs
    (File was p.cs) and ran it with:

    Code:
    mono p.exe
    Bad news, it threw an uncaught exception, you might want to fix that.

  3. #123
    Join Date
    Jun 2006
    Location
    Gwangju, Korea
    Beans
    3,479

    Re: [Beginner] Programming Challenge: 2

    Quote Originally Posted by xnevermore View Post
    Alright, here is my solution in ruby, which is a language I just started to learn, thanks to why's (poignant) guide to ruby, which is got to be one of the most entertaining programming resources around.
    I'd rather call that book odd. Seriously, though, Ruby is my favorite language, so I took a special interest in your submission. Unfortunately, unless you fix it before LaRoza closes the contest, it will be disqualified. Here's what happened when I tried running it:
    Code:
    Name: mssever
    ./ruby.rb:6:in `setName': undefined method `start_with?' for "mssever":String (NoMethodError)
        from ./ruby.rb:50
    EDIT: I have a number of suggestions for how to improve your code, but I'll wait to post them until the contest is finished.

  4. #124
    Join Date
    Mar 2007
    Location
    Florida
    Beans
    Hidden!

    Re: [Beginner] Programming Challenge: 2

    Quote Originally Posted by mssever View Post
    I'd rather call that book odd. Seriously, though, Ruby is my favorite language, so I took a special interest in your submission. Unfortunately, unless you fix it before LaRoza closes the contest, it will be disqualified. Here's what happened when I tried running it:
    Code:
    Name: mssever
    ./ruby.rb:6:in `setName': undefined method `start_with?' for "mssever":String (NoMethodError)
        from ./ruby.rb:50
    EDIT: I have a number of suggestions for how to improve your code, but I'll wait to post them until the contest is finished.
    Your version just doesn't have an implementation of String.start_with?. Works fine here. But considering the majority of people probably don't have it either, he should probably find another way or make a quick implementation of it in the String class.

  5. #125
    Join Date
    Jun 2006
    Location
    Gwangju, Korea
    Beans
    3,479

    Re: [Beginner] Programming Challenge: 2

    Quote Originally Posted by Phenax View Post
    Your version just doesn't have an implementation of String.start_with?. Works fine here. But considering the majority of people probably don't have it either, he should probably find another way or make a quick implementation of it in the String class.
    If xnevermore is using some additional library, there should be an appropriate require statement. If he/she is using some version of Ruby other than the Ubuntu Hardy default (1.8.6), that should be stated, as well--especially since the most likely other version would be a development version.

    I'm careful to maintain my Ruby installation in the default state so I can distribute my software without those kinds of problems. So, I use 1.8.6, which is what you get when installing the package ruby.

    EDIT: By the way, I assume you meant to say that I don't have String#start_with?. That's an important detail in Ruby. And, this issue can be avoided by something like:
    Code:
    if name =~ /^[\s]/ # or /^ / for a stricter interpretation of the rules
    Last edited by mssever; August 8th, 2008 at 06:14 AM.

  6. #126
    Join Date
    May 2007
    Location
    SoCal
    Beans
    306

    Re: [Beginner] Programming Challenge: 2

    Arrrrgh for work keeping me so busy! Seeing this got me to at least install nasm and do the requisite hello world program. But it's been too long since the last time I wrote assembly and that part of the brain is rusted over, not just rusty! I immediately saw a series of compares with jlt's and jgt's keeping the input within bounds.

    Anyhow, thanks for the thread and the fun thoughts.
    Chris

    btw, I loved the bash entry!
    I love Linux & I convert windoze people.
    autokey-gtk automates emailing & boosts productivity with key bindings.

  7. #127
    Join Date
    Jul 2008
    Beans
    28

    Re: [Beginner] Programming Challenge: 2

    Quote Originally Posted by mssever View Post
    If xnevermore is using some additional library, there should be an appropriate require statement. If he/she is using some version of Ruby other than the Ubuntu Hardy default (1.8.6), that should be stated, as well--especially since the most likely other version would be a development version.
    Well you're wrong about the additional libraries. Just used the standard one. You're right about the ruby version though (i'm using 1.8.7), but you're wrong about it being a development version (1.8.7 is the latest stable, 1.9 is development).

    However, I did adjust my code so it would work with those using OLDER versions of ruby. Not everyone can be a trail-blazer, I guess.

    I didn't want people to think I was taking your ideas, though. Even though my first inclination was to use regular expressions, like you suggested, I decided to use another method instead... out of spite!

  8. #128
    Join Date
    Jul 2008
    Beans
    1,491

    Re: [Beginner] Programming Challenge: 2

    Quote Originally Posted by conehead77 View Post
    quit before you entered all data correct that is
    *But* you should be able (explicitly requested by the contest) to quit at *any* prompt... I guess having more than 1 function defined in your module may make that a bit easier to implement?

  9. #129
    Join Date
    Feb 2007
    Location
    Edinburgh, Scotland
    Beans
    391

    Re: [Beginner] Programming Challenge: 2

    Ahh, didn't know this finished so soon. Was quite tempted to write a client<->server model version, to practise network programming. May quickly hack one together when I get home, just to see if I can do it.
    Today we have 15 minutes of fame, tomorrow 15 minutes of anonymity.
    My Blog | Veza - Opensource TinyURL clone with sensible URLs

  10. #130
    Join Date
    May 2005
    Beans
    14

    Re: [Beginner] Programming Challenge: 2

    I am only an amateur programmer, but probably not a beginner. Here is my version in mono. Little bit of cheating, since mono handles unicode automatically. Also I ignore leading spaces, but I think all other requirements are handled.


    Code:
    using System;
    
    class ForumChallenge {
      static void Main() {
        Console.WriteLine("Type 'exit' at any prompt to exit");
    
        // Get the data
        // Most of the work is done in the AskandValidate function
        string forumName = AskandValidate("What is your forum name?\n(leading spaces are ignored, all other characters are valid)", 
            new NameValidator<string>());
        int age = AskandValidate("What is your age?\n(must be between 1 and 120 inclusive)", 
            new NumValidator<int>(1, 120));
        int userid = AskandValidate("What is your user id?\n(must be between 1 and 999999 inclusive)", 
            new NumValidator<int>(1, 999999));
    
        // Write the output
        Console.WriteLine("You are {0}, aged {1}; next year you will be {2}, with user id {3}; the next user is {4}", 
           forumName, age, age + 1, userid, userid + 1);
      }
    
      // Asks the question
      // Validates the answer using a validator
      static T AskandValidate<T>(string question, IValidator<T> validator) {
        bool validAnswer = false;   // remain in loop until valid answer or an exit request
        string errmsg;              // helpful error message if invalid answer
        T result;                   // the result
    
        while (!validAnswer) {
          // Ask the question and read the answer
          Console.Write("{0} ", question);
          string answer = Console.ReadLine();
    
          // do we want out
          if (answer.Trim().ToLower().Equals("exit")) {
            Console.WriteLine("bye");
            System.Environment.Exit(-1);
          }
    
          // validate the answer
          // if answer is invalid, print an error message
          // otherwise exit the loop and return the value
          validAnswer = validator.Validate(answer.Trim(), out result, out errmsg);
          Console.WriteLine(errmsg);
        }
    
        return result;
      }
    }
    
    // Validator interface
    // makes code reusable (hopefully)
    interface IValidator<T> {
      // allows use of different validator algorithms for different questions
      // returns true if answer is valid
      // result is the formatted answer
      // errmsg is error message
      bool Validate(string answer, out T result, out string errmsg);
    }
    
    // Validate the name
    class NameValidator<T> : IValidator<string> {
    
      // Validation
      // Empty strings are invalid
      // Leading spaces are silently ignored (but can be checked for if necessary)
      public bool Validate(string answer, out string result, out string errmsg) {
        result = "";
        if (String.IsNullOrEmpty(answer)) {
          errmsg = "Name cannot be empty";
          return false;
        }
    
        errmsg = "";
        result = answer;
        return true;
      }
    }
    
    // Validator for numbers
    // for now it checks only integers 
    // (should be extendable to check floats,doubles etc 
    // - probably needs reflection to call the right parse function)
    class NumValidator<T> : IValidator<int> {
      private int min, max;
    
      // We know the value limits
      public NumValidator(int minValue, int maxValue) {
        min = minValue;
        max = maxValue;
      }
    
      // Validate
      public bool Validate(string answer, out int result, out string errmsg) {
        result = -1;
    
        // Convert the string to int
        // Handle all exceptions
        try {
          result = Int32.Parse(answer);
        } catch (ArgumentNullException) {
          errmsg = "Number is empty";
          return false;
        } catch (FormatException) {
          errmsg = "Answer is not a number";
          return false;
        } catch (OverflowException) {
          errmsg = "Number is too big to be a valid age";
          return false;
        }
    
        // Check if number is within limits
        if (result < min || result > max) {
          errmsg = "Number is beyond acceptable limits";
          return false;
        }
    
        errmsg = "";
        return true;
      }
    }

Page 13 of 22 FirstFirst ... 31112131415 ... 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
  •