If you decide to learn Rust using AoC 2018, I highly recommend comparing your work with that of BurntSushi, who is known to write high quality code. https://github.com/BurntSushi/advent-of-code You develop Rust skills by writing your own and then hone your skills by learning from idiomatic Rust.
Learning Rust via Advent of Code
51–60 of 85 posts
Re: Learning Rust via Advent of Code
#52I also thought regex seemed overkill and didn't feel like adding an extra crate to my Cargo.toml. Luckily for the days I attempted I was able to get by on just the split method for str's[0] which was nice and concise. So for your regex example you could also do: // #1 @ 916,616: 21x29 let parts: Vec = l.split(['@', ',', ':', 'x'].as_ref()).collect(); let x = parts[1].trim().parse:: ().expect("x as i32"); let y = part…
This is awesome. How did you figure this out? The documentation on `split` says: "The pattern can be a &str, char, or a closure that determines the split." But in your case it is an array of chars and it splits for each of them. I don't see this documented at all.
The operator for this is for eg l[1..10]. It can also happen automatically.
&str is the same type as &[char] - just a renaming.
Still learning Rust myself, apologies if this leads you astray. Just do some reading on slices.
https://doc.rust-lang.org/book/ch04-03-slices.html#string-sl...
Re: Learning Rust via Advent of Code
#53Earlier quoted context omitted.
This is awesome. How did you figure this out? The documentation on `split` says: "The pattern can be a &str, char, or a closure that determines the split." But in your case it is an array of chars and it splits for each of them. I don't see this documented at all.
Vec or an array for instance - [char; 20] can (automatically) create a "slice" of type &[char]. This is true for all types (not just char). The operator for this is for eg l[1..10]. It can also happen automatically. &str is the same type as &[char] - just a renaming. Still learning Rust myself, apologies if this leads you astray. Just do some reading on slices. https://doc.rust-lang.org/book/ch04-03-slices.html#strin…
Re: Learning Rust via Advent of Code
#54I also thought regex seemed overkill and didn't feel like adding an extra crate to my Cargo.toml. Luckily for the days I attempted I was able to get by on just the split method for str's[0] which was nice and concise. So for your regex example you could also do: // #1 @ 916,616: 21x29 let parts: Vec = l.split(['@', ',', ':', 'x'].as_ref()).collect(); let x = parts[1].trim().parse:: ().expect("x as i32"); let y = part…
This is awesome. How did you figure this out? The documentation on `split` says: "The pattern can be a &str, char, or a closure that determines the split." But in your case it is an array of chars and it splits for each of them. I don't see this documented at all.
It’s possible that it used to be only those types, but was expanded. We should fix this!
Re: Learning Rust via Advent of Code
#55Earlier quoted context omitted.
what kind of regrets do you have?
I haven't used Nim for anything else since then. If I had to give a simplified critique, the language in itself is still springing to life and the user base and documentation are small. I currently don't have the time to sink into something that could end up being a gimmick only, while there is some hardcore optimization needed in one of our services that could be approached through a better parallelization using Rus…
This kind of thing does really worry me though, it's almost like a self-fulfilling prophecy, you aren't going to use Nim because you think there isn't enough people using it :(
Do you have any ideas of how we can make you and people like you change their mind?
Re: Learning Rust via Advent of Code
#56> I feel like there should be a helper for simple parse operations. > parse!("#{} @ {},{}: {}x{}", id, x, y, w, h); > This would be a clean inverse of println!. The text_io crate does this exactly. https://crates.io/crates/text_io #[macro_use] extern crate text_io; fn main() { let id: u32; let x: u32; let y: u32; let w: u32; let h: u32; scan!("#{} @ {},{}: {}x{}", id, x, y, w, h); }
Re: Learning Rust via Advent of Code
#57> I feel like there should be a helper for simple parse operations. > parse!("#{} @ {},{}: {}x{}", id, x, y, w, h); > This would be a clean inverse of println!. The text_io crate does this exactly. https://crates.io/crates/text_io #[macro_use] extern crate text_io; fn main() { let id: u32; let x: u32; let y: u32; let w: u32; let h: u32; scan!("#{} @ {},{}: {}x{}", id, x, y, w, h); }
Re: Learning Rust via Advent of Code
#58I also thought regex seemed overkill and didn't feel like adding an extra crate to my Cargo.toml. Luckily for the days I attempted I was able to get by on just the split method for str's[0] which was nice and concise. So for your regex example you could also do: // #1 @ 916,616: 21x29 let parts: Vec = l.split(['@', ',', ':', 'x'].as_ref()).collect(); let x = parts[1].trim().parse:: ().expect("x as i32"); let y = part…
This is awesome. How did you figure this out? The documentation on `split` says: "The pattern can be a &str, char, or a closure that determines the split." But in your case it is an array of chars and it splits for each of them. I don't see this documented at all.
[0] https://doc.rust-lang.org/std/str/pattern/trait.Pattern.html...
Re: Learning Rust via Advent of Code
#59What is HN-users view of learning a programming language through this kind of problem-solving? Is it limiting? Should this be used as a complement to a larger toy project?