I mean, it shouldn't be too hard to come up with a regex term for "integer between 0 and 255", and modify it slightly for the first one because that shouldn't start with 0, I guess
well, maybe my picture of ipv4 IP addresses is what's off, dunno
@davidism too bad it doesn't handle the BunnyNetwork addresses
Question: i am trying to find out how to have distinct numbers, example: given 4, 6 ,6 ,6 how would i make it so i have 4,6,8,10?? given a random list of numbers?
I'm just not following the logic you are trying to do. However, if you are looking for a structure that doesn't allow duplicates, look at sets. But sets do not preserve order.
@Nightmare Are you saying the following: Given positive integer n, and given a list of integers [a_0, a_1, a_2, ..., a_k], find [a_0 + m_0*n, a_1 + m_1*n, a_2 + m_2*n, ..., a_k +m_k * n] such that all values are distinct and the sum of the list is minimized?
From wiki: "The opposite of lazy evaluation is eager evaluation, sometimes known as strict evaluation. Eager evaluation is the evaluation strategy employed in most programming languages."
seems pretty clear what they are asking, is a legitimate question, and if you are not comfortable with the language, can be hard to figure out at first.
Does anyone have experience with database structure for a client who wants a form that he can change the questions on, but all the past form submissions still contain their original questions (and question order)
What will be the ideal way to load the module and unload it? Compatible for both Python 2.x and 3.x. I want to load the module on demand basis as it uses too much memory
@MarcusS: Yes, kind of. But more elegant. But the link you forwarded is helpful though @AnttiHaapala: Like this`del sys.modules['module']`? Is there a way to make sure memory is released?
@AnttiHaapala I do not want to use the references anywhere else. It is been just used at one place for the internationalization of URLs and since most of the URLs do not need internationalization. I think dropping the module will work.
I'm wondering if I can get some insights into a Pickle module issue I'm having. I'm trying to save the state of a class {World}. And this class has a dict attribute called {Rooms}. Insight this dict attribute I have instantiated class objects. But when pickle.dump(...) gets to saving one of these dict items, it can't find it associated with the top-most {World} class, and I get the error: Can't pickle <class 'world.StartingRoom'>: attribute lookup StartingRoom on world failed
so, in this case, the reference to "StartingRoom" looks like this:
world._world = {(2, 1): <world.StartingRoom object at 0x1036a72b0>}
The dict key is important because it specifies the world location for this particular room. What other way could I instantiate "StartingRoom" so that I can still access it within the World class by it's x/y access coordinates (2,1)?
I don't know what you mean by "skip that pile." If the position is losing, it doesn't matter which pile you pick -- anything you do will give the opponent a winning position. Skipping one pile vs. another won't make any difference
Unless you mean like [1, 0, 1] and skips exist on both piles, and the player can use all the skips at once and force the entire position on the opponent
not sure I follow -- I think you have to clarify exactly what you mean / what a skip allows you to do exactly / how many each player has / if they both share skips or maintain their own set / etc
So there is one "skip" associated with each pile, that is shared between both players? If player 1 uses the first pile's skip, the second player no longer has the ability to "skip" the first pile at any point in the future?
I mean, the idea of skipping turns means the game is no longer a combinatorial game in the traditional sense (the whole reason the xor operator works for these games in the first place is because it assumes the players are taking turns, and that from any winning position there exists at least one move to a losing position, and from any losing position, all moves lead to winning positions)
i.e. it becomes another kind of DP / memo type probem
from itertools import product
def nim_with_skips(old_state, cache = {}):
key = tuple(old_state)
if all(pile_size == 0 for pile_size, skip in old_state): #final loss state
return False
if key in cache:
return cache[key]
for pile_index in range(len(old_state)):
pile_size, skip = old_state[pile_index]
new_state = old_state[:]
if skip > 0:
new_state[pile_index] = (pile_size, 0) #use the skip
do_we_win = (nim_with_skips(new_state) == False)
maybe something like this (to better see how skips vs non-skips influence the outcome)
@holdenweb There is one open source library on which I am contributing. One guy has opened a bug that whenever the newer version of library is imported it is consuming too much memory. He has 40 independent scripts, and each import is consuming around 15 MB. Due to 600 MB extra usage of memory, his system is getting crashed
@Nightmare JSUK there is a light bug in the code above (add a continue if the pile size is 0, or remove the pile + skip from the state if it's 0 if you want to re-use the memo from smaller subproblems)
FWIW, reduce(int.__xor__, piles) is a slightly better way to compute the Nim sum than the version on the Wikipedia page, since it avoids using a lambda.
If n = number of piles is even (i.e. n = 2k), skips won’t matter. Let’s say you’re in a losing position and you skip because pile 1 still has one available: I’ll just use pile 2’s skip. And then you on pile 3, me on pile 4, … , you on pile 2k-1, me on pile 2k. Now it’s back to your turn and it’s still a nim-sum = 0 scenario, so nothing changed.