Sort by

recency

|

261 Discussions

|

  • + 0 comments

    This reminds me of how restaurants optimize their menus for different times of the day, just like cutting bread into the perfect squares! Efficiently using resources without waste is key, whether it's bread or a digital menu system. Speaking of which, https://malaysiamenus.com/ does something similar for restaurants by letting them update their digital menus in real time—no wasted effort, just seamless updates!

  • + 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); } }