Sort by

recency

|

260 Discussions

|

  • + 0 comments

    I haven't seen my approach in the comments yet and figured it may help out anyone else trying to wrap their head around it.

    Alternative to the GCD approach (well documented below), I mentally wanted to find the largest square that was divisible by both l and b. It's not the most efficient, but it's how I saw the solution:

    Python3

    def restaurant(l, b):
        squares = [x**2 for x in range(1, 1001)]
        mult = l*b
        final_squares = mult
    
        l_divisors = [i for i in range(1, l + 1) if l % i == 0]
        b_divisors = [i for i in range(1, b + 1) if b % i == 0]
    
        if l == b:
            final_squares = 1
        else:
            mult_divisors = [i for i in range(1, mult + 1) if mult % i == 0]
    
            for mult_div in mult_divisors:
                if mult_div in squares:
                    if (mult_div**(1/2) in l_divisors) and (mult_div**(1/2) in b_divisors):
                        final_squares = mult / mult_div
    
        return int(final_squares)
    
  • + 0 comments

    def restaurant(l, b):

    N_min = min(l,b)
    for i in range(N_min,0,-1):
         if l%i + b%i == 0:
            return( (l*b)//(i**2) )
            break
    return l*b
    
  • + 0 comments
    int div = 1;
        int ans = 1;
            if(l==b){
                return ans;
            }else {              
                for(int i= 1 ; i<=l;i++ ){
                     if((l%i==0) && (b%i==0)){
                         div = i;                     
                     }
                }
               ans = (l*b)/(div*div);
            }
             return ans;
    
  • + 0 comments

    Can Someone Find the Error in my Function

    int restaurant(int l, int b) { if(0 == b % l ) { return b/l; } else { float frac = (float)b / (float)l ; int i = 1; while( (frac != (int)(frac)) ) { frac +=(float)b / (float)l; i++; } return (int)(i)*(int)(frac); } }

  • + 0 comments
    python3
    
    def divisor(n):
        div = []
        for i in range(1,n+1):
            if i == 1 or i == n:
                div.append(i)
            else:
                if n % i == 0:
                    div.append(i)
        
        return div
        
    def restaurant(l,b):
        # Write your code here
        divl = divisor(l)
        divb = divisor(b)
        common = []
        for i in divl:
            if i in divb:
                common.append(i)
                
        maximum = max(common)
        total = int((l/maximum)*(b/maximum))
        return total