49
Phil15
30 56 64 Leader of the month
23067/ 25141
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.

Best reviews / Newest reviews
20 random searches-Phil15
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
First-shadai99
Split is not helpful at all. Instead, this below is enough: x = str(number) maximum = max(x) More
First-shan.u2008
`[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
First-pupo
No need of making a list. a string is an iterable that max can very well handle. More
numpy attempt-HeNeArKr
There are other ways but I like the use of numpy, especially `reshape` and array of booleans. It's original. More
First-Villentre
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
With lru_cache/setrecursionlimit and without-Phil15
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
Too long-mlhardy.mh
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
First-ndj_ys
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
First-YellowTree
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
Counter, sort first-HeNeArKr
Good comment. Without it, we would think it's possibly wrong. More
sorted-Cjkjvfnby
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
First-colinmcnicholl 1
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
Clear-U.V 1
Don't you think you spam published solutions?! 6 (very very similar) published solutions. More
First-DEADPOOL 1
`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
2 Solutions in 1-Alex_4444D
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
4 clear lines: next(possible points generator)-Phil15
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
date.datetime-Anton_Prokopovich
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
[numpy] 9-liner: Math magic with Markov chain-Phil15 1
**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
First-vladislav.bezugliy
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
1 2 3 4 5 6 7 8 9
10
11 12 13