Best of Ruby Quiz Pragmatic programmers phần 4

Nếu hội đồng quản trị làm mà không cần chạy một trò chơi là một trận hòa. Dưới đây là những gì một trò chơi chiến thắng bởi các cầu thủ X có thể kết thúc tìm kiếm như:Điều này thực sự chỉ là một lớp dữ liệu. Nó đặt ra một loạt các mặc định và sau đó cho phép người dùng thay đổi để phù hợp với nhu cầu của họ | Answer 4. Animal Quiz 81 Answer From page 11 4 Animal Quiz Everybody solved this one using pretty much the same technique. Jim Weirich explains the strategy There is an easy solution that represents the database as a binary tree with questions as interior nodes and possible animals as leaf nodes. Each interior question node has two children corresponding to a yes or no answer. The children are either further questions which will be asked or an animal which will be guessed . Couldn t have said it better myself. Let s see Jim s own implementation of said tree animal_quiz usr bin env ruby require yaml require ui def ui ui end Spring Cleaning I removed the letter y from the vowels in because all but the most obscure words starting with y should still use a as an article for example a yew . class Question def initialize question yes no question question ye s yes @no no question unless question A a-z end def walk if question yes else no end Report erratum Answer 4. Animal Quiz 82 self end end class Animal attr_reader name def initialize name @name name end def walk if Is it an name Yea I win n n self else Rats I lose Help me play better next time. new_animal What animal were you thinking of question Give me a question to distinguish a an name from an new_animal . response For an new_animal the answer to your question would be Thank you n n if response question new_animal self else question self new_animal end end end def an animal animal A aeiou an a animal end end if animals. yaml current open animals. yaml f else current mouse end loop do current break unless Play again n n end open w do f end This is a very straightforward solution. At the top it brings in YAML for Report .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
7    318    3    24-05-2024
125    161    1    24-05-2024
5    63    2    24-05-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.