[Ruby] Learning from the basics Artificial intelligence textbook Chapter 2 End-of-chapter problem

1 minute read


As a study of machine learning, I read “Learn from basics textbook of artificial intelligence””.

The feature of this book is that a simple program of Python is included in the chapter end problem.

Chapter 2 End of Chapter Problem


LIMIT = 20

count = 0
endcount = 0
puts('Dr> I'm Doctor, talk to you')
while endcount <LIMIT
  inputline = gets.chomp.encode("UTF-8", "CP932", :invalid => :replace)
  if count >= CYCLE
    puts'Dr>' << inputline <<'?   '
    count = 0
  elsif inputline.include? ('teacher')
    puts'Dr> let's talk about you, not me'
  elsif inputline.include?('mother')
    puts'Dr> talk about your mom'
  elsif inputline.include? ('Father')
    puts'Dr> talk about your dad'
  elsif inputline.include? ('opinion')
    puts'Dr> Want to hear my opinion? '
  elsif inputline.include?('I'm worried')
    puts'Dr>' << inputline.sub(I'm worried about //, are you worried about'?)
    puts'Dr> continue'
  count += 1
  endcount += 1
puts('Dr> Let's finish it. Thank you.')

This is a problem to create a simplified version of ELIZA.


  inputline = gets.chomp.encode("UTF-8", "CP932", :invalid => :replace)

In the case of Windows10, the process of converting the character code is required. With AtCoder, there is no such processing, so it is fresh. However, it is necessary to select the legacy console due to a bug in the command prompt. 20200709.png


  • I read up to Chapter 2
  • G test was difficult