15
Alexander Vikulin
Last seen 1 year ago
Member for 9 years, 8 months, 2 days
Difficulty Normal
is this efficient way of doing that?
wouldn't starmap first run str.endswith for ALL permutations before any checks for Trues?
More
this is humiliating! :)
i even employed recursion to solve this one, and yours looks so concise and ummmm... simple, when you get a hold of it...
although, it's surely not the most "clear" one. ;-)
More
still this is about 10% slower than a while solution:
def friendly_number(number, base=1000, decimals=0, suffix='',
powers=['', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']):
d, n, p, p_len = decimals, float(number), 0, len(powers) - 1
while abs(n) >= base and
More
**or gifts == number** part is useless, because this is definitely not the best gift anyway and this bag is lost already.
after **number > gifts // 3** updating **maximum** is a waste of time since any gift better than maximum will return True and terminate bag processing.
calculating **gifts // 3
More
While digging into how this speedy solution works I discovered that it fails for the following case:
assert break_rings(({3,4},{4,5},{5,6},{6,7},{7,4},{3,8},{8,9},{9,10},{10,11},
{11,8},{3,12},{12,13},{13,14},{14,15},{15,12},{3,16},
{16,17},{17,1}
More
this time i learned that i can slice beyond upper bounds and walk away with it.
man your code is so enlightening!
More
This was inspired by [veky](http://www.checkio.org/user/veky/)'s elegant [solution](http://www.checkio.org/mission/the-square-chest/publications/veky/python-3/two-counters/), where he challenged the readers to improve his code to work for cubes of _any dimension_ and _any cube edge length_.
Test wi
More
This is a more optimal version of [this solution](http://www.checkio.org/mission/the-square-chest/publications/vikulin/python-3/any-n-dim-cube-any-cube-edge-side/)
Which was a solution inspired by an elegant [veky](http://www.checkio.org/user/veky/)'s [solution](http://www.checkio.org/mission/the-s
More
this is about 10% faster than using **math.log**
from math import log
def friendly_number(number, base=1000, decimals=0, suffix='',
powers=['', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']):
p = min(int(log(abs(number), base)) if number else 0, len(powers) - 1)
More
This solution is notable for 3 things:
1. It uses an interesting feature of function [Default Argument Values](https://docs.python.org/3.3/tutorial/controlflow.html?highlight=define%20functions#default-argument-values) to persist values between function calls. This saves us from defining a global v
More
**if n//10 else 1** will reduce recursive calls by one, but will calculate **n//10** twice as many times... or will it be optimized by jit compiler/interpreter?
More
This is more than 6 times slower that this [solution](http://www.checkio.org/mission/loading-cargo/publications/vikulin/python-3/dynamic-using-sets-fast-short-and-readable/)
More
This is about 50% faster than
checkio=lambda d:[x for x in d if d.count(x)>1]
I guess d.count(x) is not cached for repeated calls with the same x.
More
This is faster than each row updating histogram and scanning it for the largest rectangle, but it uses more memory.
More
Pay attention that because of the way Python initializes and treats default function arguments when mutable objects are used as default values, all changes to the **counter** will be retained through subsequent function calls.
More
This version runs much faster than my first simple solution shown below, because it scans the whole field only once during the first step. After that it only scans cells that where good on a previous step.
from math import hypot
from collections import Counter
def checkio(prev, counter
More
Note that modifications to **counter** object will be retained through the function calls, because of the way Python works with default parameters values.
More
isn't this solution faster?
def checkio(data):
from collections import Counter
c = Counter(data)
return [x for x in data if c[x] > 1]
More