57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 12 hours ago
Member for 11 years, 6 months, 24 days
Difficulty Advanced
We shall not cease from exploration, and the end of all our exploring will be to arrive where we started and know the place for the first time.
"if (len(data) > 0)" is just "if data"
data[1:len(data)] is just data[1:]
And your whole algorithm is just functools.reduce
And in fact already written in Python core, as "sum" builtin.
More
You could have written list(list(list([a,b]))), the effect would be the same. :-P
More
";" might be funny if everything else was in C style, but "sum" surely doesn't fit there. :-]
More
Nice reducing to addition of natural numbers. :-) pattern can be much nicer written using list comprehension: [i in range(b) for i in range(a)]. ;-)
More
Funny, but: first, Counter is really not needed, max can have key too. And second, tuples can be keys (ordered) - no need for base 42. :-)
More
You're reinventing the wheel. See Counter in collections module (standard library).
More
If you're trying to see how it works: just print(r) between lines 5 and 6. I'm sure you'll see what r is, and then the rest is pretty obvious. (Of course, if there are any questions, just ask.)
More
Doesn't work on empty list.
checkio=f=lambda x:x.pop()+f(x)if x else 0
would be better. ;-)
More
Meh. You could do much better if you were a bit bolder. :-D Maybe even find a closed formula. ;-P
More
Yes, cool. While I was obsessed with canonical representation of lines, you rightly saw that all that was needed was \_\_eq\_\_ on them.
More
Nice usage of Zeckendorf's theorem. ;-)
BTW it would be more scary without that friendly looking boo-ghost. ;-D
More
I think this is the first time I've seen an unconditional break at the end of the loop. :-)
BTW you don't need line 28, Python is smart enough to return None if there is nothing to return. ;-)
More
Better, but still not universal. Where previous worked for under 2\*\*32, this one works under 2\*\*100. :-] Python's recursion is not a way to code iteration.
http://neopythonic.blogspot.com.au/2009/04/final-words-on-tail-calls.html
More
Someone has added precondition. So all of your previous codes also work. Sorry.
Yes, this one works for all nonnegative m and n.
More