Class: ALearn::LearnAnswer
- Inherits:
-
Object
- Object
- ALearn::LearnAnswer
- Defined in:
- lib/aLearn.rb
Class Method Summary collapse
Class Method Details
.bf_search ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/aLearn.rb', line 7 def self.bf_search number = 0 # A list of all possible answers. possible_answers = File.readlines("answers/possible_answers.txt", chomp: true) # Display list of all possible answers. print possible_answers # Asks you to pick your answer. print " >> " pick_answer = gets.chomp.strip.to_i # Sets correct answer to your answer. correct_answer = possible_answers[pick_answer].strip puts " " # Sets the loop limit to the size of the array. size_limit = possible_answers.size.to_i # If loop reaches the correct answer before loop limit, generates auto answer. Otherwise continue loop until end. size_limit.times do answer = possible_answers[number] if answer == correct_answer print "Correct: "; puts answer # Generates an automatic answer from learned answer. open("results/#{correct_answer.tr ' ', '_'}.rb", "w") { |f| f.puts "puts 'Correct: #{answer}' " } abort else print "Incorrect: "; puts answer end number = number + 1 end end |
.find_answer ⇒ Object
49 50 51 52 53 |
# File 'lib/aLearn.rb', line 49 def self.find_answer print ">> "; find_script = gets.chomp system("ruby results/#{find_script}") end |