top of page
Writer's pictureRichie Sawant

Jane Street Jan2021 Puzzle Solution

Wrote a code to get the right solution for the last month's Jane Street Puzzle using Python Monte Carlo simulation to get the right answer using 10000000 iterations. We get the solution exact solution 6.859787 as expected in their solution.



from random import randint 

# Function to calculate Sum of the first N elements of 
# the table

def suml(list, size):
   if (size == 0):
     return 0
   else:
     return (list[size - 1] + suml(list, size - 1))

# The Final Average value initiated at start

val = 0

# Loop to perform the Monte Carlo simulation to calculate
# the max value of any type of the the figurine

for n in range(1000000):
    # initial conditions of a Monte Carlo Simulation
    # Initial figurines 
    figurines = 78
    
    # Initial different type of figurines
    a = [12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2]
    
    # Count of Alex's figurines 
    count = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

    # Every act of picking up a figurine from the bag
    
    for i in range(figurines):
        # Create a RandomINT from 1 to no of figurines
        # Left in the bag
        
        x = randint(1, figurines)
        
        # End the experiment if we get 1
        
        if x == 1:
           
            break
        
        elif x > 1 and x <= 1 + suml(a, 1) and a[0] > 0:
            
            count[0] += 1            
            
            a[0] -= 1
        
        
        elif x > suml(a, 1) and x <= 1 + suml(a, 2) and a[1] > 0:
            
            count[1] += 1
            
            a[1] -= 1
            
        
        elif x > suml(a, 2)  and x <= 1 + suml(a, 3) and a[2] > 0:
            
            count[2] += 1
            
            a[2] -= 1
        
        
        elif x > suml(a, 3)and x <= 1 + suml(a, 4) and a[3] > 0:
            
            count[3] += 1
            
            a[3] -= 1
        
        elif x > suml(a, 4)and x <= suml(a, 5) and a[4] > 0:
            
            count[4] += 1
            
            a[4] -= 1
        
        elif x > suml(a, 5)and x <= 1 + suml(a, 6) and a[5] > 0:
            
            count[5] += 1
            
            a[5] -= 1
        
        elif x > suml(a, 6)and x <= 1 + suml(a, 7) and a[6] > 0:
            
            count[6] += 1
            
            a[6] -= 1
        
        elif x > suml(a, 7)and x <= 1 + suml(a, 8) and a[7] > 0:
            
            count[7] += 1
            
            a[7] -= 1
        
        elif x > suml(a, 8)and x <= 1 + suml(a, 9) and a[8] > 0:
            
            count[8] += 1
            
            a[8] -= 1
        
        elif x > suml(a, 9)and x <= 1 + suml(a, 10) and a[9] > 0:
            
            count[9] += 1
            
            a[9] -= 1
        
        
        elif x > suml(a, 10)and x <= 1 + suml(a, 11) and a[10] > 0:
            
            count[10] += 1
            
            a[10] -= 1
        
        figurines -= 1
        
    val = (val*(n) + max(count))/(n+1)
    
print(val)    
6.859786599999991 (Not Close)

Thank You!

28 views0 comments

Comments


Post: Blog2_Post
bottom of page