17
Last seen 5 years ago
Member for 11 years, 2 months, 23 days
Difficulty Normal
Brute forcing is a horrible thing, really.
Dynamic programming for 0-1 knapsack gives you a fast and nice solution.
More
Hint: [1, 2, 3][2:10] == [3],
[1, 2, 3][max(0, n-1):n+2] works great for any 'n'
More
Yes, it's going to work, BUT it hardly makes you 750 best gifts. Other solution (with calculating mathematical expectation of max value of upcoming gifts) gives you much better result - about 850 best gifts.
But anyway, your code does just what it should do, nice ;)
More
stones_aux = list(stones) - it's better to use stones[:] to copy lists.
And, again, it's a bruteforcing. Never use it if it's not the only way.
More
Hey! Why doesn't this task accept solutions?
I've got completely new solution 10 lines long (total) instead of the monstrous original one :(
More
Why do you need to store all the intermediate data in a? You can just write:
sum((from_date + timedelta(days = i)).weekday() > 4 for i in xrange(delta.days+1))
It will use constant space (because of generators xrange and (... for i in ...)) instead of linear.
More
Nice and clear... I like it!
I don't know why everybody tries to write one line of mess instead of ten lines of readable code with comments.
More
http://www.checkio.org/mission/digits-multiplication/publications/Flid/python-27/reduce/
"reduce" should not be imported. The other lines are equal!
More