Halloween Sale

Sort by

recency

|

72 Discussions

|

  • + 0 comments

    public static int howManyGames(int p, int d, int m, int s) { int sum = 0; int c = 0;

         while (sum + p <= s) {
             sum += p;
             p = Math.max(p - d, m);
             c++;
        }
    return c; 
    }
    

    }

  • + 0 comments
    int howManyGames(int p, int d, int m, int s) {
        // Return the number of games you can buy
        vector <int> x;
        int sum=0;
        for(int i=p;sum<s;i-=d){
            if(i>=m){ 
                x.push_back(i);
            }else {
                x.push_back(m);
            }      
            sum=accumulate(x.begin(),x.end(),0);
        }
        if(sum>s){
            x.pop_back();
        }
        return x.size();
    }
    
  • + 0 comments

    Go pgm

    func howManyGames(p int32, d int32, m int32, s int32) int32 { var result int32 = 0 var sum int32 =0;

    for  {
            sum = sum +p
            if sum<=s{
                    result++
                    if p-d >=m{
                            p = p-d
                    }else{
                            p=m
                    }    
            }else{
                    break
            }
    }
    return result
    

    }

  • + 0 comments

    Go pgm

    func howManyGames(p int32, d int32, m int32, s int32) int32 { var result int32 = 0 var sum int32 =0;

    for  {
        sum = sum +p
        if sum<=s{
            result++
            if (p-d) >=m{
                p = p-d
            }else{
                p=m
            }    
        }else{
            break;
        }
    }
    return result
    

    }

  • + 0 comments

    static int howManyGames(int p, int d, int m, int s) { // Return the number of games you can buy

     // Return the number of games you can buy
          int numberOfGames = 0;
    
            int i = p;
            for ( i= p; i <= s; i += p)
            {
                numberOfGames++;
                // d = p <= m ? m : d;
    
                 p = p < m || (p - d) <=0 || (p-d)<m ? m : p - d;
    
            }
             return numberOfGames;
    
    }