Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 29 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
29
Dung lượng
242,51 KB
Nội dung
[...]... language is Ruby We think Ruby is better than Emerald You can choose any interface you like, as long as a user can interact with the end result You can play around with a CGI-based solution at the Ruby Quiz site.5 You can find the two Mad Libs files I’m using on the Ruby Quiz site as well.6 5 http://rubyquiz.com/cgi-bin/madlib.cgi 6 http://rubyquiz.com/madlibs/Lunch_Hungers.madlib and http://rubyquiz.com/madlibs/Gift_Giving.madlib... containing the lineage of various European royalty This particular file makes generous use of whitespace to increase readability 8 http://www.rubyquiz.com/royal.ged Report erratum 10 Q UIZ 4 A NIMAL Q UIZ Quiz Answer on page 81 4 Animal Quiz Posed by Jim Weirich Here’s an animal quiz program to try as a Ruby Quiz It works like this: The program starts by telling the user to think of an animal It then... this: • 0 @I1@ INDI This starts a new subtree of type INDI (“individual”) The ID for this individual is @I1@ • 1 NAME Jamis Gordon /Buck/ This starts a NAME subtree with a value of Jamis Gordon /Buck/ • 2 SURN Buck This is a subelement of the NAME subtree, of type SURN (“surname”) • 2 GIVN Jamis Gordon Same as SURN but specifies the given name of the individual • 1 SEX M Creates a new sub-element of the... month = Regexp.build (1 12) "0" =~ month # => false "1" =~ month # => true "12 " =~ month # => true day = Regexp.build (1 31) "6" =~ day # => true "16 " =~ day # => true "Tues" =~ day # => false year = Regexp.build(98, 99, 2000 2005) "04" =~ year # => false "2004" =~ year # => true "99" # => true =~ year num = Regexp.build(0 1_ 000_000) " -1" =~ num # => false You can determine the specifics of the expressions... clock formatted in military Report erratum 14 Q UIZ 6 R EGEXP BUILD () time 11 (0 to 23), if hours 0 through 9 may or may not have a single leading zero? • Should anything be captured by the returned Regexp? • How should anchoring work? "2004" =~ Regexp.build(4) 11 Also # => ??? known as 24-hour time Report erratum 15 Q UIZ 7 H IGH L INE Quiz Answer on page 10 1 7 HighLine When you stop to think about... side of my support base is the most fantastic bunch of family and friends a guy could have They truly make me believe I can do anything Without them I would be merely mortal Finally, but most important, I must thank Dana, my true inspiration You believed long before I did, and as always, you were right Here is the proof Report erratum 4 Part I The Quizzes Q UIZ 1 M AD L IBS Quiz Answer on page 61 1 Mad... can’t be equally smooth This Ruby Quiz is to start a module called HighLine (for high-level, lineoriented interface) Ideally this module would eventually cover many aspects of terminal interaction, but for this quiz we’ll focus just on getting input What I really think we need here is to take a page out of the OptionParser book .12 Here are some general ideas: 12 At http://www .ruby- doc.org/stdlib/libdoc/optparse/rdoc/index.html... of requesting input It should free the programmer of common concerns like calls to chomp( ) and ensuring valid input Report erratum 17 Q UIZ 8 R OMAN N UMERALS Quiz Answer on page 11 2 8 Roman Numerals This quiz asks you to write a converter to and from Roman numerals The script should be a standard Unix filter, reading from files specified on the command line or STDIN and writing to STDOUT Each line of. .. erratum 19 Q UIZ 9 R OCK P APER S CISSORS Quiz Answer on page 12 1 9 Rock Paper Scissors Generals, break out your copies of The Art of War[Tzu05], and let’s get a little competition going! Your task is to build some AI for playing the game Rock Paper Scissors against all manner of opponents The challenge is to adapt to an opponent’s strategy and seize the advantage while he is doing the same to you, of course... First, seven letters are associated with seven values: I = 1 V = 5 X = 10 L = 50 C = 10 0 D = 500 M = 10 00 13 Roman numerals for 4,000 and up do not use plain ASCII characters Report erratum 18 Q UIZ 8 R OMAN N UMERALS Second, you can combine letters to add values by listing them largest to smallest from left to right: II is 2 VIII is 8 XXXI is 31 However, you may list only three consecutive identical . and as always, you were right. Here is the proof. Report erratum Part I The Quizzes QUIZ 1. MAD LIBS 6 Quiz 1 Answer on page 61 Mad Libs This Ruby Quiz is to write a program that presents the. lineage of various European royalty. This particular file makes generous use of white- space to increase readability. 8 http://www.rubyquiz.com/royal.ged Report erratum QUIZ 4. ANIMAL QUIZ 11 Quiz 4 Answer.