Hacker News new | past | comments | ask | show | jobs | submit login
Put your programming skills to the test (coderbyte.com)
21 points by tux1968 on Feb 12, 2012 | hide | past | favorite | 33 comments



Nice.

For super quick learning, it sure would be nice to see how others solved the same challenge. Just a few suggestions for links in the "Your code was correct, great job!" box:

  - last 5 correct solutions
  - most common solution
  - solution in least lines of code
  - solution in least bytes of code
  - solution presented by <person requested>
and if you really wanted to get clever:

  - most unique (by some definition) correct solution 
  - most elegant (by some definition) correct solution
  - you should use <this> instead of <that> and <why>


The Python version seems to be using an interpreter that frankly just doesn't work:

    x = [1, 5, 3, 2, 6, 4]
    x.sort()
    print x

    Output: [1, 3, 2, 4, 5, 6]
Not to mention the incomplete standard library. I'm not sure what is the interpreter they're using but it's actually not that hard to sandbox the CPython one and disable certain functions/modules if necessary.


    def pyChallenge():
      print sum(s for s in range(1000) if s % 7 != 0 and s % 5 != 0)

    pyChallenge()
Produces a TypeError, and using xrange produces a NameError (Python 3?). I have no idea what they're trying, but it doesn't work.


I assume it's Python 2 (print is a keyword, not a function).


Ah of course, a SyntaxError would take precedence over their broken builtins.


Also, the JS seems to be quirky:

    function jsChallenge() { 
      return 1;
      return 2;
      return 3;
    }
Returns 3


> The Python version seems to be using an interpreter that frankly just doesn't work:

  NameError: name 'reduce' is not defined


If it's python3, the previously built-in reduce() has been relegated to the functools module. But I don't think this is python 3.

I'm not sure what it is, but I know I don't like "guess which subset of the language you get" being harder than actually solving the algorithms challenges.


It takes a long time to get from challenge to challenge. It'd be better if from my profile maybe it opened a new window and I could just go down the list doing them all. As it is now it goes to a page explaining the times and then asks me if I'm sure I'm ready after that.

It's a cool concept.

I also found that I like sites that don't focus on rankings so much. It's better if to achieve a level you get a certain number of points. When you have rankings, if a new person joins your site it looks like a daunting task to get to the top.

Also, I would include forums for discussing solutions after you've solved it or attempted a problem a certain number of times. Maybe let people see the solution forum and 'solve' the problem, but they only get 1 point for that. It can be frustrating to be stuck on a hard problem for someone trying to learn. Maybe it'd be cool if you let people ask questions about problems and other users could get points for answering questions, while making sure not to give away too much.

Some functions are missing from Python, and being able to use the standard lib would be nice.


I'm not a js guy at all... can anyone explain why this doesn't work for the guest challenge? I googled a bit and it seems like it should have.

  function guestChallenge() { 
    // code goes here
    var num = 0;
    for (var i = 1; i< 1001; i++) {
        if (i.toSring(10).match(/7/));
        else num+=i;
    }
    return num;          
  }
Edit: I really should have added more context! The challenge was:

Using the JavaScript language, have the function guestChallenge() add up all of the numbers from 1 to 1000. But everytime a number that contains a 7 is reached, don't add that number to the others (ie. exclude 7, 17, 370, etc). Do not put any code outside of the function and use the return keyword to return your answer from within the function.

And my program didn't generate any output at all, which leads me to believe I made a syntax error as opposed to just a logic error.

Edit again: Yes. I just had to fix my typing error ("toSring"), and then it passed. Thanks, guys!


s/toSring/toString/

To others, the demo question on the home page is a divisible by 5 or 7 problem. This is one of the guest challenges and is that the number contains the digit '7'.


Add when the numbers are divisible neither by 5 nor 7. And I think, you are looking for digit 7 in the numbers?


I think you missed a 't': i.toSring(10)


Thank you... I can't believe I wasn't seeing that!

I'm surely not the only one to do this sort of thing. Maybe there should be some kind of feedback instead of nothing happening when I click the run button.


Divisible by 7 or 5. Not only 7.


You are thinking of the challenge on the front page. He's talking about the first of the three "guest challenges" you get if you click the link on the front page to see more challenges.

The front page challenges asked for the sum of the integers from 1 to 1000, excluding those divisible by 5 or 7. Here was my sort of smart-ass answer:

   function jsChallenge() { 
     var num = 1000;
     var t = num;
     var sum = t*(t+1)/2;
     t = Math.floor(num/5);
     sum -= 5*t*(t+1)/2;
     t = Math.floor(num/7);
     sum -= 7*t*(t+1)/2;
     t = Math.floor(num/35);
     sum += 35*t*(t+1)/2;
     return sum;
}

