57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 3 hours ago
Member for 11 years, 6 months, 7 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.
Switch-pattern in Python is probably much more elegantly implemented with a dict, instead of a bunch of ifs with almost the same code.
Also, don't single-exit your functions forcefully. You don't need res at all. Just delete line 4, replace "res =" with "return" in the rest of the code, and return
More
You don't need a new function, you can reuse checkio by employing default arguments:
def checkio(data, count=0, i=0):
... now you just write code for tricky_data
return checkio(data, count, i)
BTW count is a horrible name for sum. :-P
More
Aaargh. My eyes hurt. :-P
First, this is a classic example of how to go overboard with names. It would be _more readable_ if game_result was named just `r`. :-P
And those comments should really be names.
m_diag = r[0][0] + r[1][1] + r[2][2]
Or even
m_diag = ''.join(row[i] for i, row in
More
Again, too wordy and with strange names (from the perspective of English, `result` is much more common). But generally ok.
More
This solution is not good. Besides "special cases are not special enough",
and not using modern Python idioms like sorted(), it has a math error.
While c1d and b1d are calculated correctly, a1d _doesn't_ have to be 180 -
their sum. See http://goo.gl/UMrZNd and the resulting discussion.
More
> Second code ever written
You mean in Python, or generally? :-)
More
`>> 1` is very weird in this context. `// 2` is probably better. Otherwise you should also write `% 2` as `& 1`, to be consistent. :-D
But, in fact, people often need div and mod together, so Python provides it. That also saves you from writing (otherwise useless) line 4, since len is calculated on
More
Ah, you were so close to the simplest solution. :-)
`sorted(whatever, reverse=True)[0]` is easier spelled `max(whatever)`.
And there is really no need to sort the letters twice. Alphabet already provides them in the sorted order. :-)
More
Since you're already importing itertools, `accumulate` is not far away. And it could help a lot. ;-)
Also, `s + max(0, number-prev-s)` is just `max(s, number-prev)`. ;-)
More
OMG. At least write some function for checking divisibility, if you don't want to do it the canonical way (`if not number % 5`).
More
[Here](https://py.checkio.org/mission/roman-numerals/publications/veky/python-3/enum/#) is the Roman for comparison. :-)
More
Many things can be summed, at least conceptually. Look at this: remove `replace_map`, and the transformation in line 8 (`board=game_result`), and replace all `sum`s with `''.join`s (or put `sum=''.join` at the start:).
Then, instead of checking for `3` and `-3`, you can check for `XXX` and `OOO`. M
More
It's fascinating that almost everybody who uses chr-ord conjugation for files (a-h), _doesn't_ use it also for ranks (1-8), but uses str-int conjugation. Simple is better than complex. :-)
Also, sum(...) is better than sum([...]) on at least 3 counts. :-)
More