aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKang-min Liu <gugod@gugod.org>2021-01-19 23:54:56 +0900
committerKang-min Liu <gugod@gugod.org>2021-01-19 23:54:56 +0900
commit770c854468fbad1c785769367d1c5142981cc81b (patch)
tree44ba9cb8cbaec28b829104e20ca8ca3942593d64
parent36b1f754eb8d9d230e6c1577dc9063a46f914cd0 (diff)
downloadperlweeklychallenge-club-770c854468fbad1c785769367d1c5142981cc81b.tar.gz
perlweeklychallenge-club-770c854468fbad1c785769367d1c5142981cc81b.tar.bz2
perlweeklychallenge-club-770c854468fbad1c785769367d1c5142981cc81b.zip
a solution to pwc 096.1 in rust
-rw-r--r--challenge-096/gugod/rust/.gitignore2
-rw-r--r--challenge-096/gugod/rust/Makefile10
-rw-r--r--challenge-096/gugod/rust/ch-1.rs19
3 files changed, 31 insertions, 0 deletions
diff --git a/challenge-096/gugod/rust/.gitignore b/challenge-096/gugod/rust/.gitignore
new file mode 100644
index 0000000000..ac77297bfe
--- /dev/null
+++ b/challenge-096/gugod/rust/.gitignore
@@ -0,0 +1,2 @@
+ch-1
+ch-2
diff --git a/challenge-096/gugod/rust/Makefile b/challenge-096/gugod/rust/Makefile
new file mode 100644
index 0000000000..efa7c49e4e
--- /dev/null
+++ b/challenge-096/gugod/rust/Makefile
@@ -0,0 +1,10 @@
+all: ch-1 ch-2
+
+clean:
+ rm ch-1 ch-2
+
+ch-1: ch-1.rs
+ rustc $<
+
+ch-2: ch-2.rs
+ rustc $<
diff --git a/challenge-096/gugod/rust/ch-1.rs b/challenge-096/gugod/rust/ch-1.rs
new file mode 100644
index 0000000000..b32e0b0654
--- /dev/null
+++ b/challenge-096/gugod/rust/ch-1.rs
@@ -0,0 +1,19 @@
+
+fn reverse_words(x: String) -> String {
+ return x.split_whitespace().rev()
+ .collect::<Vec<&str>>()
+ .join(" ");
+}
+
+fn main() {
+ let examples: [&str; 3] = [
+ "The Weekly Challenge",
+ " Perl and Raku are part of the same family ",
+ "join reverse split $S"
+ ];
+
+ for x in examples.iter() {
+ println!("Input: {}", x);
+ println!("Output: {}", reverse_words(x.to_string()));
+ }
+}