49
Awesome Team
Philippe Cholet
https://github.com/Philippe-Cholet
Last seen 1 hour ago
Member for 6 years, 2 months, 27 days
Difficulty Advanced
I was a math teacher in France for two years. I'm currently reconverting to IT, I'm here to improve my Python skills, and practice English.
If you want print the path we take without a single change of **YOUR code**, you can use this decorator I did for fun. Just put
@print_maze_path
before the definition of YOUR function. (Your function can have more than one argument.)
def print_maze_path(f):
CHARACTERS = EMPTY, WALL
More
Split is not helpful at all. Instead, this below is enough:
x = str(number)
maximum = max(x)
More
`[x for x in y]` is equivalent to `list(y)` but here you don't even need a list. A string is a good enough iterable: `int(max(str(number)))`
More
There are other ways but I like the use of numpy, especially `reshape` and array of booleans. It's original.
More
It's not 3rd party.
Plus
# You do not use the index i but a[i] and b[i].
def hamming(a, b):
return sum(s != t for s, t in zip(str(a), str(b)))
def is_doublet(numbers):
# something with zip too to avoid the use of "i".
More
Given a list of moves _L_, the sequence
(stones(n, L) for n>=0)
is eventually periodic (and very often periodic), and the period depends only on _L_.
Unfortunately, compute this period is not really simple in general. But with it, we can compute _stones(n, L)_ easily for **very large** numb
More
def match(comp, test):
count = 0
# you do not use the index j but comp[j] and test[j]
for c, t in zip(comp, test):
if c == t:
count += 1
# "count == 2" is already True or False, return it
return count == 2
# or
def match
More
else after a for loop? I know the thing but useless here.
No need of continue with "!=" test.
if matrix[i][j] != -matrix[j][i]:
return False
Well, then, you should considerate the use of "all(...)"
all(matrix[i][j] == -matrix[j][i] for i in range(len(matrix))
More
List comprehension is so... so good...
t = [[- matrix[j][i] for j in p] for i in p]
Then "matrix == t" is already the boolean you want return.
return matrix == t
Finally,
def checkio(matrix):
p = range(len(matrix))
return matrix == [[- matrix[j][i] for j in p] for i i
More
I don't like it, why sort all the list when you just want min or max? Bad computational complexity here : if n is the length of the list/iterable... O(n log n) instead of O(n) when you just look the iterable's elements one by one.
For me, the purpose here is not use a powerful function like sorted.
More
It seems complicated. But probably clever "sweep line algorithm". Do you think this work for rectangles with float coordinates? Because int coordinates is a big simplification for this problem.
More
Don't you think you spam published solutions?! 6 (very very similar) published solutions.
More
`if res[i] != True` then `res[i]` is already `False`. so lines 7 - 11 can be much shorter. Plus two pythonic changes:
def stones(pile, moves):
res = [True] + pile * [False]
for i in range(1, len(res)):
for j in moves:
if i - j > 0 and not res[i - j]:
More
About the first, first... what about list comprehension? Second, I'm pretty sure it should not work. It counts the number of email addresses with "." or "+" in the name part. Plus, case would matter, and duplicates would be counted multiple times.
```python
def unique_emails(emails: list[str]) -> i
More
We can do it in three lines without import math.hypot, but with complex numbers: a little less clear IMO.
grid = lambda N: ([i,j] for i in range(N) for j in range(N))
test = lambda i, j, probes: all(round(abs(i-x+(j-y)*1j)) == d for x,y,d in probes)
checkio = lambda previous: next(c for
More
abs(d1-d2).days #work so this too
return abs(date(*date1) - date(*date2)).days
# then eventually
days_diff = lambda date1, date2: abs(date(*date1) - date(*date2)).days
More
**Few explanations...** (I won't write a mathematical article for it)
_Mathematically:_ P is the transition matrix of the markov chain involved here.
_In english:_ P[i,j] is the probability to go to j from i with one dice roll.
M is the same thing as P with a ban on going through target.
**1/(I-
More
Even if you reinvent the wheel (it's not recommended like Veky said)...
Lines 6-8 can be one simple line:
ints[i], ints[i+1] = ints[i+1], ints[i]
And while loop should be a for loop here.
More