Fun With BASIC
Overthinking It™ love it when a program comes together.
Because I’m a nerd, I re-wrote the program in Ruby. I know. I know.
print "Do you have a problem? (y/n): "
if gets.chomp == "y"
print "Can anyone else help? (y/n): "
if gets.chomp == ‘n’
print "Can you find them? (y/n): "
if gets.chomp == ‘y’
puts "Maybe you can hire… the A-Team!"
exit
end
end
end
puts "You Cannot Hire the A-Team."
exit
Comments (5)
Lee
December 14th, 2008 | 5:44 pm
Wow. I, sir, salute you.
AJS
April 14th, 2009 | 2:41 pm
Hmm. Will this descend into a sort of “how many languages can we write this in?” fest? I’ll see your Ruby and raise you a Perl.
#!/usr/bin/perl -w use strict; sub yn { $_ = shift; print; $_ = ; /y/i }; if ((yn "Do you have a problem? (y/n): ") && (!yn "Can anyone else help? (y/n): ") && (yn "Can you find them? (y/n): ")) {print "Maybe you can hire⦠the A-Team!\n";} else {print "You Cannot Hire the A-Team.\n"};AJS
April 14th, 2009 | 2:48 pm
Gick. It got mangled by the formatter! You need a line break after the first line.
And thinking about it, maybe I should have put the (y/n): within the function. And made that regular expression /[yj]/i for compatibility with German-speakers. Or /[yjos]/i for compatibility with German, French and Spanish-speakers.
Nah, s*d it ….. I can always put some of those features into the next release. And if I can’t think of anything to add to the next-plus-one release, then I’ll just hold something back from the next one.
Stu
April 14th, 2009 | 2:53 pm
Javascript version is slightly fudgy:
if (confirm(“Do You Have A Problem?”) && !confirm(“Can Anyone Else Help?”) && confirm(“Can You Find Them?”)) {
alert(“Maybe You Can Hire… The A-Team”);
}
else alert(“You Cannot Hire The A-Team”);
The issue is that ‘Confirm’ gives you a choice of ‘OK’ or ‘Cancel’ rather than ‘yes’ or ‘no’
Stu
April 14th, 2009 | 3:15 pm
…And just to demonstrate the inadequacies of AppleScript…