44
Last seen 4 months ago
Member for 10 years, 2 months, 20 days
Difficulty Normal
return '{:.0f}'.replace('0', str(decimals)).format(number) + powers[e] + suffix
You can use nested brackets for **decimals**:
return '{:.{}f}'.replace(number, decimals) + powers[e] + suffix
More
# Appendix (but longer than code)
In this approach, numbers are converted to 2-D coordinates (x, y) to calculate [Manhattan distance](http://en.wikipedia.org/wiki/Taxicab_geometry) between them. [Triangle wave](http://en.wikipedia.org/wiki/Triangle_wave) is used for the converting.
----
Let 1 b
More
### Appendix (but longer than code)
----
First, let jars be small and large:
small, large = min(jars), max(jars)
The solution can be repetition of either following sequences named **SMALL** and **LARGE**:
1. **SMALL**
1. Lake-to-Small, Small-to-Large
1. Large-to-Lake, Small-
More
Partial: it is an interesting approximation, but not always correct.
When the arc passes on grid points, your function will output a wrong result.
For example, if radius == sqrt(2), i.e. the arc passes (1, 1) and more, number of partial tiles is 8, not 12.
I think it no problems so far beca
More
It's simple and clear.
I've published a [solution](http://www.checkio.org/mission/dark-labyrinth/publications/gyahun_dash/python-3/second/) inspired by your solution. Thank you.
More
You can use built-in function [complex](https://docs.python.org/3/library/functions.html#complex).
More
for c1, c2 in itertools.product(cakes, cakes):
if c1 == c2: continue
You can use **combinations** instead of **product**.
for c1, c2 in itertools.combinations(cakes, 2):
More
xr = filter(lambda a: a >= 0 and a < len(map_), range(x - 1, x + 2))
is equivalent to:
xr = filter(lambda a: 0 <= a < len(map_), range(x - 1, x + 2))
More
### Example:
((0, 0, 1, 0, 0),
(0, 1, 1, 1, 0),
(1, 1, 1, 1, 1),
(0, 1, 1, 1, 0),
(0, 0, 1, 0, 0))
First, we get horizontal and vertical RunLengths(horis and verts):
((0, 0, 1, 0, 0), # RL(length=1, y=0, x=2)
(0, 1, 1, 1, 0), # RL(length=3, y=1, x=2)
(1, 1, 1,
More
About line 9-12,
if price//coin + length < shortest:
return price // coin + length
else:
return shortest
You can write as follows and delete if-else:
return min(price // coin + length, shortest)
More
length = max(map(len, strings)) if strings else 0
In Python 3.4, we can write:
length = max(map(len, strings), default=0)
More
str.format(str.format("{{:0>{}b}}", len(c)), p)
You can call format as method of "{{:0>{}b}}".
"{{:0>{}b}}".format(len(c)).format(p)
Furthermore, nested bracket is available in format string.
"{:0>{}b}".format(p, len(c))
Please try it if you don't hate calling methods from e
More
1 up 2 right 3 down 4 down 5 left 6 left 7 up 8 up 9 up 10 ...
----
Numbers go along dirs = U, R, DD, LL, UUU, RRR, DDDD, LLLL, UUUUU, ...,
so we can get Manhattan distance by counting them (U: up, R: right, D:down, L: left). For example:
def find_distance(4, 10): # DLLUUU
ret
More
return sum(map(abs, itertools.starmap(operator.sub, zip(*map(coords, args)))))
You can use simple map instead of starmap:
return sum(map(abs, map(operator.sub, *map(coords, args))))
More
To get __time__, we solve the following cubic equation:
time ** 3 + 3 * time ** 2 + 2 * time - 6 * food = 0
More
Line 5:
bins = [re.sub('(?P\d+)(\.)?', binarize, a) for a in adds]
Line 8:
pat = ','.join(['(?P\d+)\d*'] + ['\\1\d*'] * (len(adds) - 1))
More
def all_routes_from_node(m, node):
possibilities = []
for arc in m:
if node in arc:
possibilities.append(arc)
return possibilities
How about using **list comprehension** here?
def all_routes_from_node(m, node):
return [arc fo
More