Old lady swallowed a fly: Difference between revisions
Content added Content deleted
(added alternate solution) |
(→{{header|Rust}}: Added Rust) |
||
Line 1,818: | Line 1,818: | ||
print "Perhaps she'll die.\n\n" |
print "Perhaps she'll die.\n\n" |
||
end</lang> |
end</lang> |
||
=={{header|Rust}}== |
|||
<lang rust>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"); |
|||
} |
|||
}</lang> |
|||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
<lang Scala>case class Verse(animal: String, remark: String, die: Boolean = false, always: Boolean = false) |
<lang Scala>case class Verse(animal: String, remark: String, die: Boolean = false, always: Boolean = false) |