Code Monkey home page Code Monkey logo

sqlite3-hashcode-2018's Introduction

sqlite3-hashcode-2018

If all you have is a hammer, maybe this looks like a nail !

An attempt to somehow solve the GOOGLE HASHCODE 2018 with sqlite3, it does give a simple solution to the problem.

Basically it sorts the booked rides by the "the earliest start", uses a table to store the current car's booked ride info then for each booked_ride choose the car that has/will finish a previous ride closest to the start of the current assigning ride if no car can arrive at least on the ("the latest finish" - the_ride_size) we ignore it.

It outputs in the format required by the hashcode 2018 rules, to a file named 'results.txt'.

This solution uses triggers on dummy views to emulate stored procedures, and only requires a recent sqlite3 executable and data files to work on.

By no means I claim that solutions like this (stretching sqlite3) are good practice. Take it as an example that demonstrates several capabilities of sqlite3 in a hack/compact way.

It works with a memory database unless you supply a database name when invoking it:

sqlite3 < hashcode2018.sql

With a disk database:

sqlite3 database_name.db < hashcode2018.sql

To process a specific data file look bellow after the creation of the table "booked_rides_tmp" for a line like:

.import 'a_example.in' booked_rides_tmp

and edit it.

Author: Domingo Alvarez Duarte mingodad :at: gmail.com

License: Public domain as in sqlite3

Time spent till now: 48 hours (and several dream hours) the time above includes a prototype using a scripting language SquiLu (https://github.com/mingodad/squilu) around 38 hours including a simple plot program to show the rides for a car step by step.

The scores (on Atom @1.66GHZ):

data file score time spent
a_example.in 8 0m0.202s
b_should_be_easy.in 176,877 0m0.301s
c_no_hurry.in 13,089,884 0m6.177s
d_metropolis.in 10,990,382 0m17.973s
e_high_bonus.in 21,465,945 0m23.155s
Total 45,723,096

New: The calc-rides.nut have an option to try reduce the number of required cars, with b_should_be_easy.in it can achieve the same score with only 24 cars, with e_high_bonus.in it achieve the same score with 174 cars, the others could not work with less cars.

Added a C++ port of the java solution from https://github.com/GameXtra/Google-Hash-Code-2018, it achieves a score above 49,000,000

sqlite3-hashcode-2018's People

Contributors

mingodad avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  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.