Coder Social home page Coder Social logo

brenomfviana / vjudge-rust Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 611 KB

Rust solutions for CodeChef and UVa problems.

License: MIT License

Rust 100.00%
rust rust-solution vjudge usp uva-solutions rust-solutions vjudge-rust codechef codechef-solutions

vjudge-rust's Introduction

VJudge Rust

Description

This repository contains Rust solutions of some CodeChef and UVa problems. These problems were homeworks for the Algorithms Project course of University of São Paulo (USP).

When I code these solutions there was no option to send Rust code to VJudge (the official code judge of our class) or another code judging system (Are we judged yet?). I also did not find any Rust solution for these problems. I solved the course homeworks by using C++, however I wanted to improve my Rust skills and develop Rust solutions could be not trivial (and were not) for some problems. Therefore, I decided to recode these homeworks by using Rust to learn the Rust way to solve problems. I have made a lot of code refactoring as you can see on the commits list. My first implementations did not have a clean code and there were a lot of improvements to make. I just did these improvements after the end of my course and I maybe do improve a little more sometime later.

Some observations

  • Rust code, in some situations, can be very verbose due the use of Option, Result and HashMap;
  • Rust code can be very clean, we can do a lot of things with little code;
  • Reverse sort could be simpler (something like rev_sort()) not all of this: sort_by_key(|&num| Reverse(num))
  • C++ HashMap is very different of Rust HashMap. The first one is really flexible, but can lead to unpredictable behaviors because an element can be created just by calling for a not added key (hmap[i]). Rust HashMap is more strict because the borrowing rules.

Some things that I missed

  • Tuple assignment for already defined variables, something like:
    let (mut a, mut b) = (0, 0);
    (a, b) = (4, 2);
    
    Maybe there is a reason for Rust do not allow this, but it would make the code cleaner.
  • The do...while syntax sugar. I prefer use this:
    do {
      a += 1;
    } while a > b;
    
    Instead of this:
    loop {
      a += 1;
      if a > b { break }
    }
    
    Maybe we also could have a do...while let, but I cannot think in an example of usage of this.
  • A function to read char by char from an input (read_char(&mut char)):
    let mut input = char::new();
    io::stdin().read_char(&mut input);
    
    Use this function is better to use for some problems, like the last one of this repository.

List of Problems

Problem Online Judge Code
00-stable-marriage-problem CodeChef STABLEMP
01-coin-collector UVa 11264
02-scarecrow UVa 12405
03-match-making-problem UVa 12210
04-backt-to-the-8-queens UVa 11085
05-sum-it-up UVa 574
06-rat-in-a-maze CodeChef MM1803
07-knuths-permutation UVa 10063
08-9puzzle UVa 11513
09-15puzzle UVa 10181
10-inversions -- --
11-solve-it UVa 10341
12-problemk UVa 11935
13-winterim-backpacking-trip UVa 907
14-luggage UVa 10664
15-supersale UVa 10130
16-is-bigger-smarter UVa 10131
17-let-me-count-the-ways UVa 357
18-rare-order UVa 200
19-counting-stars UVa 11244
20-bicoloring UVa 10004
21-maze-traversal UVa 10377
22-racing UVa 1234
23-sending-email UVa 10986
24-wormholes UVa 558
25-page-hopping UVa 821
26-sabotage UVa 10480
27-factors-and-factorials UVa 160
28-ocean-deep-make-it-shallow UVa 10176

License

This project is licensed under the MIT License - see the LICENSE file for details.

vjudge-rust's People

Contributors

brenomfviana avatar

Stargazers

 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.