nikitaeverywhere / google-hash-code-2017-task

The qualification task for Google Hash Code 2017

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Google Hash Code 2017 Pizza Task

This is the solution for Google Hash Code 2017 practice task. The PDF with problem statement: /pizza.pdf.

Average results of this solution:

  • 871136/1000000 on big data set
  • 47997/50000 on medium data set
  • 41/42 on small data set

Total average score is 919174. The algorithm has randomization factor, so running it multiple times may yield even better results.

Algorithm

The algorithm to solve this task is following:

  1. Find all possible variants for each cell of the pizza. This will form 3-dimensional array [x][y][variant] with each value of available slice to cut [x, y, width, height].
  2. Starting from the random cell in pizza (preferably picked up from ones which have the minimum variants available), find the slice of all available slices for this cell which has the minimum weight. In short, the weight function calculates the number, which reflects the importance of the slice we are going to cut out. The most important slices are those ones which leave less available variants around the slice than others after being cut. The more slice is important, the bigger weight it has.
  3. Once the slice is cut, remove all its variants from variants array (this will also remove some of the variants from adjacent cells).
  4. Continue cutting slices until all the variants are processed.

How to Run

You need Git and NodeJS v6+ installed to be in. After cloning the project with the next commands:

git clone https://github.com/ZitRos/google-hash-code-2017-task.git
cd google-hash-code-2017-task

Execute the Node program on input files with the following command:

node index input/small.in

The last command-line parameter is the file name to process. The output will go to the output directory.

Example

Running slicer on the medium dataset.

Parsing input/medium.in file...
Data read and parsed in 99ms
100%
Layers computed in 1947ms
Maximum number of layers: 182, min variant pieces (except 0): 1
Output html file saved in 107ms
100%
Solution found in 14651ms
Solution score: 48077/50000

The results may vary each time as algorithm features randomization.

About

The qualification task for Google Hash Code 2017


Languages

Language:JavaScript 100.0%