This is a Google Hash Code 2020 solution (Rank 824 out of 10724): Problem statement.
git clone https://github.com/baurst/hc20
cd hc20
cargo run --release 0 1 2 3 4 5
Each digit represents a specific problem (check folder datasets):
- a_example.txt
- b_read_on.txt
- c_incuabula.txt
- d_tough_choices.txt
- e_so_many_books.txt
- f_libraries_of_the_world.txt
If you provide multiple digits, the problems will be solved in parallel. The tool will create a directory called out and save the solutions with their respective score.
Our original solution was done in Python. Python is great when you need to get things done quickly and don't want to be bothered about types. Plus, as long as you can express your problem in terms of matrices and matrix-operations (numpy), it's very fast. I reimplemented our solution to get a feeling about whether I could have done the competition in Rust, which offers a nicer development experience in my opinion. Rust has a steeper learning curve, but it is fast out of the box: Instead of having to focus on a solution that can be expressed using numpy matrix operations I can come up with any idea, implement it in the most intuitive way and the compiler will take care of the speed, which is liberating.
- with good preparation (stubs for data loading and writing...) coding competitions can absolutely be done in Rust
- unsurprisingly, coding in Python is still faster
- with Rust there is much less time spent debugging: at least for me, if the code compiles it's correct most of the time
- don't worry about optimizations, the compiler will take care of speed: focus on your actual solution