We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Loading...
  • Practice
  • Compete
  • Jobs
  • Leaderboard
  • Hiring developers?
  1. Practice
  2. Algorithms
  3. Implementation
  4. Chocolate Feast
  5. Discussions

Chocolate Feast

  • Problem
  • Submissions
  • Leaderboard
  • Discussions
  • Editorial
  • Topics

    You are viewing a single comment's thread. Return to all comments →

  • cesarjom 4 years ago+ 3 comments

    @pankaj113, You can simplify/reduce your code by moving this line

    int ex_chocs = wrapper / m; 
    

    inside while loop, like so:

    while(wrapper >= m) {
        int ex_chocs = wrapper / m;
        wrapper = ex_chocs + wrapper % m;
        chocs += ex_chocs;
    }
    System.out.println(chocs);
    
    10|
    ParentPermalink
    • pankaj113 4 years ago+ 0 comments

      @cesarjom Elegant and straight-forward. Thanks for sharing.

      0|
      ParentPermalink
    • avi_ganguly94 3 years ago+ 0 comments

      just th tweak i needed

      0|
      ParentPermalink
    • narayan_m 3 years ago+ 0 comments

      can be further simplified

      while(w>=m){
          chocs+=w/m;
          w=w/m+(w%m);
      }
      
      9|
      ParentPermalink
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature