RosettaCodeData/Task/Old-lady-swallowed-a-fly/Rust/old-lady-swallowed-a-fly.rust
2018-06-22 20:57:24 +00:00

32 lines
1.3 KiB
Text

enum Action {Once, Every, Die}
use Action::*;
fn main() {
let animals = [ ("horse" , Die , "She's dead, of course!")
, ("donkey", Once , "It was rather wonky. To swallow a donkey.")
, ("cow" , Once , "I don't know how. To swallow a cow.")
, ("goat" , Once , "She just opened her throat. To swallow a goat.")
, ("pig" , Once , "Her mouth was so big. To swallow a pig.")
, ("dog" , Once , "What a hog. To swallow a dog.")
, ("cat" , Once , "Fancy that. To swallow a cat.")
, ("bird" , Once , "Quite absurd. To swallow a bird.")
, ("spider", Once , "That wriggled and jiggled and tickled inside her.")
, ("fly" , Every, "I don't know why she swallowed the fly.")
];
for (i, a) in animals.iter().enumerate().rev() {
println!("There was an old lady who swallowed a {}\n{}", a.0, a.2);
if let Die = a.1 {break}
for (swallowed, to_catch) in animals[i..].iter().zip(&animals[i+1..]) {
println!("She swallowed the {} to catch the {}.", swallowed.0, to_catch.0);
if let Every = to_catch.1 {
println!("{}", to_catch.2);
}
}
println!("Perhaps she'll die.\n");
}
}