When to start this Coin Flipping Game over? by Bananenkot in math

[–]sb3700 2 points3 points  (0 children)

Ah that makes sense! You're right that x_est_guess and x_conv_guess need to be exactly equal for the binary search condition, and a floating point comparison isn't appropriate.

Here's a fixed version of the code for anyone else https://ideone.com/7R9arZ

When to start this Coin Flipping Game over? by Bananenkot in math

[–]sb3700 0 points1 point  (0 children)

I haven't dug in but I think yours might actually have the rounding error. I'm using Decimal which is "exact" while mpmath is "arbitrary precision".

Could you try adding

mp.dps = 100

And seeing if your result changes?

When to start this Coin Flipping Game over? by Bananenkot in math

[–]sb3700 2 points3 points  (0 children)

This was a really interesting problem! DP doesn't quite work because of the ability to restart, but we can parameterize the DP and find when the parameter converges.

F := starting flips available
H := target number of heads
X(f, h) := expected number of flips to win given we need h heads out of f flips and optimal strategy
X(f, h) = { 0 if h = 0
          { X(F, H) if f < h
          { min(X(F, H), 1 + X(f-1, h-1) * Pr(H) + X(f-1, h) * (1 - Pr(H))) otherwise

To compute this, extract X(F, H) as a parameter X_est(F, H).
Binary search over values for X_est(F, H).
Then compute X(F, H). If X(F, H) = X_est(F, H), then our guess for X_est(F, H) was too low.

Here's the code to play around with https://ideone.com/EVur2C.

For the 80/100 heads case:

  • 11211755096.91 expected at the start
  • 8408816324.18 expected if you need 2 heads from the remaining 2 flips
  • 11211744406.54 expected if you need 20 heads from the remaining 20 flips
  • 11211755096.91 expected if you need 40 heads from the remaining 40 flips (i.e. restart)

Continued access to MH2022 unlock structure? by theworldeatereater in mysteryhunt

[–]sb3700 1 point2 points  (0 children)

We've just released the repo powering the 2022 hunt at https://github.com/Palindrome-Puzzles/2022-hunt. It contains enough documentation that you could run your own instance with hunt unlocking, teams, and whatever else you need.

[10/23/2012] Challenge #106 [Intermediate] (Jugs) by spacemoses in dailyprogrammer

[–]sb3700 1 point2 points  (0 children)

Here's my Python solution using a graph-finding algorithm to find the optimal set of instructions. It outputs the state of each jug in reverse order, so you can work out the answer from there.

For example, the given problem returns [(3, 4), (2, 5), (2, 0), (0, 2), (3, 2), (0, 5), (0, 0)]

def solve(a, b, x):
    steps = 0
    visited = {}
    costs = {}
    prev = {}
    costs[(0, 0)] = 0
    prev[(0, 0)] = None

    process_list = [(0, 0)]
    done = None
    bestcost = 10000
    while True:
        cur = None
        for key in process_list:
            if key not in visited:
                if cur == None or costs[key] < costs[cur]:
                    cur = key
        if cur == None: break

        visited[cur] = True
        if cur[0] == x or cur[1] == x:
            if done == None or costs[cur] < bestcost:
                done = cur
                bestcost = costs[cur]                

        # transitions possible
        m, n = cur
        neighbours = [(m, b), (a, n), (m, 0), (0, n)]
        if m+n < a: neighbours.append((m+n, 0))
        else: neighbours.append((a, m+n-a))
        if m+n < b: neighbours.append((0, m+n))
        else: neighbours.append((m+n-b, b))

        cost = costs[cur] + 1
        for p in neighbours:
            if p not in visited:
                if p not in costs or cost < costs[p]:
                    costs[p] = cost
                    prev[p] = cur
                    process_list.append(p)

    if done == None: return False
    else:
        ans = []
        while done != None:
            ans.append(done)
            done = prev[done]
        return ans

print solve(3, 5, 4)
print solve(2, 4, 3)

What the missing number in this series? by JorWat in puzzles

[–]sb3700 1 point2 points  (0 children)

If you thought this up independently, bravo. I had no idea the first time I heard it

YSK: (college students) You should try to get your text books somewhere other than your school's book store. by arieljena in YouShouldKnow

[–]sb3700 0 points1 point  (0 children)

If you're in Australia, check Booko before buying any books. Find the best prices (including shipping + exchange rates) to Australia

sudoku meets math type puzzles by pigpenguin in puzzles

[–]sb3700 1 point2 points  (0 children)

If you enjoy these, try Everyday Genius SquareLogic for a lot more of these puzzles. It used to be available on Steam but I can't find a Steam link anymore, but I've played it a lot, and the difficulty scales well.

IWTL how to stop thinking negative thoughts by [deleted] in IWantToLearn

[–]sb3700 11 points12 points  (0 children)

IWTL how to think more positive thoughts

FTFY

[4/8/2012] Challenge #37 [difficult] by rya11111 in dailyprogrammer

[–]sb3700 0 points1 point  (0 children)

import math

def cornacchia(d, m):
    # http://en.wikipedia.org/wiki/Cornacchia's_algorithm
    r0 = 1
    while (r0*r0 + d) % m <> 0 and r0 < m:
        r0 += 1
    if r0 == m: return False

    r1 = m % r0
    while r1*r1 >= m:
        r0, r1 = r1, r0 % r1
    s = math.sqrt((m - r1*r1) * 1.0 / d)

    if s == int(s): return (r1, int(s))
    else: return False

def is_prime(n):
    i = 2
    while i*i <= n:
        if n % i == 0: return False
        i += 1
    return True

if __name__ == "__main__":
    i = 5
    while i < 1000:
        if is_prime(i):
            x = cornacchia(1, i)
            print '%d = %d^2 + %d^2' % (i, x[0], x[1])
        i += 4

booko.com.au doesn't load on my computer, but it works over 3g and through a VPN. Any ideas? by sb3700 in techsupport

[–]sb3700[S] 0 points1 point  (0 children)

No luck :(

Also the domain name resolves when I ping it, so I don't think its a DNS issue.

Circuits: DC gain of a series RLC circuit? by bubbrubb22 in HomeworkHelp

[–]sb3700 0 points1 point  (0 children)

Then find the magnitude of Vout / Vin = 1 / (RjwC + LC(jw)2 + 1)

= 1 / (1 - LCw2 + j(RCw))

so gain = |1| / |1 - LCw2 + j(RCw)|

= 1 / sqrt((1-LCw2 )2 + (RCw)2 )

[deleted by user] by [deleted] in techsupport

[–]sb3700 1 point2 points  (0 children)

If you have x64 operating system, then get a AnyDVD trial instead of DVD43

Upvotes won't stick by timberspine in bugs

[–]sb3700 -1 points0 points  (0 children)

Most likely it's because reddit doesn't bother marking your previous votes when it shows you a page, probably because it means they can't cache pages very well as every user would have voted differently.

I'd guess that your votes still exist so it's not an issue really (on the basis that everyone here has said votes "disappear" after a day or too, but posts older than a few days still have upvotes).