The first guest challenge asks for the sum of the integers from 1 to 1000, excluding those that contain the digit 7.


If you're going to be a smart-ass, then go all out.

  function jsChallenge() {
    function sum(n) {
      var k = Math.floor(1000 / n);
      return n * k * (k + 1) / 2;
    };
    return sum(1) - sum(5) - sum(7) + sum(35);
  }


Here's a fun way to solve

Using the Python language, have the function pyChallenge() add up all of the numbers from 1 to 1000. But every time a number appears that is divisible by 5 or 7, disregard it and do not add that number to the others (ie. disregard 7, 10, 15, 21, etc). Do not put any code outside of the function and use the print keyword to return your answer from within the function.

    def pyChallenge():
        sum = (1000 * (1000 + 1)) / 2
        for i in range(5, 1001, 5):
            sum -= i
        for i in range(7, 1001, 7):
            sum -= i
        for i in range(35, 1001, 35):
            sum += i
    
        print sum
    
        #As opposed to:
        #sum = 0
        #for i in range(1, 1000):
        #    if i % 5 and i % 7:
        #        sum += i
        #print sum
    
    # this call is needed to test your function
    pyChallenge()


Any particular reason you didn't go for the list comprehension?

  def pyChallenge():
    print sum([el for el in range(1001) if not((el%5==0) or el%7==0))])
  # this call is needed to test your function
  pyChallenge()


Really fun, but it seems like it provides JS input even if you use python. This causes all of the input cases to be marked as incorrect. For the Arith Geo question, here was my code: https://gist.github.com/1809940 and here was the result: https://gist.github.com/1809944 . So for example it said 'new Array(1,2,3,4)' yielded incorrect output. But I tried running [1,2,3,4] and it worked fine.

I know I selected python because it let me test my code by running it both before and after I submitted.

Anyway it's still really fun - keep up the good work!


Idea is good, and have crossed my mind a few times. Design is OK - clean and simple.

Yet, UI is ridiculous. Logging in utilises pattern, I've never seen before (just displaying the same login form with a tiny "Thanks for logging in" message below).

If you use javascript so thoroughly, try to implement HTML5 History API (stay clear of hashbangs, please). A few times I clicked "back" and went back 5 steps.

Some of backend glitches, probably, can be ignored because of "unexpected" load, right? :)

Having said all that, it's good that after Bespin and all-favorite CodeAcademy, programming challange sites get modern touch.


Very cool.

One thing I would recommend is making sure the problem descriptions are extremely clear, clarifying bounds, etc. For instance, "Using the JavaScript language, have the function jsChallenge() add up all of the numbers from 1 to 1000." This should probably read "... numbers from 0 to 1000 exclusive" or something similar. Looking at problems from programming competitions such as ACM ICPC would provide really great reference material, at least in terms of how to describe a problem.


Awesome website! Just one thing. Before signing up I tried one of the javascript exercises, when I submitted it I was taken to another page describing the benefits of being a member. After signing up, I noticed that I lost my working solution to the first exercise I tried. It would be nice if you guys found a way to save first-time users code. Looking forward to using the site!


I like the idea, but what version of Python is supported? It seems that some operations are not supported. On the first challenge it didn't like the `sorted` built-in or allow iteration over a str object. I ended up solving the challenge, but in a way that I would never use in real application, i.e., not idiomatic Python. It should be clearer what language features are allowed.


It didn't like the xrange function. Also doesn't seem to like the generator expressions.


It doesn't seem to like the map function either. List comprehensions, which seem to work, could be used instead but it would be nice to know which features are disabled/not supported before starting to code.


List comprehensions worked but reduce did not. Had to resort to for loops.


Fun idea, but by the time I made it to the third challenge, I could no longer submit my solution. I was stuck on the please wait screen. I suspect this is due to the load imposed by being featured on HN right now, but in the interest of scorekeeping, it's not clear how to revert the challenge to regain the lost time points.


One thing i dislike about these sites is they mainly seem to deal with algorithmic problems - the sort you'd find in a typical programming textbook - rather than any genuinely interesting or fun challenge.


This is awesome. One point would be to change the spec of Panlindrome to say print 'false' when it's not a palindrome. (It just says print 'true' when it is :))


This is also a very fun diversion - http://www.pythonchallenge.com/


Are there any issues with certain passwords (too long, containing special characters)? Also, where is the forgot password link?


It looks like it doesn't like recursion.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: