Rust Katas

Caution I’m just learning Rust .. code = crap :D Lotto Generator Version 2 src/main.rs use rand::Rng; use std::fmt; fn main() { let lotto = Game { name: String::from("Lotto 6aus49"), take: 6, lower: 1, upper: 49, }; println!("Playing {lotto}"); lotto.print_result(); } struct Game { name: String, take: usize, lower: u32, upper: u32, } impl Game { fn print_result(&self){ let mut rng = rand::thread_rng(); let mut result:Vec<u32> = Vec::new(); while result.len() < self.take { let num = rng.gen_range(self.lower..self.upper); if !result.contains(&num) { result.push(num); } } result.sort(); println!("Result: {result:?}"); } } impl fmt::Display for Game { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{} ({} from {} to {}))", self.name, self.take, self.lower, self.upper) } } ...

March 1, 2018 · 1 min · 181 words · Micha Kops

Coding Katas with Maven

Searching for nice coding kata sites I found this one – codingkata.org – I really liked because of the quick start and nice maven integration. Just head over to the kata overview select the kata you wish to try out, copy the generated maven command line option and run it in the console – heres the code for the hello-world sample: Coding Katas from Maven Archetype mvn archetype:generate -DinteractiveMode=false -DarchetypeRepository=http://www.codingkata.org/repo/release -DarchetypeGroupId=org.codingkata.template -DarchetypeArtifactId=solv-java-archetype -DarchetypeVersion=1.04 -DgroupId=org.codingkata.unit -DartifactId=hello-world-solv-java -DkataId=hello-world -DkataVersion=1.02 -DlangVersion=1.6 -DlibVersion=1.3.2 -Dversion=1271358 ...

April 15, 2010 · 2 min · 236 words · Micha Kops

Rust Snippets

Installation Installing rustup first…​ install rustup via shell script curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh install rustup via brew brew install rustup-init (1) rustup-init (2) Welcome to Rust! [...] Current installation options: default host triple: aarch64-apple-darwin default toolchain: stable (default) profile: default modify PATH variable: yes 1) Proceed with standard installation (default - just press enter) 2) Customize installation 3) Cancel installation install rustup install rust binaries and add them to paths etc…​ ...

March 1, 2010 · 1 min · 109 words · Micha Kops