Porting rosettacode.org Rust solutions to current Rust
Should we port the tasks that are already on rosettacode.org to current Rust? Some of them are in Rust 0.7 and I believe will need some adjusting to keep compiling. Others may not even be possible at all with the current status of closures (e.g. the Y combinator one ). I believe modifying them and holding them here would be a good way to make sure they stay up to speed with the language changes, instead of letting them slowly bitrot.
Below is a list of tasks that currently have a Rust solution. Some of them have already been recreated here too, but a good number of them aren't.
I think it would be also a nice task for people new to the language who want to try their hand at modifying something that is "almost working". What do you think?
- [x] 100 doors | http://rosettacode.org/wiki/100_doors#Rust
- [x] 99 Bottles of Beer | http://rosettacode.org/wiki/99_Bottles_of_Beer#Rust
- [x] A+B | http://rosettacode.org/wiki/A%2BB#Rust
- [x] Ackermann function | http://rosettacode.org/wiki/Ackermann_function#Rust
- [x] AKS test for primes | http://rosettacode.org/wiki/AKS_test_for_primes#Rust
- [x] Anagrams | http://rosettacode.org/wiki/Anagrams#Rust
- [x] Arithmetic/Complex | http://rosettacode.org/wiki/Arithmetic/Complex#Rust
- [x] Averages/Arithmetic mean | http://rosettacode.org/wiki/Averages/Arithmetic_mean#Rust
- [x] Binary digits | http://rosettacode.org/wiki/Binary_digits#Rust
- [x] Binary search | http://rosettacode.org/wiki/Binary_search#Rust
- [x] Bitmap/Write a PPM file | http://rosettacode.org/wiki/Bitmap/Write_a_PPM_file#Rust
- [x] Bitwise operations | http://rosettacode.org/wiki/Bitwise_operations#Rust
- [x] Bulls and cows | http://rosettacode.org/wiki/Bulls_and_cows#Rust
- [x] Check input device is a terminal | http://rosettacode.org/wiki/Check_input_device_is_a_terminal#Rust
- [x] Check output device is a terminal | http://rosettacode.org/wiki/Check_output_device_is_a_terminal#Rust
- [x] Closures/Value capture | http://rosettacode.org/wiki/Closures/Value_capture#Rust
- [x] Combinations | http://rosettacode.org/wiki/Combinations#Rust
- [x] Comma quibbling | http://rosettacode.org/wiki/Comma_quibbling#Rust
- [x] Command-line arguments | http://rosettacode.org/wiki/Command-line_arguments#Rust
- [x] Comments | http://rosettacode.org/wiki/Comments#Rust
- [x] Concurrent computing | http://rosettacode.org/wiki/Concurrent_computing#Rust
- [x] Count in octal | http://rosettacode.org/wiki/Count_in_octal#Rust
- [x] Deal cards for FreeCell | http://rosettacode.org/wiki/Deal_cards_for_FreeCell#Rust
- [x] Dining philosophers | http://rosettacode.org/wiki/Dining_philosophers#Rust
- [x] Empty program | http://rosettacode.org/wiki/Empty_program#Rust
- [x] Entropy | http://rosettacode.org/wiki/Entropy#Rust
- [x] Enumerations | http://rosettacode.org/wiki/Enumerations#Rust
- [x] Even or odd | http://rosettacode.org/wiki/Even_or_odd#Rust
- [x] Factorial | http://rosettacode.org/wiki/Factorial#Rust
- [x] Fibonacci n-step number sequences | http://rosettacode.org/wiki/Fibonacci_n-step_number_sequences#Rust
- [x] Fibonacci sequence | http://rosettacode.org/wiki/Fibonacci_sequence#Rust
- [x] File IO | http://rosettacode.org/wiki/File_IO#Rust
- [x] File size | http://rosettacode.org/wiki/File_size#Rust
- [x] Find limit of recursion | http://rosettacode.org/wiki/Find_limit_of_recursion#Rust
- [x] FizzBuzz | http://rosettacode.org/wiki/FizzBuzz#Rust
- [x] Gray code | http://rosettacode.org/wiki/Gray_code#Rust
- [x] Greatest common divisor | http://rosettacode.org/wiki/Greatest_common_divisor#Rust
- [x] Guess the number | http://rosettacode.org/wiki/Guess_the_number#Rust
- [x] Guess the number/With feedback | http://rosettacode.org/wiki/Guess_the_number/With_feedback#Rust
- [x] Guess the number/With feedback (player) | http://rosettacode.org/wiki/Guess_the_number/With_feedback_(player)#Rust
- [x] Hello world/Standard error | http://rosettacode.org/wiki/Hello_world/Standard_error#Rust
- [x] Hello world/Text | http://rosettacode.org/wiki/Hello_world/Text#Rust
- [x] Hello world/Web server | http://rosettacode.org/wiki/Hello_world/Web_server#Rust
- [x] Horner's rule for polynomial evaluation | http://rosettacode.org/wiki/Horner%27s_rule_for_polynomial_evaluation#Rust
- [x] Increment a numerical string | http://rosettacode.org/wiki/Increment_a_numerical_string#Rust
- [x] Infinity | http://rosettacode.org/wiki/Infinity#Rust
- [x] Integer sequence | http://rosettacode.org/wiki/Integer_sequence#Rust
- [x] Knapsack problem/0-1 | http://rosettacode.org/wiki/Knapsack_problem/0-1#Rust
- [x] Knuth shuffle | http://rosettacode.org/wiki/Knuth_shuffle#Rust
- [x] Letter frequency | http://rosettacode.org/wiki/Letter_frequency#Rust
- [x] Levenshtein distance | http://rosettacode.org/wiki/Levenshtein_distance#Rust
- [x] Look-and-say sequence | http://rosettacode.org/wiki/Look-and-say_sequence#Rust
- [x] Loop over multiple arrays simultaneously | http://rosettacode.org/wiki/Loop_over_multiple_arrays_simultaneously#Rust
- [x] Loops/Break | http://rosettacode.org/wiki/Loops/Break#Rust
- [x] Loops/Continue | http://rosettacode.org/wiki/Loops/Continue#Rust
- [x] Loops/Downward for | http://rosettacode.org/wiki/Loops/Downward_for#Rust
- [x] Loops/For with a specified step | http://rosettacode.org/wiki/Loops/For_with_a_specified_step#Rust
- [x] Loops/Infinite | http://rosettacode.org/wiki/Loops/Infinite#Rust
- [x] Loops/Nested | http://rosettacode.org/wiki/Loops/Nested#Rust
- [x] Luhn test of credit card numbers | http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers#Rust
- [x] Middle three digits | http://rosettacode.org/wiki/Middle_three_digits#Rust
- [x] Mouse position | http://rosettacode.org/wiki/Mouse_position#Rust
- [x] Mutual recursion | http://rosettacode.org/wiki/Mutual_recursion#Rust
- [x] N-queens problem | http://rosettacode.org/wiki/N-queens_problem#Rust
- [x] Ordered words | http://rosettacode.org/wiki/Ordered_words#Rust
- [x] Playing cards | http://rosettacode.org/wiki/Playing_cards#Rust
- [x] Program name | http://rosettacode.org/wiki/Program_name#Rust
- [x] Quine | http://rosettacode.org/wiki/Quine#Rust
- [x] Random numbers | http://rosettacode.org/wiki/Random_numbers#Rust
- [x] Read entire file | http://rosettacode.org/wiki/Read_entire_file#Rust
- [x] Reverse a string | http://rosettacode.org/wiki/Reverse_a_string#Rust
- [x] Roman numerals/Decode | http://rosettacode.org/wiki/Roman_numerals/Decode#Rust
- [x] Roman numerals/Encode | http://rosettacode.org/wiki/Roman_numerals/Encode#Rust
- [x] Rot-13 | http://rosettacode.org/wiki/Rot-13#Rust
- [ ] Scripted main | http://rosettacode.org/wiki/Scripted_main#Rust
- [x] Sieve of Eratosthenes | http://rosettacode.org/wiki/Sieve_of_Eratosthenes#Rust
- [x] Singly-linked list/Element definition | http://rosettacode.org/wiki/Singly-linked_list/Element_definition#Rust
- [x] Sort an integer array | http://rosettacode.org/wiki/Sort_an_integer_array#Rust
- [x] Sorting algorithms/Insertion sort | http://rosettacode.org/wiki/Sorting_algorithms/Insertion_sort#Rust
- [x] Sorting algorithms/Quicksort | http://rosettacode.org/wiki/Sorting_algorithms/Quicksort#Rust
- [x] Sorting algorithms/Sleep sort | http://rosettacode.org/wiki/Sorting_algorithms/Sleep_sort#Rust
- [x] String case | http://rosettacode.org/wiki/String_case#Rust
- [x] String concatenation | http://rosettacode.org/wiki/String_concatenation#Rust
- [x] Strip whitespace from a string/Top and tail | http://rosettacode.org/wiki/Strip_whitespace_from_a_string/Top_and_tail#Rust
- [x] Sum and product of an array | http://rosettacode.org/wiki/Sum_and_product_of_an_array#Rust
- [x] Sum of squares | http://rosettacode.org/wiki/Sum_of_squares#Rust
- [x] The Twelve Days of Christmas | http://rosettacode.org/wiki/The_Twelve_Days_of_Christmas#Rust
- [x] Towers of Hanoi | http://rosettacode.org/wiki/Towers_of_Hanoi#Rust
- [x] Unicode variable names | http://rosettacode.org/wiki/Unicode_variable_names#Rust
- [x] Unix/ls | http://rosettacode.org/wiki/Unix/ls#Rust
- [x] Vigenère cipher | http://rosettacode.org/wiki/Vigen%C3%A8re_cipher#Rust
- [x] Y combinator | http://rosettacode.org/wiki/Y_combinator#Rust
This is very nice! I think we should port the ones that we don't yet have!
Made a first pass at flagging the ones we already have. I may have missed some...
@pfalabella Thanks so much for putting this list together!
Empty Program is complete here.
I'm gonna whip up a Python script to try and automate this. I'll open up a pull request in the next couple of days for discussion on features.
@jschaf Would be awesome to do this with Rust.
I don't think the tools are quite there yet. Is there a request (a la python) library yet? Once the tools mature, I'm all for porting to rust.
On Wed, Sep 3, 2014 at 1:22 PM, Andrew Hobden [email protected] wrote:
@jschaf https://github.com/jschaf Would be awesome to do this with Rust.
— Reply to this email directly or view it on GitHub https://github.com/Hoverbear/rust-rosetta/issues/170#issuecomment-54332812 .
if the purpose of your proposed script is to download the Rust example codes from rosettacode, I agree that doing it in Rust would be challenging. The http request part should be doable with https://github.com/chris-morgan/rust-http but parsing the html, finding the Rust section, and stripping away the html tags (as I'm not aware of any direct way to download code from rosettacode.org) looks a bit harder....
I've taken a cursory look at the servo repository, but unless I'm mistaken they only have bindings to an external library to do the html parsing (https://github.com/servo/rust-hubbub)?
EDIT (TL;DR version): I would do it in Python too... :)
I have added Closures/Value capture, but it is by no means a port... It has nothing in common with the original
@jschaf There is a new http library which is actively developed and lets you make requests easily, it is called hyper (https://github.com/hyperium/hyper). The readme gives clear examples on how to use it.
Neat, I'll take a look.
On Mon, Oct 27, 2014 at 12:19 PM, Adolfo Ochagavía <[email protected]
wrote:
@jschaf https://github.com/jschaf There is a new http library which is actively developed and lets you make requests easily, it is called hyper ( https://github.com/hyperium/hyper). The readme gives clear examples on how to use it.
— Reply to this email directly or view it on GitHub https://github.com/Hoverbear/rust-rosetta/issues/170#issuecomment-60621130 .
I updated the Fibonacci n-step example, at http://rosettacode.org/wiki/Fibonacci_n-step_number_sequences#Rust before I knew about this repo. Feel free to copy from there.
- There are some solutions in the repo that aren't on rosettacode yet, right? Is there an automated way to check what solutions still need to be uploaded?
- Some solutions were ported for 0.13, we should make sure they work for 1.0. We should probably uncheck everything in the list to verify.
- I saw that there is still old code along with the new code for some problems (http://rosettacode.org/wiki/100_doors#Rust). That should probably be removed.
@gsingh93 thanks for raising these points. At this moment in time there is no synchronization with rosettacode.org in either way. If tasks get added or updated here on rust-rosetta, the new code does not get published on rosettacode.org. Likewise, if someone publishes a new Rust solution on rosettacode.org, there's no automated way of fetching it in this repository.
The list in this thread is only reflecting the problems that at the time were on rosettacode.org but not on this repo. The checks only mean that the checked task has been "ported" to a current version of rust in this repo, not that the tasks have then been updated also on rosettacode.org.
There were discussions (see above in this thread) about building some automated way to have that synchronization, but nothing has materialized so far. Without any automation and with the language and libraries still in this state of constant change, copying all code back and forth manually task by task would be grueling....
At one point, before 1.0 final, we should figure out our story at least to get the tasks that are on this repo published on rosettacode.org. It does not look trivial: I am not aware of the existence of rosettacode APIs that allow to do it directly, so probably it will require a bit of site-scraping, but I think it would be an interesting project. If anyone's up to it, I would be happy to contribute.
There is a RosettaCodeData repository which mirror's the website. Maybe it would be interesting to see if they scrape the site or use an API.
I started on a python library to automate the tasks, but I stalled out after starting a new job. The main code is at https://github.com/jschaf/rosetta-robot/blob/master/rosettarobot/robot.py. It can generate the right syntax for wikimedia, but I haven't added upload functionality.
I wanted the script to be able to automatically update rosetta-code and then be able to generate a static site served by Github of rust-rosetta code.
I updated nearly all the tasks that are on rosettacode to Rust 1.3.0-stable. I think I missed just two: http://rosettacode.org/wiki/Hello_world/Web_server and rosettacode.org/wiki/Scripted_main. I did not know about this repo, so stuff is out of sync right now. EDIT: oh some are Rust 1.5.0-nightly. Tried to keep it as stable as possible.
@potocpav Wow thank you! :)
I wanted to update this repo too, but I found that the solutions here are out of sync with rosettacode.org really bad. Like, they tend to be completely different. Is there a desire to sync them and keep them synced? How should that go about? I would be glad to help (or just do it :) ), but I don't quite know how. Any ideas? :)
I don't think there's an official API, so you have to use some screen scraping. I started with Python and the request libary. At a high level, it's something like:
- Get code from repo by using the URL comment string in each file
- Convert code into MediaWiki syntax. I used Jinja2 for that.
- Get rossettacode submission
- Check to see if it was put there earlier by our script, if so, overwrite it.
- If someone else updated it, we can either skip it or overwrite it.
Thorny issues:
- How do you handle library code? A link to the file in the github repo?
- What do we do if code already exists.
#410 is a way to move forward on this. Thanks for @euclio !
So scriptedmain redirects to http://rosettacode.org/wiki/Modulinos#Rust. That task has a caveat to prefer http://rosettacode.org/wiki/Executable_library. So we could probably close this.
Two other relevant points:
- https://github.com/acmeism/RosettaCodeData is a project to scrape Rosetta code.
- The creator of Rosetta code intends to modernize the wiki
Any future, serious work to synchronize Rust solutions should check in with them! I imagine a more modern way of managing the content could greatly simplify our tooling and improve contributor experience.