Skip to main content

All Questions

Tagged with
4 votes
1 answer
117 views

Calculate optimal game upgrades, v2

This is the second iteration of the code I originally posted here: Calculate optimal game upgrades. Based on the feedback there, I chose to change the code to use a dynamic programming approach with ...
ayaan098's user avatar
7 votes
2 answers
1k views

Convert 64-bit Gray code to integer

This algorithm encodes a 64 bit integer. As input I have a 64 bit integer a, for example: (a is a single 64 bit number,which I split in 8 bytes for readability) <...
tutizeri's user avatar
  • 173
2 votes
1 answer
145 views

Python 3 weighted random choice function memoized version

I have written a function that randomly picks one element from a set with different probabilities for each element, anyway it takes a dictionary as argument, the keys of the dictionary are the choices ...
Ξένη Γήινος's user avatar
1 vote
1 answer
494 views

Optimizing solution of Sum of Pairs: Codewars in Python

I need help to optimize my code for huge lists with approx. 10000000 elements. Is there a way to improve my algorithm or should I try to build a new one using a completely different approach? Task: ...
Luca Brasi's user avatar
6 votes
1 answer
437 views

Memoizing a tree's parent pointers in Python

I have a simple binary tree that has no parent pointers. ...
Mark Karavan's user avatar
7 votes
2 answers
749 views

Project Euler 357 prime number generator in Python 3

I'm brute forcing the Project Euler 357 since no better algorithm comes to my mind. The challenge asks: Find the sum of all positive integers n not exceeding 108 such that for every divisor d of n, ...
Bor's user avatar
  • 507
2 votes
2 answers
738 views

Memoizing decorator with retries - now with backoff added! (Part 3)

A continuation of Memoizing decorator with retries, part 2, and related to https://codereview.stackexchange.com/a/133493/47529. I liked my decorator before, but especially in my original use case of a ...
Dan Oberlam's user avatar
  • 8,064
6 votes
3 answers
587 views

Memoizing decorator with retries, part 2

A while ago I asked this question Memoizing decorator that can retry and then promptly forgot about it. I more recently saw Python decorator for retrying w/exponential backoff and wanted to add ...
Dan Oberlam's user avatar
  • 8,064
12 votes
2 answers
2k views

Memoizing decorator that can retry

I have some tasks that I'd like to memoize because they connect to a rather slow network and have to wait for the data. Unfortunately this network can be a little finnicky and we get occasional ...
Dan Oberlam's user avatar
  • 8,064
5 votes
2 answers
368 views

Comparison of Fibonacci (Multinacci) Functions in Python3

After coming up with a formula on this Stack Overflow question, defeating recursion limits and finding a few new ways of calculating these numbers (as per this Stack Overflow question), I decided that ...
mleyfman's user avatar
  • 5,190
2 votes
2 answers
1k views

Python memoization decorator

I have spent all night whipping up this recipe. It's my first Python decorator. I feel like I have a full understanding of how decorators work now and I think I came up with a good object-oriented ...
Tyler Crompton's user avatar