@anonymous/

EquatorialDeepSearch

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import functools

def memoize(func):
  cache = func.cache = {}
  
  @functools.wraps(func)
  def memoized_func(*args, **kwargs):
    key = str(args) + str(kwargs)
    if key not in cache:
      cache[key] = func(*args, **kwargs)
    return cache[key]
    
  return memoized_func


@memoize
def ev(mg, vt):
  play = mg + vt
  if (mg<=0): 
    return 1
  if (mg>=vt): 
    return 0
  if (mg == play/2 - 0.5): 
    return (mg/play * ev(mg-1, vt-1))

  return max(
    ev(mg, vt-1), 
    ((vt/play * (vt-1)/(play-1) * ev(mg, vt-3)) + 
    (2 * vt/play * mg/(play-1) * ev(mg-1, vt-2)) +
    (mg/play * (mg-1)/(play-1) * ev(mg-2, vt-1))
    ))

print(ev(int(input("Scum: ")), int(input("Town: "))))