34
Last seen 2 years ago
Member for 11 years, 5 months, 27 days
Difficulty Normal
Well, your solution is O(n) but need unnecessary treatment, I think.
At least, why do you make 2 Counters?
May I suggest this following, very similar to yours but with less memory used:
def checkio(data):
from collections import Counter
count = Counter(data)
return [n for n i
More
Changing the beginning of the year is a nice idea.
Maybe extracting a function to compute days would be nicer:
def days_diff(date1, date2):
def days(date):
y, m, d = date
correction = m <= 2
y -= correction; m += 12*correction - 3
More
To my mind, this solution is not really creative.
Moreover, it presents several flaws:
* Use python unpacking with * operator instead of enumerating indexes: _date(*date1)_
* As pedrobueno mentions, *timedelta.days* is useful here.
* Why 2 _return_ statements? Last one is useless (as extra variabl
More
Python 3 annotations, very nice!
Just to mention it to future readers ;-) :
Switch lines 11 and 12 and you have a solution that runs 20x faster, rather than this one which runs in more than 1s on my slow (very slow) computer!
More
I definitely like the representation you have made, keeping stack and moves in same list; even better with the use of `slice`.
However, I can't tell I'm fond of this list/''.join step on tuples. If you wanted to introduce some performance with the use of `deque`, I have the feeling that looping two
More
Again a wrong solution on left-down diagonal:
Tested with:
checkio([[1, 5, 4, 4, 3],
[2, 2, 4, 1, 5],
[1, 4, 3, 5, 4],
[4, 3, 3, 2, 5]])
Correction is in line 20:
if (x+4 <= l_x and y+1 >= 4 and
More
And certainly possible to go down by changing type test.
Edit: Well, Veky's idea breaks down character count: 'd*0==0'
More
Simple approach (not as ugly as you said!)
Just to give you a more pythonic implementation:
def checkio(number):
pig = newpigs = 1
fooddif, food = 0, number
while food:
oldfood, food = food, max(food - pig, 0)
fooddif = max(fooddif, ol
More
Easier: the most frequent day is always the first day of the year.
Second day of the year has the same frequency than the first one when its year is leap.
More
Such exotic lib with use of recent RecursionError, I bet this solution is Veky's!
Nice union-find algorithm, although handling cycles by exceeding max depth recursion limit seems a bit inefficient (and wrong on very big graph - 1000 edges, isn't it? - but I don't hope such big tests at CheckIO :-P)
More
Nice solution (quite the same on my own, except I reasoned on k-1).
Just a bit surprised by last line ; why not simply ;-) :
return max(t, number - s)
More
This is effectively a DFS. You can search for Dijkstra's algorithm if you want to learn more about.
Just a few things:
lines 8-14: you can factorize these lines for 'clearer' code
pair = drones.split("-")
for index, drone in enumerate(pair):
if node == drone and pair[index - 1] no
More
This code searches through _text_ 26 times - it is not what I call a "Speedy" solution.
More
Smart way to "limit" your grid but here you should use 'infinite' grid by memoizing live cells, truly easier.
More
Better than first one, really more readable!
But still a niptick: imagine you have 2 live cells (0,0) and (100, 100).
Are you really gonna loop through 10,000 (-2) dead cells for nothing?
More
I'm glad you chose to code such a mathematical masterpiece.
I didn't have the courage to write it down !
More
for golfing, here is your solution in 65 characters ;)
check_pangram=lambda t:len(set(filter(str.islower,t.lower())))>25
More
Strings are also iterable, so you can use _for_ loop and _in_ operator on them directly.
More
'd*0==0'... Amazing, really.
By the way, 1 more character to delete: space between 0 and 'and' ;)
More