Git Product home page Git Product logo

hashcode-practice-one-pizza's Introduction

Google Hash Code 2022 practice problem solution: One Pizza

Algorithm description:

Hill-climbing algorithm

  • Empty initialization.
  • Update state if new state equals or better in score,
  • Random steps.

Details

  1. Initialize solution - no ingredients.
  2. Select a random client which does not want the current pizza.
  3. Add missing ingredients the random client like.
  4. Remove existing ingredients the random client dislike.
  5. If the new ingredients score is equal or higher than the existing - update the current pizza ingredients.
  6. Goto 2.

Notes

  • Tried greedy init. Did not improve the solution.
  • When calculating the score with the new ingredients - perform a delta calculation which is faster.
  • The commited code is hill-climb, constant seed random, stop condition: no improvment found in the last 1M iterations.

Scores

Tested the algorithm in 2 modes:

  • 1M Iterations - Stop condition: no improvment found in the last 1M iterations. The algorithm takes about 10 minutes to run with the constant seed random in the code.
  • Max - continue hill-climbing without limit. The best solution for E was found after ~8 hours. Time based random seed.
Input 1M Iterations Max
A - An Example 2 =
B - Basic 5 =
C - Coarse 5 =
D - Difficult 1,805 =
E - Elaborate 2,078 2,083
Total 3,895 3,900

hashcode-practice-one-pizza's People

Contributors

sagishporer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.