News for hackers. Stuff that matters.
Re:Computer Scientists Invent an Efficient New Way to Count by josephernest on Friday May 17, 2024 @10:03AM (#40390029)
> adding words but now flipping a coin immediately after adding it

Edit: I thought your formulation was correct but not really:

We flip the coin after adding, but we also flip the coin even if we didn't add the word (because it was already there). This is subtle!

wrong:

    if k not in mem:
        mem += [k]
        if np.random.rand() > p:
            mem.remove(k)
wrong:

    if k not in mem:
        mem += [k]
    else:
        if np.random.rand() > p:
            mem.remove(k)
correct:

    if k not in mem:
        mem += [k]
    if k in mem:      # not the same than "else" here
        if np.random.rand() > p:
            mem.remove(k)
correct:

    if k not in mem:
        mem += [k]
    if np.random.rand() > p:
        mem.remove(k)
Re:Computer Scientists Invent an Efficient New Way to Count by Alexanfa on Friday May 17, 2024 @10:21AM (#40390260)
Ah, I'm using a set instead of list so I just always add and then toss remove.
Re:Computer Scientists Invent an Efficient New Way to Count by kuldeepmeel on Saturday May 18, 2024 @03:46AM (#40397175)
The following is also not correct.

    if k not in mem:
        mem += [k]
    if k in mem:      # not the same than "else" here
        if np.random.rand() > p:
            mem.remove(k)
Your final solution is indeed correct, and I think more elegant than what we had in our paper [I am one of the authors].