This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
def random_walk_3_sat(f, n, rr) # W1: R を rr に変更 | |
ff = f.split(/\s*and\s*/) | |
rr.times do | |
x = Array.new(n) { [true, false].sample } # W4: a を x に変更 | |
(3*n).times do | |
return "充足可能である" if ff.all? { |c| eval(c) } # W7,8,9 | |
c = ff.find { |cc| !eval(cc) } # W10 |