57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 16 hours ago
Member for 11 years, 6 months, 6 days
Difficulty Advanced
We shall not cease from exploration, and the end of all our exploring will be to arrive where we started and know the place for the first time.
This is a nice example of how chaining can help you write better code.
First, x == 1 and y == 1 can be written as x == y == 1.
Then you see you have it also in equivalence.
if x == y == 1 or x == y == 0:
Then you see you can factor out x == y.
if x == y in (0, 1):
Then you realize that
More
You're aware that you wrote the same thing three times? :-)
More
Very simple, and I'm actually surprised it works. :-)
Few details:
line 6: "continue" would much better fit here instead of "pass". Then "elif" in line 7 can simply be "if". Or just reverse the logic, "if n in target:", and then nest another condition. The best, of course, is to use EAFP. Just
More
You could have had even less code here:
checkio = {
... # your wonderful dict
}.get
;-) (I know that's not your main point, but it is a point: code is practically nonexistent here.)
BTW, see my solution as an antithesis to this: maximizing code, minimizing data. :-)
More
I've seen that many people look for my solution of this mission, and they only find the horrible code I've written about three years ago, when I first solved this mission. I think it's a shame. In the meantime, both I and Python have become much better, and this is the result. :-)
More
You can use * in the ''.join, too.
''.join([head.upper(), *body, tail if ...])
More
LOL. I'm beginning to like you. You have some potential. ;-)
(Of course, you're aware of bin builtin? Just checking...)
More
Why [0]? There is no char in Python, just str of len 1. Just as there is no "digit", just a single-digit int. :-)
And don't aggregate over listcomps. Drop the [] inside .join().
More
Next time someone tells me Python is a functional programming language, I'll show them this. :-DD
More
You could have just slapped `functools.lru_cache(maxsize=5000)` on your `dec_to_rom` and call it `checkio`. :-P
More
That counting from 1 at every step feels forced a bit. Python naturally counts from 0.
For "a in bla1 and b in bla2 and c in bla3"... you might wish to learn about sets. Precisely, sets of tuples.
In your inner functions, you don't need lines like 25 and 26. Python returns None by default, whi
More
w(y,1+i,13)==4 for i in range(12)
same number of characters, but easier to read IMO. Of course, the true portable solution is
calendar.January + i
:-D
If you really want to have as few hits as possible, a month has Friday 13th iff it has Friday 6th. And 6 is shorter than 13. :-)
More
Specialcasing what shouldn't be specialcased, sorting to find the minimum, list "comprehensions" which do nothing at all... :-/ A perfect example of how you can't fix the bad code by documenting it. :-]
* What's wrong with treating 0 the same as all the other numbers?
* Imagine you have a thousan
More
Cool. Especially the - grid[row][col] part. ;-)
In slicing, max is unfortunately necessary, since -1 has a different meaning. But min isn't necessary.
r[max(0, col-1):col+2]
works fine.
More
Line 21 would probably be easier to parse if you'd filter a set to get a set: {(x+1, y), (x, y+1), ...}. And when you see this, it's even better to write do\_not\_hurt as a _set_ of possible indices, and just intersect your set of offseted positions with it.
Also, when you have a set of possible in
More
You can drop the []. "".join(l for ...) is clearer, more direct, uses less memory, and potentially faster.
More
''.join and generator expressions would be much nicer solution instead of that C-like loop.
(Not directly applicable since numbers are small, but might be interesting: [Schlemiel the painter story](http://www.joelonsoftware.com/articles/fog0000000319.html))
More