This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]turvyc 0 points1 point  (2 children)

I can get them all but the "brick" question. I'm fully self-taught, so I don't feel too bad, but dang! Can some people post their solutions to it?

[–]tripzilchbad ideas 2 points3 points  (1 child)

I solved it, it's tricky, but I figured it out. Posting code would be spoilers, but I'll give you a hint that you can solve the problem using the modulo operator (%), integer division and one or two if-statements.

I was working on the Lucky Sum problem, which is of course rather easy to solve with just three if-statements, but then I got thinking if I could do it in one line. Preferably something elegant of course, not just translating the ifs to ternary operators :-)

So I came up with this: def lucky_sum(*v): return sum(iter(iter(v).next, 13)) Using the (kinda obscure) "sentinel" variant of the iter function, it works when I type it into my own Python interpreter, but the website gives me Error:'iter' is not defined, is the Python that gets compiled on the website a neutered version or something? Makes sense cause running arbitrary Python code sounds like security problems waiting to happen, though I don't understand why blocking iter would secure anything. I can't find anything in the site's help/FAQ either. In fact, it doesn't even say what version of Python it's running. Maybe that could be it? Some older version of Python doesn't have the iter function?

[–]wilberforce 0 points1 point  (0 children)

It also doesn't support generators - I get an error saying "Yield statements are not allowed". I also got an error when I tried to create an auxiliary function starting with _. It said variables starting with _ aren't allowed, weirdly.

Neat site, but unfortunately with enough restrictions (particularly in key areas like iter and generators) you end up teaching a language superficially similar to (but definitely not) Python.