Sort by

recency

|

42 Discussions

|

  • + 0 comments

    from math import gcd

    def proba(n, k): count=0 dice1=range(1, n+1) dice2=range(1, n+1) for i in dice1: for j in dice2: if i + j <= k: count+=1 nbr_event = n*n

    pgcd=gcd(count, nbr_event)
    
    num=count//pgcd
    denum= nbr_event//pgcd
    
    return f"{num}/{denum}"
    

    proba(6, 9)

  • + 0 comments

    The expectations for this puzzle aren't really clear. For a standard pair of six-sided dice, the problem is simple enough that one can work out the math in one's head and hardcode the answer ("5/6" as @kongguibin pointed out). But in a real interview, would one be expected to implement the logic? And would one be expected to make the solution generalizable to m dice with n sides?

  • + 0 comments

    17/21

  • + 0 comments
    from fractions import Fraction
    
    max_num = 9
    count = 0
    total_combinations = 6**2
    dice = range(1, 7)
    
    for die_1 in dice:
        for die_2 in dice:
            dice_sum = die_1 + die_2
            if dice_sum <= max_num:
                count += 1
    
    print(str(Fraction(count, total_combinations)))
          
    
  • + 0 comments
    most9 = 0
    total_rolls = 0
    
    for p in range(1,6+1):
        for q in range(1,6+1):
            if (p+q) <= 9:
                most9 += 1
            total_rolls += 1
    
    
    
    print(str((most9//6))+"/"+str((total_rolls//6)))