From 82c81afaed52a85e33c67c6e78f1cc63bb23f2bd Mon Sep 17 00:00:00 2001 From: Jadi Date: Wed, 2 Aug 2023 12:43:58 +0330 Subject: [PATCH] Adding 20_Buzzword in Rust --- 20_Buzzword/rust/Cargo.toml | 9 +++ 20_Buzzword/rust/README.md | 3 + 20_Buzzword/rust/src/main.rs | 112 +++++++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 20_Buzzword/rust/Cargo.toml create mode 100644 20_Buzzword/rust/README.md create mode 100644 20_Buzzword/rust/src/main.rs diff --git a/20_Buzzword/rust/Cargo.toml b/20_Buzzword/rust/Cargo.toml new file mode 100644 index 00000000..3b1d02f5 --- /dev/null +++ b/20_Buzzword/rust/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "rust" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +rand = "0.8.5" diff --git a/20_Buzzword/rust/README.md b/20_Buzzword/rust/README.md new file mode 100644 index 00000000..fc6468b9 --- /dev/null +++ b/20_Buzzword/rust/README.md @@ -0,0 +1,3 @@ +Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html) + +Conversion to [Rust](https://www.rust-lang.org/) diff --git a/20_Buzzword/rust/src/main.rs b/20_Buzzword/rust/src/main.rs new file mode 100644 index 00000000..dae4b819 --- /dev/null +++ b/20_Buzzword/rust/src/main.rs @@ -0,0 +1,112 @@ +use rand::seq::SliceRandom; +use std::io::{self, Write}; + +fn main() { + let words = vec![ + vec![ + "Ability", + "Basal", + "Behavioral", + "Child-centered", + "Differentiated", + "Discovery", + "Flexible", + "Heterogeneous", + "Homogenous", + "Manipulative", + "Modular", + "Tavistock", + "Individualized", + ], + vec![ + "learning", + "evaluative", + "objective", + "cognitive", + "enrichment", + "scheduling", + "humanistic", + "integrated", + "non-graded", + "training", + "vertical age", + "motivational", + "creative", + ], + vec![ + "grouping", + "modification", + "accountability", + "process", + "core curriculum", + "algorithm", + "performance", + "reinforcement", + "open classroom", + "resource", + "structure", + "facility", + "environment", + ], + ]; + + // intro text + println!("\n Buzzword Generator"); + println!("Creative Computing Morristown, New Jersey"); + println!("\n\n"); + println!("This program prints highly acceptable phrases in"); + println!("'educator-speak' that you can work into reports"); + println!("and speeches. Whenever a question mark is printed,"); + println!("type a 'Y' for another phrase or 'N' to quit."); + println!("\n\nHere's the first phrase:"); + + let mut continue_running: bool = true; + + while continue_running { + let mut first_word: bool = true; + for section in &words { + if !first_word { + print!(" "); + } + first_word = false; + print!("{}", section.choose(&mut rand::thread_rng()).unwrap()); + } + print!("\n\n? "); + io::stdout().flush().unwrap(); + + let mut cont_question: String = String::new(); + io::stdin() + .read_line(&mut cont_question) + .expect("Failed to read the line"); + if !cont_question.to_uppercase().starts_with("Y") { + continue_running = false; + } + } + println!("Come back when you need help with another report!\n"); + +} + + +///////////////////////////////////////////////////////////////////////// +// +// Porting Notes +// +// The original program stored all 39 words in one array, then +// built the buzzword phrases by randomly sampling from each of the +// three regions of the array (1-13, 14-26, and 27-39). +// +// Here, we're storing the words for each section in separate +// tuples. That makes it easy to just loop through the sections +// to stitch the phrase together, and it easily accommodates adding +// (or removing) elements from any section. They don't all need to +// be the same length. +// +// The author of this program (and founder of Creative Computing +// magazine) first started working at DEC--Digital Equipment +// Corporation--as a consultant helping the company market its +// computers as educational products. He later was editor of a DEC +// newsletter named "EDU" that focused on using computers in an +// educational setting. No surprise, then, that the buzzwords in +// this program were targeted towards educators! +// +/////////////////////////////////////////////////////////////////////////