26
Freek Dijkstra
http://www.macfreek.nl/freek/
Last seen 1 year ago
Member for 11 years, 5 months, 3 days
Difficulty Normal
Physicist by education.
Network specialist by profession.
Amateur programmer by hobby.
Why reinvent the wheel? https://docs.python.org/3/library/difflib.html#difflib.SequenceMatcher.find_longest_match
More
Just a little more insight. I disliked that this method may modify the iterator by changing it's 'position'. However, this is what the build-in **min()** and **max()** do too.
>>> it = iter([1,2,3,4,5,6,7,8,9])
>>> list(it)
[1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> it = iter([1,2,3
More
FYI, I wanted to leave the special case of extracting the first argument out of the loop.
Since sets do not support indexing (only iteration), I could not write **running_max = key(args[0]); for x in args[1:]: ...**. Hence the somewhat clumsy iter() and next() construct.
More
I completely missing about the 'g' type for [string formatting](https://docs.python.org/2/library/string.html#formatspec). Lines 28-36 could better be written as:
return "(x-{0:g})^2+(y-{1:g})^2={2:G}^2".format(round(Ux,2), round(Uy,2), round(R,2))
More
This is actually a brute force algorithm, but runs very fast by checking things in the right order. Actually, on my (5 year old) laptop it actually runs fastest from a few contenders.
* MacFreek (this solution): 0.21 s
* [CimpaMiroslav](http://www.checkio.org/mission/numbered-triangles/publicati
More
Your solution seems to fail these two tests (I presume they have been added later):
assert checkio(
[[9, 5, 1], [1, 5, 9], [9, 1, 5],
[1, 9, 5], [5, 9, 1], [5, 1, 9]]) == 54
assert checkio(
[[99, 9, 1], [99, 2, 9], [9, 99, 3],
[4, 9, 99], [5, 99, 9],
More
On the plus side: the code is clean, the helper functions are clear, and native Python functions are used where possible,
On the minus side, I went out of my way to get the xor of all digits in sequence. Of course, I could simply have taken the xor of the whole number. DÔH!
sum[int(d) for
More
One comment: you may potentially make it even faster by using the digits as the key in the _gen_ dict, instead of the digit positions.
For example, for _checkio('237637')_ both _gen[1,2]_ and _gen[4,2]_ would both contain results that the two digits 3 and 7 could yield (_{37, 10, -4, 3/7, 21}_).
More
I like it that you provided additional insight on lines 10..13.
The only possible improvement I can think of is to check that the input >= 1. For number = 1, it raises a ValueError during int(''), and for number = 0, it goes in an infinite loop. Admittedly, this is not strictly required, as the i
More
Very nice solution! And fast indeed!
It took me a little while to understand your algorithm. For other interested readers, here it is with my annotations.
def checkio(data):
"""Solution by nickie"""
N = len(data)
print (data)
# gen[i,l] is a set of all p
More
I just might have gotten a bit carried away here in my desire to solve this in linear time instead of iterating over it.
I got an exact solution to find at what time step the feeder runs out of food, but found that it was a bit prone to error. For example when it was just at time step 8, it would
More
expr = re.compile("^.*(?=.{10,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$")
The .* at the start of the regexp seems spurious.
re.compile("^(?=.{10,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$")
would also work, since you already have a .* in every lookahead.
More