Skip to content

Instantly share code, notes, and snippets.

@maehrm
maehrm / gist:961031
Created May 8, 2011 01:56 — forked from antimon2/gist:960956
rw3sat.rb
#!/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